2 ** License Applicability. Except to the extent portions of this file are
3 ** made subject to an alternative license as permitted in the SGI Free
4 ** Software License B, Version 1.1 (the "License"), the contents of this
5 ** file are subject only to the provisions of the License. You may not use
6 ** this file except in compliance with the License. You may obtain a copy
7 ** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
8 ** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
10 ** http://oss.sgi.com/projects/FreeB
12 ** Note that, as provided in the License, the Software is distributed on an
13 ** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
14 ** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
15 ** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
16 ** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
18 ** Original Code. The Original Code is: OpenGL Sample Implementation,
19 ** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
20 ** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
21 ** Copyright in any portions created by third parties is as indicated
22 ** elsewhere herein. All Rights Reserved.
24 ** Additional Notice Provisions: The application programming interfaces
25 ** established by SGI in conjunction with the Original Code are The
26 ** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
27 ** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
28 ** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
29 ** Window System(R) (Version 1.3), released October 19, 1998. This software
30 ** was created using the OpenGL(R) version 1.2.1 Sample Implementation
31 ** published by SGI, but has not been independently verified as being
32 ** compliant with the OpenGL(R) version 1.2.1 Specification.
42 #include <limits.h> /* UINT_MAX */
56 /* Pixel storage modes */
59 GLint pack_row_length
;
61 GLint pack_skip_pixels
;
63 GLint pack_swap_bytes
;
64 GLint pack_skip_images
;
65 GLint pack_image_height
;
67 GLint unpack_alignment
;
68 GLint unpack_row_length
;
69 GLint unpack_skip_rows
;
70 GLint unpack_skip_pixels
;
71 GLint unpack_lsb_first
;
72 GLint unpack_swap_bytes
;
73 GLint unpack_skip_images
;
74 GLint unpack_image_height
;
77 static int gluBuild1DMipmapLevelsCore(GLenum
, GLint
,
80 GLenum
, GLenum
, GLint
, GLint
, GLint
,
82 static int gluBuild2DMipmapLevelsCore(GLenum
, GLint
,
85 GLenum
, GLenum
, GLint
, GLint
, GLint
,
87 static int gluBuild3DMipmapLevelsCore(GLenum
, GLint
,
88 GLsizei
, GLsizei
, GLsizei
,
89 GLsizei
, GLsizei
, GLsizei
,
90 GLenum
, GLenum
, GLint
, GLint
, GLint
,
94 * internal function declarations
96 static GLfloat
bytes_per_element(GLenum type
);
97 static GLint
elements_per_group(GLenum format
, GLenum type
);
98 static GLint
is_index(GLenum format
);
99 static GLint
image_size(GLint width
, GLint height
, GLenum format
, GLenum type
);
100 static void fill_image(const PixelStorageModes
*,
101 GLint width
, GLint height
, GLenum format
,
102 GLenum type
, GLboolean index_format
,
103 const void *userdata
, GLushort
*newimage
);
104 static void empty_image(const PixelStorageModes
*,
105 GLint width
, GLint height
, GLenum format
,
106 GLenum type
, GLboolean index_format
,
107 const GLushort
*oldimage
, void *userdata
);
108 static void scale_internal(GLint components
, GLint widthin
, GLint heightin
,
109 const GLushort
*datain
,
110 GLint widthout
, GLint heightout
,
113 static void scale_internal_ubyte(GLint components
, GLint widthin
,
114 GLint heightin
, const GLubyte
*datain
,
115 GLint widthout
, GLint heightout
,
116 GLubyte
*dataout
, GLint element_size
,
117 GLint ysize
, GLint group_size
);
118 static void scale_internal_byte(GLint components
, GLint widthin
,
119 GLint heightin
, const GLbyte
*datain
,
120 GLint widthout
, GLint heightout
,
121 GLbyte
*dataout
, GLint element_size
,
122 GLint ysize
, GLint group_size
);
123 static void scale_internal_ushort(GLint components
, GLint widthin
,
124 GLint heightin
, const GLushort
*datain
,
125 GLint widthout
, GLint heightout
,
126 GLushort
*dataout
, GLint element_size
,
127 GLint ysize
, GLint group_size
,
129 static void scale_internal_short(GLint components
, GLint widthin
,
130 GLint heightin
, const GLshort
*datain
,
131 GLint widthout
, GLint heightout
,
132 GLshort
*dataout
, GLint element_size
,
133 GLint ysize
, GLint group_size
,
135 static void scale_internal_uint(GLint components
, GLint widthin
,
136 GLint heightin
, const GLuint
*datain
,
137 GLint widthout
, GLint heightout
,
138 GLuint
*dataout
, GLint element_size
,
139 GLint ysize
, GLint group_size
,
141 static void scale_internal_int(GLint components
, GLint widthin
,
142 GLint heightin
, const GLint
*datain
,
143 GLint widthout
, GLint heightout
,
144 GLint
*dataout
, GLint element_size
,
145 GLint ysize
, GLint group_size
,
147 static void scale_internal_float(GLint components
, GLint widthin
,
148 GLint heightin
, const GLfloat
*datain
,
149 GLint widthout
, GLint heightout
,
150 GLfloat
*dataout
, GLint element_size
,
151 GLint ysize
, GLint group_size
,
154 static int checkMipmapArgs(GLenum
, GLenum
, GLenum
);
155 static GLboolean
legalFormat(GLenum
);
156 static GLboolean
legalType(GLenum
);
157 static GLboolean
isTypePackedPixel(GLenum
);
158 static GLboolean
isLegalFormatForPackedPixelType(GLenum
, GLenum
);
159 static GLboolean
isLegalLevels(GLint
, GLint
, GLint
, GLint
);
160 static void closestFit(GLenum
, GLint
, GLint
, GLint
, GLenum
, GLenum
,
163 /* all extract/shove routines must return double to handle unsigned ints */
164 static GLdouble
extractUbyte(int, const void *);
165 static void shoveUbyte(GLdouble
, int, void *);
166 static GLdouble
extractSbyte(int, const void *);
167 static void shoveSbyte(GLdouble
, int, void *);
168 static GLdouble
extractUshort(int, const void *);
169 static void shoveUshort(GLdouble
, int, void *);
170 static GLdouble
extractSshort(int, const void *);
171 static void shoveSshort(GLdouble
, int, void *);
172 static GLdouble
extractUint(int, const void *);
173 static void shoveUint(GLdouble
, int, void *);
174 static GLdouble
extractSint(int, const void *);
175 static void shoveSint(GLdouble
, int, void *);
176 static GLdouble
extractFloat(int, const void *);
177 static void shoveFloat(GLdouble
, int, void *);
178 static void halveImageSlice(int, GLdouble (*)(int, const void *),
179 void (*)(GLdouble
, int, void *),
181 const void *, void *,
182 GLint
, GLint
, GLint
, GLint
, GLint
);
183 static void halveImage3D(int, GLdouble (*)(int, const void *),
184 void (*)(GLdouble
, int, void *),
186 const void *, void *,
187 GLint
, GLint
, GLint
, GLint
, GLint
);
189 /* packedpixel type scale routines */
190 static void extract332(int,const void *, GLfloat
[]);
191 static void shove332(const GLfloat
[],int ,void *);
192 static void extract233rev(int,const void *, GLfloat
[]);
193 static void shove233rev(const GLfloat
[],int ,void *);
194 static void extract565(int,const void *, GLfloat
[]);
195 static void shove565(const GLfloat
[],int ,void *);
196 static void extract565rev(int,const void *, GLfloat
[]);
197 static void shove565rev(const GLfloat
[],int ,void *);
198 static void extract4444(int,const void *, GLfloat
[]);
199 static void shove4444(const GLfloat
[],int ,void *);
200 static void extract4444rev(int,const void *, GLfloat
[]);
201 static void shove4444rev(const GLfloat
[],int ,void *);
202 static void extract5551(int,const void *, GLfloat
[]);
203 static void shove5551(const GLfloat
[],int ,void *);
204 static void extract1555rev(int,const void *, GLfloat
[]);
205 static void shove1555rev(const GLfloat
[],int ,void *);
206 static void extract8888(int,const void *, GLfloat
[]);
207 static void shove8888(const GLfloat
[],int ,void *);
208 static void extract8888rev(int,const void *, GLfloat
[]);
209 static void shove8888rev(const GLfloat
[],int ,void *);
210 static void extract1010102(int,const void *, GLfloat
[]);
211 static void shove1010102(const GLfloat
[],int ,void *);
212 static void extract2101010rev(int,const void *, GLfloat
[]);
213 static void shove2101010rev(const GLfloat
[],int ,void *);
214 static void scaleInternalPackedPixel(int,
215 void (*)(int, const void *,GLfloat
[]),
216 void (*)(const GLfloat
[],int, void *),
217 GLint
,GLint
, const void *,
218 GLint
,GLint
,void *,GLint
,GLint
,GLint
);
219 static void halveImagePackedPixel(int,
220 void (*)(int, const void *,GLfloat
[]),
221 void (*)(const GLfloat
[],int, void *),
222 GLint
, GLint
, const void *,
223 void *, GLint
, GLint
, GLint
);
224 static void halve1DimagePackedPixel(int,
225 void (*)(int, const void *,GLfloat
[]),
226 void (*)(const GLfloat
[],int, void *),
227 GLint
, GLint
, const void *,
228 void *, GLint
, GLint
, GLint
);
230 static void halve1Dimage_ubyte(GLint
, GLuint
, GLuint
,const GLubyte
*,
231 GLubyte
*, GLint
, GLint
, GLint
);
232 static void halve1Dimage_byte(GLint
, GLuint
, GLuint
,const GLbyte
*, GLbyte
*,
233 GLint
, GLint
, GLint
);
234 static void halve1Dimage_ushort(GLint
, GLuint
, GLuint
, const GLushort
*,
235 GLushort
*, GLint
, GLint
, GLint
, GLint
);
236 static void halve1Dimage_short(GLint
, GLuint
, GLuint
,const GLshort
*, GLshort
*,
237 GLint
, GLint
, GLint
, GLint
);
238 static void halve1Dimage_uint(GLint
, GLuint
, GLuint
, const GLuint
*, GLuint
*,
239 GLint
, GLint
, GLint
, GLint
);
240 static void halve1Dimage_int(GLint
, GLuint
, GLuint
, const GLint
*, GLint
*,
241 GLint
, GLint
, GLint
, GLint
);
242 static void halve1Dimage_float(GLint
, GLuint
, GLuint
, const GLfloat
*, GLfloat
*,
243 GLint
, GLint
, GLint
, GLint
);
245 static GLint
imageSize3D(GLint
, GLint
, GLint
, GLenum
,GLenum
);
246 static void fillImage3D(const PixelStorageModes
*, GLint
, GLint
, GLint
,GLenum
,
247 GLenum
, GLboolean
, const void *, GLushort
*);
248 static void emptyImage3D(const PixelStorageModes
*,
249 GLint
, GLint
, GLint
, GLenum
,
251 const GLushort
*, void *);
252 static void scaleInternal3D(GLint
, GLint
, GLint
, GLint
, const GLushort
*,
253 GLint
, GLint
, GLint
, GLushort
*);
255 static void retrieveStoreModes(PixelStorageModes
*psm
)
257 glGetIntegerv(GL_UNPACK_ALIGNMENT
, &psm
->unpack_alignment
);
258 glGetIntegerv(GL_UNPACK_ROW_LENGTH
, &psm
->unpack_row_length
);
259 glGetIntegerv(GL_UNPACK_SKIP_ROWS
, &psm
->unpack_skip_rows
);
260 glGetIntegerv(GL_UNPACK_SKIP_PIXELS
, &psm
->unpack_skip_pixels
);
261 glGetIntegerv(GL_UNPACK_LSB_FIRST
, &psm
->unpack_lsb_first
);
262 glGetIntegerv(GL_UNPACK_SWAP_BYTES
, &psm
->unpack_swap_bytes
);
264 glGetIntegerv(GL_PACK_ALIGNMENT
, &psm
->pack_alignment
);
265 glGetIntegerv(GL_PACK_ROW_LENGTH
, &psm
->pack_row_length
);
266 glGetIntegerv(GL_PACK_SKIP_ROWS
, &psm
->pack_skip_rows
);
267 glGetIntegerv(GL_PACK_SKIP_PIXELS
, &psm
->pack_skip_pixels
);
268 glGetIntegerv(GL_PACK_LSB_FIRST
, &psm
->pack_lsb_first
);
269 glGetIntegerv(GL_PACK_SWAP_BYTES
, &psm
->pack_swap_bytes
);
272 static void retrieveStoreModes3D(PixelStorageModes
*psm
)
274 glGetIntegerv(GL_UNPACK_ALIGNMENT
, &psm
->unpack_alignment
);
275 glGetIntegerv(GL_UNPACK_ROW_LENGTH
, &psm
->unpack_row_length
);
276 glGetIntegerv(GL_UNPACK_SKIP_ROWS
, &psm
->unpack_skip_rows
);
277 glGetIntegerv(GL_UNPACK_SKIP_PIXELS
, &psm
->unpack_skip_pixels
);
278 glGetIntegerv(GL_UNPACK_LSB_FIRST
, &psm
->unpack_lsb_first
);
279 glGetIntegerv(GL_UNPACK_SWAP_BYTES
, &psm
->unpack_swap_bytes
);
280 glGetIntegerv(GL_UNPACK_SKIP_IMAGES
, &psm
->unpack_skip_images
);
281 glGetIntegerv(GL_UNPACK_IMAGE_HEIGHT
, &psm
->unpack_image_height
);
283 glGetIntegerv(GL_PACK_ALIGNMENT
, &psm
->pack_alignment
);
284 glGetIntegerv(GL_PACK_ROW_LENGTH
, &psm
->pack_row_length
);
285 glGetIntegerv(GL_PACK_SKIP_ROWS
, &psm
->pack_skip_rows
);
286 glGetIntegerv(GL_PACK_SKIP_PIXELS
, &psm
->pack_skip_pixels
);
287 glGetIntegerv(GL_PACK_LSB_FIRST
, &psm
->pack_lsb_first
);
288 glGetIntegerv(GL_PACK_SWAP_BYTES
, &psm
->pack_swap_bytes
);
289 glGetIntegerv(GL_PACK_SKIP_IMAGES
, &psm
->pack_skip_images
);
290 glGetIntegerv(GL_PACK_IMAGE_HEIGHT
, &psm
->pack_image_height
);
293 static int computeLog(GLuint value
)
300 if (value
== 0) return -1;
305 if (value
!= 1) return -1;
314 ** Compute the nearest power of 2 number. This algorithm is a little
315 ** strange, but it works quite well.
317 static int nearestPower(GLuint value
)
324 if (value
== 0) return -1;
329 } else if (value
== 3) {
337 #define __GLU_SWAP_2_BYTES(s)\
338 (GLushort)(((GLushort)((const GLubyte*)(s))[1])<<8 | ((const GLubyte*)(s))[0])
340 #define __GLU_SWAP_4_BYTES(s)\
341 (GLuint)(((GLuint)((const GLubyte*)(s))[3])<<24 | \
342 ((GLuint)((const GLubyte*)(s))[2])<<16 | \
343 ((GLuint)((const GLubyte*)(s))[1])<<8 | ((const GLubyte*)(s))[0])
345 static void halveImage(GLint components
, GLuint width
, GLuint height
,
346 const GLushort
*datain
, GLushort
*dataout
)
349 int newwidth
, newheight
;
354 newwidth
= width
/ 2;
355 newheight
= height
/ 2;
356 delta
= width
* components
;
361 for (i
= 0; i
< newheight
; i
++) {
362 for (j
= 0; j
< newwidth
; j
++) {
363 for (k
= 0; k
< components
; k
++) {
364 s
[0] = (t
[0] + t
[components
] + t
[delta
] +
365 t
[delta
+components
] + 2) / 4;
374 static void halveImage_ubyte(GLint components
, GLuint width
, GLuint height
,
375 const GLubyte
*datain
, GLubyte
*dataout
,
376 GLint element_size
, GLint ysize
, GLint group_size
)
379 int newwidth
, newheight
;
384 /* handle case where there is only 1 column/row */
385 if (width
== 1 || height
== 1) {
386 assert( !(width
== 1 && height
== 1) ); /* can't be 1x1 */
387 halve1Dimage_ubyte(components
,width
,height
,datain
,dataout
,
388 element_size
,ysize
,group_size
);
392 newwidth
= width
/ 2;
393 newheight
= height
/ 2;
394 padBytes
= ysize
- (width
*group_size
);
396 t
= (const char *)datain
;
399 for (i
= 0; i
< newheight
; i
++) {
400 for (j
= 0; j
< newwidth
; j
++) {
401 for (k
= 0; k
< components
; k
++) {
402 s
[0] = (*(const GLubyte
*)t
+
403 *(const GLubyte
*)(t
+group_size
) +
404 *(const GLubyte
*)(t
+ysize
) +
405 *(const GLubyte
*)(t
+ysize
+group_size
) + 2) / 4;
406 s
++; t
+= element_size
;
416 static void halve1Dimage_ubyte(GLint components
, GLuint width
, GLuint height
,
417 const GLubyte
*dataIn
, GLubyte
*dataOut
,
418 GLint element_size
, GLint ysize
,
421 GLint halfWidth
= width
/ 2;
422 GLint halfHeight
= height
/ 2;
423 const char *src
= (const char *) dataIn
;
424 GLubyte
*dest
= dataOut
;
427 assert(width
== 1 || height
== 1); /* must be 1D */
428 assert(width
!= height
); /* can't be square */
430 if (height
== 1) { /* 1 row */
431 assert(width
!= 1); /* widthxheight can't be 1x1 */
434 for (jj
= 0; jj
< halfWidth
; jj
++) {
436 for (kk
= 0; kk
< components
; kk
++) {
437 *dest
= (*(const GLubyte
*)src
+
438 *(const GLubyte
*)(src
+group_size
)) / 2;
443 src
+= group_size
; /* skip to next 2 */
446 int padBytes
= ysize
- (width
*group_size
);
447 src
+= padBytes
; /* for assertion only */
450 else if (width
== 1) { /* 1 column */
451 int padBytes
= ysize
- (width
* group_size
);
452 assert(height
!= 1); /* widthxheight can't be 1x1 */
454 /* one vertical column with possible pad bytes per row */
455 /* average two at a time */
457 for (jj
= 0; jj
< halfHeight
; jj
++) {
459 for (kk
= 0; kk
< components
; kk
++) {
460 *dest
= (*(const GLubyte
*)src
+ *(const GLubyte
*)(src
+ysize
)) / 2;
465 src
+= padBytes
; /* add pad bytes, if any, to get to end to row */
470 assert(src
== &((const char *)dataIn
)[ysize
*height
]);
471 assert((char *)dest
== &((char *)dataOut
)
472 [components
* element_size
* halfWidth
* halfHeight
]);
473 } /* halve1Dimage_ubyte() */
475 static void halveImage_byte(GLint components
, GLuint width
, GLuint height
,
476 const GLbyte
*datain
, GLbyte
*dataout
,
478 GLint ysize
, GLint group_size
)
481 int newwidth
, newheight
;
486 /* handle case where there is only 1 column/row */
487 if (width
== 1 || height
== 1) {
488 assert( !(width
== 1 && height
== 1) ); /* can't be 1x1 */
489 halve1Dimage_byte(components
,width
,height
,datain
,dataout
,
490 element_size
,ysize
,group_size
);
494 newwidth
= width
/ 2;
495 newheight
= height
/ 2;
496 padBytes
= ysize
- (width
*group_size
);
498 t
= (const char *)datain
;
501 for (i
= 0; i
< newheight
; i
++) {
502 for (j
= 0; j
< newwidth
; j
++) {
503 for (k
= 0; k
< components
; k
++) {
504 s
[0] = (*(const GLbyte
*)t
+
505 *(const GLbyte
*)(t
+group_size
) +
506 *(const GLbyte
*)(t
+ysize
) +
507 *(const GLbyte
*)(t
+ysize
+group_size
) + 2) / 4;
508 s
++; t
+= element_size
;
517 static void halve1Dimage_byte(GLint components
, GLuint width
, GLuint height
,
518 const GLbyte
*dataIn
, GLbyte
*dataOut
,
519 GLint element_size
,GLint ysize
, GLint group_size
)
521 GLint halfWidth
= width
/ 2;
522 GLint halfHeight
= height
/ 2;
523 const char *src
= (const char *) dataIn
;
524 GLbyte
*dest
= dataOut
;
527 assert(width
== 1 || height
== 1); /* must be 1D */
528 assert(width
!= height
); /* can't be square */
530 if (height
== 1) { /* 1 row */
531 assert(width
!= 1); /* widthxheight can't be 1x1 */
534 for (jj
= 0; jj
< halfWidth
; jj
++) {
536 for (kk
= 0; kk
< components
; kk
++) {
537 *dest
= (*(const GLbyte
*)src
+ *(const GLbyte
*)(src
+group_size
)) / 2;
542 src
+= group_size
; /* skip to next 2 */
545 int padBytes
= ysize
- (width
*group_size
);
546 src
+= padBytes
; /* for assertion only */
549 else if (width
== 1) { /* 1 column */
550 int padBytes
= ysize
- (width
* group_size
);
551 assert(height
!= 1); /* widthxheight can't be 1x1 */
553 /* one vertical column with possible pad bytes per row */
554 /* average two at a time */
556 for (jj
= 0; jj
< halfHeight
; jj
++) {
558 for (kk
= 0; kk
< components
; kk
++) {
559 *dest
= (*(const GLbyte
*)src
+ *(const GLbyte
*)(src
+ysize
)) / 2;
564 src
+= padBytes
; /* add pad bytes, if any, to get to end to row */
568 assert(src
== &((const char *)dataIn
)[ysize
*height
]);
571 assert((char *)dest
== &((char *)dataOut
)
572 [components
* element_size
* halfWidth
* halfHeight
]);
573 } /* halve1Dimage_byte() */
575 static void halveImage_ushort(GLint components
, GLuint width
, GLuint height
,
576 const GLushort
*datain
, GLushort
*dataout
,
577 GLint element_size
, GLint ysize
, GLint group_size
,
581 int newwidth
, newheight
;
586 /* handle case where there is only 1 column/row */
587 if (width
== 1 || height
== 1) {
588 assert( !(width
== 1 && height
== 1) ); /* can't be 1x1 */
589 halve1Dimage_ushort(components
,width
,height
,datain
,dataout
,
590 element_size
,ysize
,group_size
, myswap_bytes
);
594 newwidth
= width
/ 2;
595 newheight
= height
/ 2;
596 padBytes
= ysize
- (width
*group_size
);
598 t
= (const char *)datain
;
602 for (i
= 0; i
< newheight
; i
++) {
603 for (j
= 0; j
< newwidth
; j
++) {
604 for (k
= 0; k
< components
; k
++) {
605 s
[0] = (*(const GLushort
*)t
+
606 *(const GLushort
*)(t
+group_size
) +
607 *(const GLushort
*)(t
+ysize
) +
608 *(const GLushort
*)(t
+ysize
+group_size
) + 2) / 4;
609 s
++; t
+= element_size
;
617 for (i
= 0; i
< newheight
; i
++) {
618 for (j
= 0; j
< newwidth
; j
++) {
619 for (k
= 0; k
< components
; k
++) {
620 s
[0] = (__GLU_SWAP_2_BYTES(t
) +
621 __GLU_SWAP_2_BYTES(t
+group_size
) +
622 __GLU_SWAP_2_BYTES(t
+ysize
) +
623 __GLU_SWAP_2_BYTES(t
+ysize
+group_size
)+ 2)/4;
624 s
++; t
+= element_size
;
633 static void halve1Dimage_ushort(GLint components
, GLuint width
, GLuint height
,
634 const GLushort
*dataIn
, GLushort
*dataOut
,
635 GLint element_size
, GLint ysize
,
636 GLint group_size
, GLint myswap_bytes
)
638 GLint halfWidth
= width
/ 2;
639 GLint halfHeight
= height
/ 2;
640 const char *src
= (const char *) dataIn
;
641 GLushort
*dest
= dataOut
;
644 assert(width
== 1 || height
== 1); /* must be 1D */
645 assert(width
!= height
); /* can't be square */
647 if (height
== 1) { /* 1 row */
648 assert(width
!= 1); /* widthxheight can't be 1x1 */
651 for (jj
= 0; jj
< halfWidth
; jj
++) {
653 for (kk
= 0; kk
< components
; kk
++) {
655 GLushort ushort
[BOX2
];
657 ushort
[0]= __GLU_SWAP_2_BYTES(src
);
658 ushort
[1]= __GLU_SWAP_2_BYTES(src
+group_size
);
661 ushort
[0]= *(const GLushort
*)src
;
662 ushort
[1]= *(const GLushort
*)(src
+group_size
);
665 *dest
= (ushort
[0] + ushort
[1]) / 2;
669 src
+= group_size
; /* skip to next 2 */
672 int padBytes
= ysize
- (width
*group_size
);
673 src
+= padBytes
; /* for assertion only */
676 else if (width
== 1) { /* 1 column */
677 int padBytes
= ysize
- (width
* group_size
);
678 assert(height
!= 1); /* widthxheight can't be 1x1 */
680 /* one vertical column with possible pad bytes per row */
681 /* average two at a time */
683 for (jj
= 0; jj
< halfHeight
; jj
++) {
685 for (kk
= 0; kk
< components
; kk
++) {
687 GLushort ushort
[BOX2
];
689 ushort
[0]= __GLU_SWAP_2_BYTES(src
);
690 ushort
[1]= __GLU_SWAP_2_BYTES(src
+ysize
);
693 ushort
[0]= *(const GLushort
*)src
;
694 ushort
[1]= *(const GLushort
*)(src
+ysize
);
696 *dest
= (ushort
[0] + ushort
[1]) / 2;
701 src
+= padBytes
; /* add pad bytes, if any, to get to end to row */
705 assert(src
== &((const char *)dataIn
)[ysize
*height
]);
708 assert((char *)dest
== &((char *)dataOut
)
709 [components
* element_size
* halfWidth
* halfHeight
]);
711 } /* halve1Dimage_ushort() */
714 static void halveImage_short(GLint components
, GLuint width
, GLuint height
,
715 const GLshort
*datain
, GLshort
*dataout
,
716 GLint element_size
, GLint ysize
, GLint group_size
,
720 int newwidth
, newheight
;
725 /* handle case where there is only 1 column/row */
726 if (width
== 1 || height
== 1) {
727 assert( !(width
== 1 && height
== 1) ); /* can't be 1x1 */
728 halve1Dimage_short(components
,width
,height
,datain
,dataout
,
729 element_size
,ysize
,group_size
, myswap_bytes
);
733 newwidth
= width
/ 2;
734 newheight
= height
/ 2;
735 padBytes
= ysize
- (width
*group_size
);
737 t
= (const char *)datain
;
741 for (i
= 0; i
< newheight
; i
++) {
742 for (j
= 0; j
< newwidth
; j
++) {
743 for (k
= 0; k
< components
; k
++) {
744 s
[0] = (*(const GLshort
*)t
+
745 *(const GLshort
*)(t
+group_size
) +
746 *(const GLshort
*)(t
+ysize
) +
747 *(const GLshort
*)(t
+ysize
+group_size
) + 2) / 4;
748 s
++; t
+= element_size
;
756 for (i
= 0; i
< newheight
; i
++) {
757 for (j
= 0; j
< newwidth
; j
++) {
758 for (k
= 0; k
< components
; k
++) {
761 b
= __GLU_SWAP_2_BYTES(t
);
762 buf
= *(const GLshort
*)&b
;
763 b
= __GLU_SWAP_2_BYTES(t
+group_size
);
764 buf
+= *(const GLshort
*)&b
;
765 b
= __GLU_SWAP_2_BYTES(t
+ysize
);
766 buf
+= *(const GLshort
*)&b
;
767 b
= __GLU_SWAP_2_BYTES(t
+ysize
+group_size
);
768 buf
+= *(const GLshort
*)&b
;
769 s
[0] = (GLshort
)((buf
+2)/4);
770 s
++; t
+= element_size
;
779 static void halve1Dimage_short(GLint components
, GLuint width
, GLuint height
,
780 const GLshort
*dataIn
, GLshort
*dataOut
,
781 GLint element_size
, GLint ysize
,
782 GLint group_size
, GLint myswap_bytes
)
784 GLint halfWidth
= width
/ 2;
785 GLint halfHeight
= height
/ 2;
786 const char *src
= (const char *) dataIn
;
787 GLshort
*dest
= dataOut
;
790 assert(width
== 1 || height
== 1); /* must be 1D */
791 assert(width
!= height
); /* can't be square */
793 if (height
== 1) { /* 1 row */
794 assert(width
!= 1); /* widthxheight can't be 1x1 */
797 for (jj
= 0; jj
< halfWidth
; jj
++) {
799 for (kk
= 0; kk
< components
; kk
++) {
801 GLshort sshort
[BOX2
];
803 sshort
[0]= __GLU_SWAP_2_BYTES(src
);
804 sshort
[1]= __GLU_SWAP_2_BYTES(src
+group_size
);
807 sshort
[0]= *(const GLshort
*)src
;
808 sshort
[1]= *(const GLshort
*)(src
+group_size
);
811 *dest
= (sshort
[0] + sshort
[1]) / 2;
815 src
+= group_size
; /* skip to next 2 */
818 int padBytes
= ysize
- (width
*group_size
);
819 src
+= padBytes
; /* for assertion only */
822 else if (width
== 1) { /* 1 column */
823 int padBytes
= ysize
- (width
* group_size
);
824 assert(height
!= 1); /* widthxheight can't be 1x1 */
826 /* one vertical column with possible pad bytes per row */
827 /* average two at a time */
829 for (jj
= 0; jj
< halfHeight
; jj
++) {
831 for (kk
= 0; kk
< components
; kk
++) {
833 GLshort sshort
[BOX2
];
835 sshort
[0]= __GLU_SWAP_2_BYTES(src
);
836 sshort
[1]= __GLU_SWAP_2_BYTES(src
+ysize
);
839 sshort
[0]= *(const GLshort
*)src
;
840 sshort
[1]= *(const GLshort
*)(src
+ysize
);
842 *dest
= (sshort
[0] + sshort
[1]) / 2;
847 src
+= padBytes
; /* add pad bytes, if any, to get to end to row */
851 assert(src
== &((const char *)dataIn
)[ysize
*height
]);
854 assert((char *)dest
== &((char *)dataOut
)
855 [components
* element_size
* halfWidth
* halfHeight
]);
857 } /* halve1Dimage_short() */
860 static void halveImage_uint(GLint components
, GLuint width
, GLuint height
,
861 const GLuint
*datain
, GLuint
*dataout
,
862 GLint element_size
, GLint ysize
, GLint group_size
,
866 int newwidth
, newheight
;
871 /* handle case where there is only 1 column/row */
872 if (width
== 1 || height
== 1) {
873 assert( !(width
== 1 && height
== 1) ); /* can't be 1x1 */
874 halve1Dimage_uint(components
,width
,height
,datain
,dataout
,
875 element_size
,ysize
,group_size
, myswap_bytes
);
879 newwidth
= width
/ 2;
880 newheight
= height
/ 2;
881 padBytes
= ysize
- (width
*group_size
);
883 t
= (const char *)datain
;
887 for (i
= 0; i
< newheight
; i
++) {
888 for (j
= 0; j
< newwidth
; j
++) {
889 for (k
= 0; k
< components
; k
++) {
890 /* need to cast to double to hold large unsigned ints */
891 s
[0] = ((double)*(const GLuint
*)t
+
892 (double)*(const GLuint
*)(t
+group_size
) +
893 (double)*(const GLuint
*)(t
+ysize
) +
894 (double)*(const GLuint
*)(t
+ysize
+group_size
))/4 + 0.5;
895 s
++; t
+= element_size
;
904 for (i
= 0; i
< newheight
; i
++) {
905 for (j
= 0; j
< newwidth
; j
++) {
906 for (k
= 0; k
< components
; k
++) {
907 /* need to cast to double to hold large unsigned ints */
909 buf
= (GLdouble
)__GLU_SWAP_4_BYTES(t
) +
910 (GLdouble
)__GLU_SWAP_4_BYTES(t
+group_size
) +
911 (GLdouble
)__GLU_SWAP_4_BYTES(t
+ysize
) +
912 (GLdouble
)__GLU_SWAP_4_BYTES(t
+ysize
+group_size
);
913 s
[0] = (GLuint
)(buf
/4 + 0.5);
915 s
++; t
+= element_size
;
925 static void halve1Dimage_uint(GLint components
, GLuint width
, GLuint height
,
926 const GLuint
*dataIn
, GLuint
*dataOut
,
927 GLint element_size
, GLint ysize
,
928 GLint group_size
, GLint myswap_bytes
)
930 GLint halfWidth
= width
/ 2;
931 GLint halfHeight
= height
/ 2;
932 const char *src
= (const char *) dataIn
;
933 GLuint
*dest
= dataOut
;
936 assert(width
== 1 || height
== 1); /* must be 1D */
937 assert(width
!= height
); /* can't be square */
939 if (height
== 1) { /* 1 row */
940 assert(width
!= 1); /* widthxheight can't be 1x1 */
943 for (jj
= 0; jj
< halfWidth
; jj
++) {
945 for (kk
= 0; kk
< components
; kk
++) {
949 uint
[0]= __GLU_SWAP_4_BYTES(src
);
950 uint
[1]= __GLU_SWAP_4_BYTES(src
+group_size
);
953 uint
[0]= *(const GLuint
*)src
;
954 uint
[1]= *(const GLuint
*)(src
+group_size
);
956 *dest
= ((double)uint
[0]+(double)uint
[1])/2.0;
961 src
+= group_size
; /* skip to next 2 */
964 int padBytes
= ysize
- (width
*group_size
);
965 src
+= padBytes
; /* for assertion only */
968 else if (width
== 1) { /* 1 column */
969 int padBytes
= ysize
- (width
* group_size
);
970 assert(height
!= 1); /* widthxheight can't be 1x1 */
972 /* one vertical column with possible pad bytes per row */
973 /* average two at a time */
975 for (jj
= 0; jj
< halfHeight
; jj
++) {
977 for (kk
= 0; kk
< components
; kk
++) {
981 uint
[0]= __GLU_SWAP_4_BYTES(src
);
982 uint
[1]= __GLU_SWAP_4_BYTES(src
+ysize
);
985 uint
[0]= *(const GLuint
*)src
;
986 uint
[1]= *(const GLuint
*)(src
+ysize
);
988 *dest
= ((double)uint
[0]+(double)uint
[1])/2.0;
993 src
+= padBytes
; /* add pad bytes, if any, to get to end to row */
997 assert(src
== &((const char *)dataIn
)[ysize
*height
]);
1000 assert((char *)dest
== &((char *)dataOut
)
1001 [components
* element_size
* halfWidth
* halfHeight
]);
1003 } /* halve1Dimage_uint() */
1005 static void halveImage_int(GLint components
, GLuint width
, GLuint height
,
1006 const GLint
*datain
, GLint
*dataout
, GLint element_size
,
1007 GLint ysize
, GLint group_size
, GLint myswap_bytes
)
1010 int newwidth
, newheight
;
1015 /* handle case where there is only 1 column/row */
1016 if (width
== 1 || height
== 1) {
1017 assert( !(width
== 1 && height
== 1) ); /* can't be 1x1 */
1018 halve1Dimage_int(components
,width
,height
,datain
,dataout
,
1019 element_size
,ysize
,group_size
, myswap_bytes
);
1023 newwidth
= width
/ 2;
1024 newheight
= height
/ 2;
1025 padBytes
= ysize
- (width
*group_size
);
1027 t
= (const char *)datain
;
1029 /* Piece o' cake! */
1031 for (i
= 0; i
< newheight
; i
++) {
1032 for (j
= 0; j
< newwidth
; j
++) {
1033 for (k
= 0; k
< components
; k
++) {
1034 s
[0] = ((float)*(const GLint
*)t
+
1035 (float)*(const GLint
*)(t
+group_size
) +
1036 (float)*(const GLint
*)(t
+ysize
) +
1037 (float)*(const GLint
*)(t
+ysize
+group_size
))/4 + 0.5;
1038 s
++; t
+= element_size
;
1046 for (i
= 0; i
< newheight
; i
++) {
1047 for (j
= 0; j
< newwidth
; j
++) {
1048 for (k
= 0; k
< components
; k
++) {
1051 b
= __GLU_SWAP_4_BYTES(t
);
1053 b
= __GLU_SWAP_4_BYTES(t
+group_size
);
1055 b
= __GLU_SWAP_4_BYTES(t
+ysize
);
1057 b
= __GLU_SWAP_4_BYTES(t
+ysize
+group_size
);
1059 s
[0] = (GLint
)(buf
/4 + 0.5);
1061 s
++; t
+= element_size
;
1071 static void halve1Dimage_int(GLint components
, GLuint width
, GLuint height
,
1072 const GLint
*dataIn
, GLint
*dataOut
,
1073 GLint element_size
, GLint ysize
,
1074 GLint group_size
, GLint myswap_bytes
)
1076 GLint halfWidth
= width
/ 2;
1077 GLint halfHeight
= height
/ 2;
1078 const char *src
= (const char *) dataIn
;
1079 GLint
*dest
= dataOut
;
1082 assert(width
== 1 || height
== 1); /* must be 1D */
1083 assert(width
!= height
); /* can't be square */
1085 if (height
== 1) { /* 1 row */
1086 assert(width
!= 1); /* widthxheight can't be 1x1 */
1089 for (jj
= 0; jj
< halfWidth
; jj
++) {
1091 for (kk
= 0; kk
< components
; kk
++) {
1095 uint
[0]= __GLU_SWAP_4_BYTES(src
);
1096 uint
[1]= __GLU_SWAP_4_BYTES(src
+group_size
);
1099 uint
[0]= *(const GLuint
*)src
;
1100 uint
[1]= *(const GLuint
*)(src
+group_size
);
1102 *dest
= ((float)uint
[0]+(float)uint
[1])/2.0;
1107 src
+= group_size
; /* skip to next 2 */
1110 int padBytes
= ysize
- (width
*group_size
);
1111 src
+= padBytes
; /* for assertion only */
1114 else if (width
== 1) { /* 1 column */
1115 int padBytes
= ysize
- (width
* group_size
);
1116 assert(height
!= 1); /* widthxheight can't be 1x1 */
1118 /* one vertical column with possible pad bytes per row */
1119 /* average two at a time */
1121 for (jj
= 0; jj
< halfHeight
; jj
++) {
1123 for (kk
= 0; kk
< components
; kk
++) {
1127 uint
[0]= __GLU_SWAP_4_BYTES(src
);
1128 uint
[1]= __GLU_SWAP_4_BYTES(src
+ysize
);
1131 uint
[0]= *(const GLuint
*)src
;
1132 uint
[1]= *(const GLuint
*)(src
+ysize
);
1134 *dest
= ((float)uint
[0]+(float)uint
[1])/2.0;
1139 src
+= padBytes
; /* add pad bytes, if any, to get to end to row */
1143 assert(src
== &((const char *)dataIn
)[ysize
*height
]);
1146 assert((char *)dest
== &((char *)dataOut
)
1147 [components
* element_size
* halfWidth
* halfHeight
]);
1149 } /* halve1Dimage_int() */
1152 static void halveImage_float(GLint components
, GLuint width
, GLuint height
,
1153 const GLfloat
*datain
, GLfloat
*dataout
,
1154 GLint element_size
, GLint ysize
, GLint group_size
,
1158 int newwidth
, newheight
;
1163 /* handle case where there is only 1 column/row */
1164 if (width
== 1 || height
== 1) {
1165 assert( !(width
== 1 && height
== 1) ); /* can't be 1x1 */
1166 halve1Dimage_float(components
,width
,height
,datain
,dataout
,
1167 element_size
,ysize
,group_size
, myswap_bytes
);
1171 newwidth
= width
/ 2;
1172 newheight
= height
/ 2;
1173 padBytes
= ysize
- (width
*group_size
);
1175 t
= (const char *)datain
;
1177 /* Piece o' cake! */
1179 for (i
= 0; i
< newheight
; i
++) {
1180 for (j
= 0; j
< newwidth
; j
++) {
1181 for (k
= 0; k
< components
; k
++) {
1182 s
[0] = (*(const GLfloat
*)t
+
1183 *(const GLfloat
*)(t
+group_size
) +
1184 *(const GLfloat
*)(t
+ysize
) +
1185 *(const GLfloat
*)(t
+ysize
+group_size
)) / 4;
1186 s
++; t
+= element_size
;
1194 for (i
= 0; i
< newheight
; i
++) {
1195 for (j
= 0; j
< newwidth
; j
++) {
1196 for (k
= 0; k
< components
; k
++) {
1197 union { GLuint b
; GLfloat f
; } swapbuf
;
1198 swapbuf
.b
= __GLU_SWAP_4_BYTES(t
);
1200 swapbuf
.b
= __GLU_SWAP_4_BYTES(t
+group_size
);
1202 swapbuf
.b
= __GLU_SWAP_4_BYTES(t
+ysize
);
1204 swapbuf
.b
= __GLU_SWAP_4_BYTES(t
+ysize
+group_size
);
1207 s
++; t
+= element_size
;
1217 static void halve1Dimage_float(GLint components
, GLuint width
, GLuint height
,
1218 const GLfloat
*dataIn
, GLfloat
*dataOut
,
1219 GLint element_size
, GLint ysize
,
1220 GLint group_size
, GLint myswap_bytes
)
1222 GLint halfWidth
= width
/ 2;
1223 GLint halfHeight
= height
/ 2;
1224 const char *src
= (const char *) dataIn
;
1225 GLfloat
*dest
= dataOut
;
1228 assert(width
== 1 || height
== 1); /* must be 1D */
1229 assert(width
!= height
); /* can't be square */
1231 if (height
== 1) { /* 1 row */
1232 assert(width
!= 1); /* widthxheight can't be 1x1 */
1235 for (jj
= 0; jj
< halfWidth
; jj
++) {
1237 for (kk
= 0; kk
< components
; kk
++) {
1239 GLfloat sfloat
[BOX2
];
1241 sfloat
[0]= __GLU_SWAP_4_BYTES(src
);
1242 sfloat
[1]= __GLU_SWAP_4_BYTES(src
+group_size
);
1245 sfloat
[0]= *(const GLfloat
*)src
;
1246 sfloat
[1]= *(const GLfloat
*)(src
+group_size
);
1249 *dest
= (sfloat
[0] + sfloat
[1]) / 2.0;
1253 src
+= group_size
; /* skip to next 2 */
1256 int padBytes
= ysize
- (width
*group_size
);
1257 src
+= padBytes
; /* for assertion only */
1260 else if (width
== 1) { /* 1 column */
1261 int padBytes
= ysize
- (width
* group_size
);
1262 assert(height
!= 1); /* widthxheight can't be 1x1 */
1264 /* one vertical column with possible pad bytes per row */
1265 /* average two at a time */
1267 for (jj
= 0; jj
< halfHeight
; jj
++) {
1269 for (kk
= 0; kk
< components
; kk
++) {
1271 GLfloat sfloat
[BOX2
];
1273 sfloat
[0]= __GLU_SWAP_4_BYTES(src
);
1274 sfloat
[1]= __GLU_SWAP_4_BYTES(src
+ysize
);
1277 sfloat
[0]= *(const GLfloat
*)src
;
1278 sfloat
[1]= *(const GLfloat
*)(src
+ysize
);
1280 *dest
= (sfloat
[0] + sfloat
[1]) / 2.0;
1285 src
+= padBytes
; /* add pad bytes, if any, to get to end to row */
1286 src
+= ysize
; /* skip to odd row */
1290 assert(src
== &((const char *)dataIn
)[ysize
*height
]);
1291 assert((char *)dest
== &((char *)dataOut
)
1292 [components
* element_size
* halfWidth
* halfHeight
]);
1293 } /* halve1Dimage_float() */
1295 static void scale_internal(GLint components
, GLint widthin
, GLint heightin
,
1296 const GLushort
*datain
,
1297 GLint widthout
, GLint heightout
,
1300 float x
, lowx
, highx
, convx
, halfconvx
;
1301 float y
, lowy
, highy
, convy
, halfconvy
;
1302 float xpercent
,ypercent
;
1304 /* Max components in a format is 4, so... */
1307 int i
,j
,k
,yint
,xint
,xindex
,yindex
;
1310 if (widthin
== widthout
*2 && heightin
== heightout
*2) {
1311 halveImage(components
, widthin
, heightin
, datain
, dataout
);
1314 convy
= (float) heightin
/heightout
;
1315 convx
= (float) widthin
/widthout
;
1316 halfconvx
= convx
/2;
1317 halfconvy
= convy
/2;
1318 for (i
= 0; i
< heightout
; i
++) {
1319 y
= convy
* (i
+0.5);
1320 if (heightin
> heightout
) {
1321 highy
= y
+ halfconvy
;
1322 lowy
= y
- halfconvy
;
1327 for (j
= 0; j
< widthout
; j
++) {
1328 x
= convx
* (j
+0.5);
1329 if (widthin
> widthout
) {
1330 highx
= x
+ halfconvx
;
1331 lowx
= x
- halfconvx
;
1338 ** Ok, now apply box filter to box that goes from (lowx, lowy)
1339 ** to (highx, highy) on input data into this pixel on output
1342 totals
[0] = totals
[1] = totals
[2] = totals
[3] = 0.0;
1348 yindex
= (yint
+ heightin
) % heightin
;
1349 if (highy
< yint
+1) {
1350 ypercent
= highy
- y
;
1352 ypercent
= yint
+1 - y
;
1359 xindex
= (xint
+ widthin
) % widthin
;
1360 if (highx
< xint
+1) {
1361 xpercent
= highx
- x
;
1363 xpercent
= xint
+1 - x
;
1366 percent
= xpercent
* ypercent
;
1368 temp
= (xindex
+ (yindex
* widthin
)) * components
;
1369 for (k
= 0; k
< components
; k
++) {
1370 totals
[k
] += datain
[temp
+ k
] * percent
;
1380 temp
= (j
+ (i
* widthout
)) * components
;
1381 for (k
= 0; k
< components
; k
++) {
1382 /* totals[] should be rounded in the case of enlarging an RGB
1383 * ramp when the type is 332 or 4444
1385 dataout
[temp
+ k
] = (totals
[k
]+0.5)/area
;
1391 static void scale_internal_ubyte(GLint components
, GLint widthin
,
1392 GLint heightin
, const GLubyte
*datain
,
1393 GLint widthout
, GLint heightout
,
1394 GLubyte
*dataout
, GLint element_size
,
1395 GLint ysize
, GLint group_size
)
1400 /* Max components in a format is 4, so... */
1405 const char *temp
, *temp0
;
1406 const char *temp_index
;
1409 int lowx_int
, highx_int
, lowy_int
, highy_int
;
1410 float x_percent
, y_percent
;
1411 float lowx_float
, highx_float
, lowy_float
, highy_float
;
1412 float convy_float
, convx_float
;
1413 int convy_int
, convx_int
;
1415 const char *left
, *right
;
1417 if (widthin
== widthout
*2 && heightin
== heightout
*2) {
1418 halveImage_ubyte(components
, widthin
, heightin
,
1419 (const GLubyte
*)datain
, (GLubyte
*)dataout
,
1420 element_size
, ysize
, group_size
);
1423 convy
= (float) heightin
/heightout
;
1424 convx
= (float) widthin
/widthout
;
1425 convy_int
= floor(convy
);
1426 convy_float
= convy
- convy_int
;
1427 convx_int
= floor(convx
);
1428 convx_float
= convx
- convx_int
;
1430 area
= convx
* convy
;
1434 highy_int
= convy_int
;
1435 highy_float
= convy_float
;
1437 for (i
= 0; i
< heightout
; i
++) {
1438 /* Clamp here to be sure we don't read beyond input buffer. */
1439 if (highy_int
>= heightin
)
1440 highy_int
= heightin
- 1;
1443 highx_int
= convx_int
;
1444 highx_float
= convx_float
;
1446 for (j
= 0; j
< widthout
; j
++) {
1449 ** Ok, now apply box filter to box that goes from (lowx, lowy)
1450 ** to (highx, highy) on input data into this pixel on output
1453 totals
[0] = totals
[1] = totals
[2] = totals
[3] = 0.0;
1455 /* calculate the value for pixels in the 1st row */
1456 xindex
= lowx_int
*group_size
;
1457 if((highy_int
>lowy_int
) && (highx_int
>lowx_int
)) {
1459 y_percent
= 1-lowy_float
;
1460 temp
= (const char *)datain
+ xindex
+ lowy_int
* ysize
;
1461 percent
= y_percent
* (1-lowx_float
);
1462 for (k
= 0, temp_index
= temp
; k
< components
;
1463 k
++, temp_index
+= element_size
) {
1464 totals
[k
] += (GLubyte
)(*(temp_index
)) * percent
;
1467 for(l
= lowx_int
+1; l
< highx_int
; l
++) {
1469 for (k
= 0, temp_index
= temp
; k
< components
;
1470 k
++, temp_index
+= element_size
) {
1471 totals
[k
] += (GLubyte
)(*(temp_index
)) * y_percent
;
1476 percent
= y_percent
* highx_float
;
1477 for (k
= 0, temp_index
= temp
; k
< components
;
1478 k
++, temp_index
+= element_size
) {
1479 totals
[k
] += (GLubyte
)(*(temp_index
)) * percent
;
1482 /* calculate the value for pixels in the last row */
1483 y_percent
= highy_float
;
1484 percent
= y_percent
* (1-lowx_float
);
1485 temp
= (const char *)datain
+ xindex
+ highy_int
* ysize
;
1486 for (k
= 0, temp_index
= temp
; k
< components
;
1487 k
++, temp_index
+= element_size
) {
1488 totals
[k
] += (GLubyte
)(*(temp_index
)) * percent
;
1490 for(l
= lowx_int
+1; l
< highx_int
; l
++) {
1492 for (k
= 0, temp_index
= temp
; k
< components
;
1493 k
++, temp_index
+= element_size
) {
1494 totals
[k
] += (GLubyte
)(*(temp_index
)) * y_percent
;
1498 percent
= y_percent
* highx_float
;
1499 for (k
= 0, temp_index
= temp
; k
< components
;
1500 k
++, temp_index
+= element_size
) {
1501 totals
[k
] += (GLubyte
)(*(temp_index
)) * percent
;
1505 /* calculate the value for pixels in the 1st and last column */
1506 for(m
= lowy_int
+1; m
< highy_int
; m
++) {
1509 for (k
= 0; k
< components
;
1510 k
++, left
+= element_size
, right
+= element_size
) {
1511 totals
[k
] += (GLubyte
)(*(left
))*(1-lowx_float
)
1512 +(GLubyte
)(*(right
))*highx_float
;
1515 } else if (highy_int
> lowy_int
) {
1516 x_percent
= highx_float
- lowx_float
;
1517 percent
= (1-lowy_float
)*x_percent
;
1518 temp
= (const char *)datain
+ xindex
+ lowy_int
*ysize
;
1519 for (k
= 0, temp_index
= temp
; k
< components
;
1520 k
++, temp_index
+= element_size
) {
1521 totals
[k
] += (GLubyte
)(*(temp_index
)) * percent
;
1523 for(m
= lowy_int
+1; m
< highy_int
; m
++) {
1525 for (k
= 0, temp_index
= temp
; k
< components
;
1526 k
++, temp_index
+= element_size
) {
1527 totals
[k
] += (GLubyte
)(*(temp_index
)) * x_percent
;
1530 percent
= x_percent
* highy_float
;
1532 for (k
= 0, temp_index
= temp
; k
< components
;
1533 k
++, temp_index
+= element_size
) {
1534 totals
[k
] += (GLubyte
)(*(temp_index
)) * percent
;
1536 } else if (highx_int
> lowx_int
) {
1537 y_percent
= highy_float
- lowy_float
;
1538 percent
= (1-lowx_float
)*y_percent
;
1539 temp
= (const char *)datain
+ xindex
+ lowy_int
*ysize
;
1540 for (k
= 0, temp_index
= temp
; k
< components
;
1541 k
++, temp_index
+= element_size
) {
1542 totals
[k
] += (GLubyte
)(*(temp_index
)) * percent
;
1544 for (l
= lowx_int
+1; l
< highx_int
; l
++) {
1546 for (k
= 0, temp_index
= temp
; k
< components
;
1547 k
++, temp_index
+= element_size
) {
1548 totals
[k
] += (GLubyte
)(*(temp_index
)) * y_percent
;
1552 percent
= y_percent
* highx_float
;
1553 for (k
= 0, temp_index
= temp
; k
< components
;
1554 k
++, temp_index
+= element_size
) {
1555 totals
[k
] += (GLubyte
)(*(temp_index
)) * percent
;
1558 percent
= (highy_float
-lowy_float
)*(highx_float
-lowx_float
);
1559 temp
= (const char *)datain
+ xindex
+ lowy_int
* ysize
;
1560 for (k
= 0, temp_index
= temp
; k
< components
;
1561 k
++, temp_index
+= element_size
) {
1562 totals
[k
] += (GLubyte
)(*(temp_index
)) * percent
;
1568 /* this is for the pixels in the body */
1569 temp0
= (const char *)datain
+ xindex
+ group_size
+
1571 for (m
= lowy_int
+1; m
< highy_int
; m
++) {
1573 for(l
= lowx_int
+1; l
< highx_int
; l
++) {
1574 for (k
= 0, temp_index
= temp
; k
< components
;
1575 k
++, temp_index
+= element_size
) {
1576 totals
[k
] += (GLubyte
)(*(temp_index
));
1583 outindex
= (j
+ (i
* widthout
)) * components
;
1584 for (k
= 0; k
< components
; k
++) {
1585 dataout
[outindex
+ k
] = totals
[k
]/area
;
1586 /*printf("totals[%d] = %f\n", k, totals[k]);*/
1588 lowx_int
= highx_int
;
1589 lowx_float
= highx_float
;
1590 highx_int
+= convx_int
;
1591 highx_float
+= convx_float
;
1592 if(highx_float
> 1) {
1597 lowy_int
= highy_int
;
1598 lowy_float
= highy_float
;
1599 highy_int
+= convy_int
;
1600 highy_float
+= convy_float
;
1601 if(highy_float
> 1) {
1608 static void scale_internal_byte(GLint components
, GLint widthin
,
1609 GLint heightin
, const GLbyte
*datain
,
1610 GLint widthout
, GLint heightout
,
1611 GLbyte
*dataout
, GLint element_size
,
1612 GLint ysize
, GLint group_size
)
1617 /* Max components in a format is 4, so... */
1622 const char *temp
, *temp0
;
1623 const char *temp_index
;
1626 int lowx_int
, highx_int
, lowy_int
, highy_int
;
1627 float x_percent
, y_percent
;
1628 float lowx_float
, highx_float
, lowy_float
, highy_float
;
1629 float convy_float
, convx_float
;
1630 int convy_int
, convx_int
;
1632 const char *left
, *right
;
1634 if (widthin
== widthout
*2 && heightin
== heightout
*2) {
1635 halveImage_byte(components
, widthin
, heightin
,
1636 (const GLbyte
*)datain
, (GLbyte
*)dataout
,
1637 element_size
, ysize
, group_size
);
1640 convy
= (float) heightin
/heightout
;
1641 convx
= (float) widthin
/widthout
;
1642 convy_int
= floor(convy
);
1643 convy_float
= convy
- convy_int
;
1644 convx_int
= floor(convx
);
1645 convx_float
= convx
- convx_int
;
1647 area
= convx
* convy
;
1651 highy_int
= convy_int
;
1652 highy_float
= convy_float
;
1654 for (i
= 0; i
< heightout
; i
++) {
1655 /* Clamp here to be sure we don't read beyond input buffer. */
1656 if (highy_int
>= heightin
)
1657 highy_int
= heightin
- 1;
1660 highx_int
= convx_int
;
1661 highx_float
= convx_float
;
1663 for (j
= 0; j
< widthout
; j
++) {
1666 ** Ok, now apply box filter to box that goes from (lowx, lowy)
1667 ** to (highx, highy) on input data into this pixel on output
1670 totals
[0] = totals
[1] = totals
[2] = totals
[3] = 0.0;
1672 /* calculate the value for pixels in the 1st row */
1673 xindex
= lowx_int
*group_size
;
1674 if((highy_int
>lowy_int
) && (highx_int
>lowx_int
)) {
1676 y_percent
= 1-lowy_float
;
1677 temp
= (const char *)datain
+ xindex
+ lowy_int
* ysize
;
1678 percent
= y_percent
* (1-lowx_float
);
1679 for (k
= 0, temp_index
= temp
; k
< components
;
1680 k
++, temp_index
+= element_size
) {
1681 totals
[k
] += (GLbyte
)(*(temp_index
)) * percent
;
1684 for(l
= lowx_int
+1; l
< highx_int
; l
++) {
1686 for (k
= 0, temp_index
= temp
; k
< components
;
1687 k
++, temp_index
+= element_size
) {
1688 totals
[k
] += (GLbyte
)(*(temp_index
)) * y_percent
;
1693 percent
= y_percent
* highx_float
;
1694 for (k
= 0, temp_index
= temp
; k
< components
;
1695 k
++, temp_index
+= element_size
) {
1696 totals
[k
] += (GLbyte
)(*(temp_index
)) * percent
;
1699 /* calculate the value for pixels in the last row */
1700 y_percent
= highy_float
;
1701 percent
= y_percent
* (1-lowx_float
);
1702 temp
= (const char *)datain
+ xindex
+ highy_int
* ysize
;
1703 for (k
= 0, temp_index
= temp
; k
< components
;
1704 k
++, temp_index
+= element_size
) {
1705 totals
[k
] += (GLbyte
)(*(temp_index
)) * percent
;
1707 for(l
= lowx_int
+1; l
< highx_int
; l
++) {
1709 for (k
= 0, temp_index
= temp
; k
< components
;
1710 k
++, temp_index
+= element_size
) {
1711 totals
[k
] += (GLbyte
)(*(temp_index
)) * y_percent
;
1715 percent
= y_percent
* highx_float
;
1716 for (k
= 0, temp_index
= temp
; k
< components
;
1717 k
++, temp_index
+= element_size
) {
1718 totals
[k
] += (GLbyte
)(*(temp_index
)) * percent
;
1722 /* calculate the value for pixels in the 1st and last column */
1723 for(m
= lowy_int
+1; m
< highy_int
; m
++) {
1726 for (k
= 0; k
< components
;
1727 k
++, left
+= element_size
, right
+= element_size
) {
1728 totals
[k
] += (GLbyte
)(*(left
))*(1-lowx_float
)
1729 +(GLbyte
)(*(right
))*highx_float
;
1732 } else if (highy_int
> lowy_int
) {
1733 x_percent
= highx_float
- lowx_float
;
1734 percent
= (1-lowy_float
)*x_percent
;
1735 temp
= (const char *)datain
+ xindex
+ lowy_int
*ysize
;
1736 for (k
= 0, temp_index
= temp
; k
< components
;
1737 k
++, temp_index
+= element_size
) {
1738 totals
[k
] += (GLbyte
)(*(temp_index
)) * percent
;
1740 for(m
= lowy_int
+1; m
< highy_int
; m
++) {
1742 for (k
= 0, temp_index
= temp
; k
< components
;
1743 k
++, temp_index
+= element_size
) {
1744 totals
[k
] += (GLbyte
)(*(temp_index
)) * x_percent
;
1747 percent
= x_percent
* highy_float
;
1749 for (k
= 0, temp_index
= temp
; k
< components
;
1750 k
++, temp_index
+= element_size
) {
1751 totals
[k
] += (GLbyte
)(*(temp_index
)) * percent
;
1753 } else if (highx_int
> lowx_int
) {
1754 y_percent
= highy_float
- lowy_float
;
1755 percent
= (1-lowx_float
)*y_percent
;
1756 temp
= (const char *)datain
+ xindex
+ lowy_int
*ysize
;
1757 for (k
= 0, temp_index
= temp
; k
< components
;
1758 k
++, temp_index
+= element_size
) {
1759 totals
[k
] += (GLbyte
)(*(temp_index
)) * percent
;
1761 for (l
= lowx_int
+1; l
< highx_int
; l
++) {
1763 for (k
= 0, temp_index
= temp
; k
< components
;
1764 k
++, temp_index
+= element_size
) {
1765 totals
[k
] += (GLbyte
)(*(temp_index
)) * y_percent
;
1769 percent
= y_percent
* highx_float
;
1770 for (k
= 0, temp_index
= temp
; k
< components
;
1771 k
++, temp_index
+= element_size
) {
1772 totals
[k
] += (GLbyte
)(*(temp_index
)) * percent
;
1775 percent
= (highy_float
-lowy_float
)*(highx_float
-lowx_float
);
1776 temp
= (const char *)datain
+ xindex
+ lowy_int
* ysize
;
1777 for (k
= 0, temp_index
= temp
; k
< components
;
1778 k
++, temp_index
+= element_size
) {
1779 totals
[k
] += (GLbyte
)(*(temp_index
)) * percent
;
1785 /* this is for the pixels in the body */
1786 temp0
= (const char *)datain
+ xindex
+ group_size
+
1788 for (m
= lowy_int
+1; m
< highy_int
; m
++) {
1790 for(l
= lowx_int
+1; l
< highx_int
; l
++) {
1791 for (k
= 0, temp_index
= temp
; k
< components
;
1792 k
++, temp_index
+= element_size
) {
1793 totals
[k
] += (GLbyte
)(*(temp_index
));
1800 outindex
= (j
+ (i
* widthout
)) * components
;
1801 for (k
= 0; k
< components
; k
++) {
1802 dataout
[outindex
+ k
] = totals
[k
]/area
;
1803 /*printf("totals[%d] = %f\n", k, totals[k]);*/
1805 lowx_int
= highx_int
;
1806 lowx_float
= highx_float
;
1807 highx_int
+= convx_int
;
1808 highx_float
+= convx_float
;
1809 if(highx_float
> 1) {
1814 lowy_int
= highy_int
;
1815 lowy_float
= highy_float
;
1816 highy_int
+= convy_int
;
1817 highy_float
+= convy_float
;
1818 if(highy_float
> 1) {
1825 static void scale_internal_ushort(GLint components
, GLint widthin
,
1826 GLint heightin
, const GLushort
*datain
,
1827 GLint widthout
, GLint heightout
,
1828 GLushort
*dataout
, GLint element_size
,
1829 GLint ysize
, GLint group_size
,
1835 /* Max components in a format is 4, so... */
1840 const char *temp
, *temp0
;
1841 const char *temp_index
;
1844 int lowx_int
, highx_int
, lowy_int
, highy_int
;
1845 float x_percent
, y_percent
;
1846 float lowx_float
, highx_float
, lowy_float
, highy_float
;
1847 float convy_float
, convx_float
;
1848 int convy_int
, convx_int
;
1850 const char *left
, *right
;
1852 if (widthin
== widthout
*2 && heightin
== heightout
*2) {
1853 halveImage_ushort(components
, widthin
, heightin
,
1854 (const GLushort
*)datain
, (GLushort
*)dataout
,
1855 element_size
, ysize
, group_size
, myswap_bytes
);
1858 convy
= (float) heightin
/heightout
;
1859 convx
= (float) widthin
/widthout
;
1860 convy_int
= floor(convy
);
1861 convy_float
= convy
- convy_int
;
1862 convx_int
= floor(convx
);
1863 convx_float
= convx
- convx_int
;
1865 area
= convx
* convy
;
1869 highy_int
= convy_int
;
1870 highy_float
= convy_float
;
1872 for (i
= 0; i
< heightout
; i
++) {
1873 /* Clamp here to be sure we don't read beyond input buffer. */
1874 if (highy_int
>= heightin
)
1875 highy_int
= heightin
- 1;
1878 highx_int
= convx_int
;
1879 highx_float
= convx_float
;
1881 for (j
= 0; j
< widthout
; j
++) {
1883 ** Ok, now apply box filter to box that goes from (lowx, lowy)
1884 ** to (highx, highy) on input data into this pixel on output
1887 totals
[0] = totals
[1] = totals
[2] = totals
[3] = 0.0;
1889 /* calculate the value for pixels in the 1st row */
1890 xindex
= lowx_int
*group_size
;
1891 if((highy_int
>lowy_int
) && (highx_int
>lowx_int
)) {
1893 y_percent
= 1-lowy_float
;
1894 temp
= (const char *)datain
+ xindex
+ lowy_int
* ysize
;
1895 percent
= y_percent
* (1-lowx_float
);
1896 for (k
= 0, temp_index
= temp
; k
< components
;
1897 k
++, temp_index
+= element_size
) {
1899 totals
[k
] += __GLU_SWAP_2_BYTES(temp_index
) * percent
;
1901 totals
[k
] += *(const GLushort
*)temp_index
* percent
;
1905 for(l
= lowx_int
+1; l
< highx_int
; l
++) {
1907 for (k
= 0, temp_index
= temp
; k
< components
;
1908 k
++, temp_index
+= element_size
) {
1911 __GLU_SWAP_2_BYTES(temp_index
) * y_percent
;
1913 totals
[k
] += *(const GLushort
*)temp_index
* y_percent
;
1919 percent
= y_percent
* highx_float
;
1920 for (k
= 0, temp_index
= temp
; k
< components
;
1921 k
++, temp_index
+= element_size
) {
1923 totals
[k
] += __GLU_SWAP_2_BYTES(temp_index
) * percent
;
1925 totals
[k
] += *(const GLushort
*)temp_index
* percent
;
1929 /* calculate the value for pixels in the last row */
1930 y_percent
= highy_float
;
1931 percent
= y_percent
* (1-lowx_float
);
1932 temp
= (const char *)datain
+ xindex
+ highy_int
* ysize
;
1933 for (k
= 0, temp_index
= temp
; k
< components
;
1934 k
++, temp_index
+= element_size
) {
1936 totals
[k
] += __GLU_SWAP_2_BYTES(temp_index
) * percent
;
1938 totals
[k
] += *(const GLushort
*)temp_index
* percent
;
1941 for(l
= lowx_int
+1; l
< highx_int
; l
++) {
1943 for (k
= 0, temp_index
= temp
; k
< components
;
1944 k
++, temp_index
+= element_size
) {
1947 __GLU_SWAP_2_BYTES(temp_index
) * y_percent
;
1949 totals
[k
] += *(const GLushort
*)temp_index
* y_percent
;
1954 percent
= y_percent
* highx_float
;
1955 for (k
= 0, temp_index
= temp
; k
< components
;
1956 k
++, temp_index
+= element_size
) {
1958 totals
[k
] += __GLU_SWAP_2_BYTES(temp_index
) * percent
;
1960 totals
[k
] += *(const GLushort
*)temp_index
* percent
;
1964 /* calculate the value for pixels in the 1st and last column */
1965 for(m
= lowy_int
+1; m
< highy_int
; m
++) {
1968 for (k
= 0; k
< components
;
1969 k
++, left
+= element_size
, right
+= element_size
) {
1972 __GLU_SWAP_2_BYTES(left
) * (1-lowx_float
) +
1973 __GLU_SWAP_2_BYTES(right
) * highx_float
;
1975 totals
[k
] += *(const GLushort
*)left
* (1-lowx_float
)
1976 + *(const GLushort
*)right
* highx_float
;
1980 } else if (highy_int
> lowy_int
) {
1981 x_percent
= highx_float
- lowx_float
;
1982 percent
= (1-lowy_float
)*x_percent
;
1983 temp
= (const char *)datain
+ xindex
+ lowy_int
*ysize
;
1984 for (k
= 0, temp_index
= temp
; k
< components
;
1985 k
++, temp_index
+= element_size
) {
1987 totals
[k
] += __GLU_SWAP_2_BYTES(temp_index
) * percent
;
1989 totals
[k
] += *(const GLushort
*)temp_index
* percent
;
1992 for(m
= lowy_int
+1; m
< highy_int
; m
++) {
1994 for (k
= 0, temp_index
= temp
; k
< components
;
1995 k
++, temp_index
+= element_size
) {
1998 __GLU_SWAP_2_BYTES(temp_index
) * x_percent
;
2000 totals
[k
] += *(const GLushort
*)temp_index
* x_percent
;
2004 percent
= x_percent
* highy_float
;
2006 for (k
= 0, temp_index
= temp
; k
< components
;
2007 k
++, temp_index
+= element_size
) {
2009 totals
[k
] += __GLU_SWAP_2_BYTES(temp_index
) * percent
;
2011 totals
[k
] += *(const GLushort
*)temp_index
* percent
;
2014 } else if (highx_int
> lowx_int
) {
2015 y_percent
= highy_float
- lowy_float
;
2016 percent
= (1-lowx_float
)*y_percent
;
2017 temp
= (const char *)datain
+ xindex
+ lowy_int
*ysize
;
2018 for (k
= 0, temp_index
= temp
; k
< components
;
2019 k
++, temp_index
+= element_size
) {
2021 totals
[k
] += __GLU_SWAP_2_BYTES(temp_index
) * percent
;
2023 totals
[k
] += *(const GLushort
*)temp_index
* percent
;
2026 for (l
= lowx_int
+1; l
< highx_int
; l
++) {
2028 for (k
= 0, temp_index
= temp
; k
< components
;
2029 k
++, temp_index
+= element_size
) {
2032 __GLU_SWAP_2_BYTES(temp_index
) * y_percent
;
2034 totals
[k
] += *(const GLushort
*)temp_index
* y_percent
;
2039 percent
= y_percent
* highx_float
;
2040 for (k
= 0, temp_index
= temp
; k
< components
;
2041 k
++, temp_index
+= element_size
) {
2043 totals
[k
] += __GLU_SWAP_2_BYTES(temp_index
) * percent
;
2045 totals
[k
] += *(const GLushort
*)temp_index
* percent
;
2049 percent
= (highy_float
-lowy_float
)*(highx_float
-lowx_float
);
2050 temp
= (const char *)datain
+ xindex
+ lowy_int
* ysize
;
2051 for (k
= 0, temp_index
= temp
; k
< components
;
2052 k
++, temp_index
+= element_size
) {
2054 totals
[k
] += __GLU_SWAP_2_BYTES(temp_index
) * percent
;
2056 totals
[k
] += *(const GLushort
*)temp_index
* percent
;
2061 /* this is for the pixels in the body */
2062 temp0
= (const char *)datain
+ xindex
+ group_size
+
2064 for (m
= lowy_int
+1; m
< highy_int
; m
++) {
2066 for(l
= lowx_int
+1; l
< highx_int
; l
++) {
2067 for (k
= 0, temp_index
= temp
; k
< components
;
2068 k
++, temp_index
+= element_size
) {
2070 totals
[k
] += __GLU_SWAP_2_BYTES(temp_index
);
2072 totals
[k
] += *(const GLushort
*)temp_index
;
2080 outindex
= (j
+ (i
* widthout
)) * components
;
2081 for (k
= 0; k
< components
; k
++) {
2082 dataout
[outindex
+ k
] = totals
[k
]/area
;
2083 /*printf("totals[%d] = %f\n", k, totals[k]);*/
2085 lowx_int
= highx_int
;
2086 lowx_float
= highx_float
;
2087 highx_int
+= convx_int
;
2088 highx_float
+= convx_float
;
2089 if(highx_float
> 1) {
2094 lowy_int
= highy_int
;
2095 lowy_float
= highy_float
;
2096 highy_int
+= convy_int
;
2097 highy_float
+= convy_float
;
2098 if(highy_float
> 1) {
2105 static void scale_internal_short(GLint components
, GLint widthin
,
2106 GLint heightin
, const GLshort
*datain
,
2107 GLint widthout
, GLint heightout
,
2108 GLshort
*dataout
, GLint element_size
,
2109 GLint ysize
, GLint group_size
,
2115 /* Max components in a format is 4, so... */
2120 const char *temp
, *temp0
;
2121 const char *temp_index
;
2124 int lowx_int
, highx_int
, lowy_int
, highy_int
;
2125 float x_percent
, y_percent
;
2126 float lowx_float
, highx_float
, lowy_float
, highy_float
;
2127 float convy_float
, convx_float
;
2128 int convy_int
, convx_int
;
2130 const char *left
, *right
;
2132 GLushort swapbuf
; /* unsigned buffer */
2134 if (widthin
== widthout
*2 && heightin
== heightout
*2) {
2135 halveImage_short(components
, widthin
, heightin
,
2136 (const GLshort
*)datain
, (GLshort
*)dataout
,
2137 element_size
, ysize
, group_size
, myswap_bytes
);
2140 convy
= (float) heightin
/heightout
;
2141 convx
= (float) widthin
/widthout
;
2142 convy_int
= floor(convy
);
2143 convy_float
= convy
- convy_int
;
2144 convx_int
= floor(convx
);
2145 convx_float
= convx
- convx_int
;
2147 area
= convx
* convy
;
2151 highy_int
= convy_int
;
2152 highy_float
= convy_float
;
2154 for (i
= 0; i
< heightout
; i
++) {
2155 /* Clamp here to be sure we don't read beyond input buffer. */
2156 if (highy_int
>= heightin
)
2157 highy_int
= heightin
- 1;
2160 highx_int
= convx_int
;
2161 highx_float
= convx_float
;
2163 for (j
= 0; j
< widthout
; j
++) {
2165 ** Ok, now apply box filter to box that goes from (lowx, lowy)
2166 ** to (highx, highy) on input data into this pixel on output
2169 totals
[0] = totals
[1] = totals
[2] = totals
[3] = 0.0;
2171 /* calculate the value for pixels in the 1st row */
2172 xindex
= lowx_int
*group_size
;
2173 if((highy_int
>lowy_int
) && (highx_int
>lowx_int
)) {
2175 y_percent
= 1-lowy_float
;
2176 temp
= (const char *)datain
+ xindex
+ lowy_int
* ysize
;
2177 percent
= y_percent
* (1-lowx_float
);
2178 for (k
= 0, temp_index
= temp
; k
< components
;
2179 k
++, temp_index
+= element_size
) {
2181 swapbuf
= __GLU_SWAP_2_BYTES(temp_index
);
2182 totals
[k
] += *(const GLshort
*)&swapbuf
* percent
;
2184 totals
[k
] += *(const GLshort
*)temp_index
* percent
;
2188 for(l
= lowx_int
+1; l
< highx_int
; l
++) {
2190 for (k
= 0, temp_index
= temp
; k
< components
;
2191 k
++, temp_index
+= element_size
) {
2193 swapbuf
= __GLU_SWAP_2_BYTES(temp_index
);
2194 totals
[k
] += *(const GLshort
*)&swapbuf
* y_percent
;
2196 totals
[k
] += *(const GLshort
*)temp_index
* y_percent
;
2202 percent
= y_percent
* highx_float
;
2203 for (k
= 0, temp_index
= temp
; k
< components
;
2204 k
++, temp_index
+= element_size
) {
2206 swapbuf
= __GLU_SWAP_2_BYTES(temp_index
);
2207 totals
[k
] += *(const GLshort
*)&swapbuf
* percent
;
2209 totals
[k
] += *(const GLshort
*)temp_index
* percent
;
2213 /* calculate the value for pixels in the last row */
2214 y_percent
= highy_float
;
2215 percent
= y_percent
* (1-lowx_float
);
2216 temp
= (const char *)datain
+ xindex
+ highy_int
* ysize
;
2217 for (k
= 0, temp_index
= temp
; k
< components
;
2218 k
++, temp_index
+= element_size
) {
2220 swapbuf
= __GLU_SWAP_2_BYTES(temp_index
);
2221 totals
[k
] += *(const GLshort
*)&swapbuf
* percent
;
2223 totals
[k
] += *(const GLshort
*)temp_index
* percent
;
2226 for(l
= lowx_int
+1; l
< highx_int
; l
++) {
2228 for (k
= 0, temp_index
= temp
; k
< components
;
2229 k
++, temp_index
+= element_size
) {
2231 swapbuf
= __GLU_SWAP_2_BYTES(temp_index
);
2232 totals
[k
] += *(const GLshort
*)&swapbuf
* y_percent
;
2234 totals
[k
] += *(const GLshort
*)temp_index
* y_percent
;
2239 percent
= y_percent
* highx_float
;
2240 for (k
= 0, temp_index
= temp
; k
< components
;
2241 k
++, temp_index
+= element_size
) {
2243 swapbuf
= __GLU_SWAP_2_BYTES(temp_index
);
2244 totals
[k
] += *(const GLshort
*)&swapbuf
* percent
;
2246 totals
[k
] += *(const GLshort
*)temp_index
* percent
;
2250 /* calculate the value for pixels in the 1st and last column */
2251 for(m
= lowy_int
+1; m
< highy_int
; m
++) {
2254 for (k
= 0; k
< components
;
2255 k
++, left
+= element_size
, right
+= element_size
) {
2257 swapbuf
= __GLU_SWAP_2_BYTES(left
);
2258 totals
[k
] += *(const GLshort
*)&swapbuf
* (1-lowx_float
);
2259 swapbuf
= __GLU_SWAP_2_BYTES(right
);
2260 totals
[k
] += *(const GLshort
*)&swapbuf
* highx_float
;
2262 totals
[k
] += *(const GLshort
*)left
* (1-lowx_float
)
2263 + *(const GLshort
*)right
* highx_float
;
2267 } else if (highy_int
> lowy_int
) {
2268 x_percent
= highx_float
- lowx_float
;
2269 percent
= (1-lowy_float
)*x_percent
;
2270 temp
= (const char *)datain
+ xindex
+ lowy_int
*ysize
;
2271 for (k
= 0, temp_index
= temp
; k
< components
;
2272 k
++, temp_index
+= element_size
) {
2274 swapbuf
= __GLU_SWAP_2_BYTES(temp_index
);
2275 totals
[k
] += *(const GLshort
*)&swapbuf
* percent
;
2277 totals
[k
] += *(const GLshort
*)temp_index
* percent
;
2280 for(m
= lowy_int
+1; m
< highy_int
; m
++) {
2282 for (k
= 0, temp_index
= temp
; k
< components
;
2283 k
++, temp_index
+= element_size
) {
2285 swapbuf
= __GLU_SWAP_2_BYTES(temp_index
);
2286 totals
[k
] += *(const GLshort
*)&swapbuf
* x_percent
;
2288 totals
[k
] += *(const GLshort
*)temp_index
* x_percent
;
2292 percent
= x_percent
* highy_float
;
2294 for (k
= 0, temp_index
= temp
; k
< components
;
2295 k
++, temp_index
+= element_size
) {
2297 swapbuf
= __GLU_SWAP_2_BYTES(temp_index
);
2298 totals
[k
] += *(const GLshort
*)&swapbuf
* percent
;
2300 totals
[k
] += *(const GLshort
*)temp_index
* percent
;
2303 } else if (highx_int
> lowx_int
) {
2304 y_percent
= highy_float
- lowy_float
;
2305 percent
= (1-lowx_float
)*y_percent
;
2307 temp
= (const char *)datain
+ xindex
+ lowy_int
*ysize
;
2308 for (k
= 0, temp_index
= temp
; k
< components
;
2309 k
++, temp_index
+= element_size
) {
2311 swapbuf
= __GLU_SWAP_2_BYTES(temp_index
);
2312 totals
[k
] += *(const GLshort
*)&swapbuf
* percent
;
2314 totals
[k
] += *(const GLshort
*)temp_index
* percent
;
2317 for (l
= lowx_int
+1; l
< highx_int
; l
++) {
2319 for (k
= 0, temp_index
= temp
; k
< components
;
2320 k
++, temp_index
+= element_size
) {
2322 swapbuf
= __GLU_SWAP_2_BYTES(temp_index
);
2323 totals
[k
] += *(const GLshort
*)&swapbuf
* y_percent
;
2325 totals
[k
] += *(const GLshort
*)temp_index
* y_percent
;
2330 percent
= y_percent
* highx_float
;
2331 for (k
= 0, temp_index
= temp
; k
< components
;
2332 k
++, temp_index
+= element_size
) {
2334 swapbuf
= __GLU_SWAP_2_BYTES(temp_index
);
2335 totals
[k
] += *(const GLshort
*)&swapbuf
* percent
;
2337 totals
[k
] += *(const GLshort
*)temp_index
* percent
;
2341 percent
= (highy_float
-lowy_float
)*(highx_float
-lowx_float
);
2342 temp
= (const char *)datain
+ xindex
+ lowy_int
* ysize
;
2343 for (k
= 0, temp_index
= temp
; k
< components
;
2344 k
++, temp_index
+= element_size
) {
2346 swapbuf
= __GLU_SWAP_2_BYTES(temp_index
);
2347 totals
[k
] += *(const GLshort
*)&swapbuf
* percent
;
2349 totals
[k
] += *(const GLshort
*)temp_index
* percent
;
2354 /* this is for the pixels in the body */
2355 temp0
= (const char *)datain
+ xindex
+ group_size
+
2357 for (m
= lowy_int
+1; m
< highy_int
; m
++) {
2359 for(l
= lowx_int
+1; l
< highx_int
; l
++) {
2360 for (k
= 0, temp_index
= temp
; k
< components
;
2361 k
++, temp_index
+= element_size
) {
2363 swapbuf
= __GLU_SWAP_2_BYTES(temp_index
);
2364 totals
[k
] += *(const GLshort
*)&swapbuf
;
2366 totals
[k
] += *(const GLshort
*)temp_index
;
2374 outindex
= (j
+ (i
* widthout
)) * components
;
2375 for (k
= 0; k
< components
; k
++) {
2376 dataout
[outindex
+ k
] = totals
[k
]/area
;
2377 /*printf("totals[%d] = %f\n", k, totals[k]);*/
2379 lowx_int
= highx_int
;
2380 lowx_float
= highx_float
;
2381 highx_int
+= convx_int
;
2382 highx_float
+= convx_float
;
2383 if(highx_float
> 1) {
2388 lowy_int
= highy_int
;
2389 lowy_float
= highy_float
;
2390 highy_int
+= convy_int
;
2391 highy_float
+= convy_float
;
2392 if(highy_float
> 1) {
2399 static void scale_internal_uint(GLint components
, GLint widthin
,
2400 GLint heightin
, const GLuint
*datain
,
2401 GLint widthout
, GLint heightout
,
2402 GLuint
*dataout
, GLint element_size
,
2403 GLint ysize
, GLint group_size
,
2409 /* Max components in a format is 4, so... */
2414 const char *temp
, *temp0
;
2415 const char *temp_index
;
2418 int lowx_int
, highx_int
, lowy_int
, highy_int
;
2419 float x_percent
, y_percent
;
2420 float lowx_float
, highx_float
, lowy_float
, highy_float
;
2421 float convy_float
, convx_float
;
2422 int convy_int
, convx_int
;
2424 const char *left
, *right
;
2426 if (widthin
== widthout
*2 && heightin
== heightout
*2) {
2427 halveImage_uint(components
, widthin
, heightin
,
2428 (const GLuint
*)datain
, (GLuint
*)dataout
,
2429 element_size
, ysize
, group_size
, myswap_bytes
);
2432 convy
= (float) heightin
/heightout
;
2433 convx
= (float) widthin
/widthout
;
2434 convy_int
= floor(convy
);
2435 convy_float
= convy
- convy_int
;
2436 convx_int
= floor(convx
);
2437 convx_float
= convx
- convx_int
;
2439 area
= convx
* convy
;
2443 highy_int
= convy_int
;
2444 highy_float
= convy_float
;
2446 for (i
= 0; i
< heightout
; i
++) {
2447 /* Clamp here to be sure we don't read beyond input buffer. */
2448 if (highy_int
>= heightin
)
2449 highy_int
= heightin
- 1;
2452 highx_int
= convx_int
;
2453 highx_float
= convx_float
;
2455 for (j
= 0; j
< widthout
; j
++) {
2457 ** Ok, now apply box filter to box that goes from (lowx, lowy)
2458 ** to (highx, highy) on input data into this pixel on output
2461 totals
[0] = totals
[1] = totals
[2] = totals
[3] = 0.0;
2463 /* calculate the value for pixels in the 1st row */
2464 xindex
= lowx_int
*group_size
;
2465 if((highy_int
>lowy_int
) && (highx_int
>lowx_int
)) {
2467 y_percent
= 1-lowy_float
;
2468 temp
= (const char *)datain
+ xindex
+ lowy_int
* ysize
;
2469 percent
= y_percent
* (1-lowx_float
);
2470 for (k
= 0, temp_index
= temp
; k
< components
;
2471 k
++, temp_index
+= element_size
) {
2473 totals
[k
] += __GLU_SWAP_4_BYTES(temp_index
) * percent
;
2475 totals
[k
] += *(const GLuint
*)temp_index
* percent
;
2479 for(l
= lowx_int
+1; l
< highx_int
; l
++) {
2481 for (k
= 0, temp_index
= temp
; k
< components
;
2482 k
++, temp_index
+= element_size
) {
2485 __GLU_SWAP_4_BYTES(temp_index
) * y_percent
;
2487 totals
[k
] += *(const GLuint
*)temp_index
* y_percent
;
2493 percent
= y_percent
* highx_float
;
2494 for (k
= 0, temp_index
= temp
; k
< components
;
2495 k
++, temp_index
+= element_size
) {
2497 totals
[k
] += __GLU_SWAP_4_BYTES(temp_index
) * percent
;
2499 totals
[k
] += *(const GLuint
*)temp_index
* percent
;
2503 /* calculate the value for pixels in the last row */
2504 y_percent
= highy_float
;
2505 percent
= y_percent
* (1-lowx_float
);
2506 temp
= (const char *)datain
+ xindex
+ highy_int
* ysize
;
2507 for (k
= 0, temp_index
= temp
; k
< components
;
2508 k
++, temp_index
+= element_size
) {
2510 totals
[k
] += __GLU_SWAP_4_BYTES(temp_index
) * percent
;
2512 totals
[k
] += *(const GLuint
*)temp_index
* percent
;
2515 for(l
= lowx_int
+1; l
< highx_int
; l
++) {
2517 for (k
= 0, temp_index
= temp
; k
< components
;
2518 k
++, temp_index
+= element_size
) {
2521 __GLU_SWAP_4_BYTES(temp_index
) * y_percent
;
2523 totals
[k
] += *(const GLuint
*)temp_index
* y_percent
;
2528 percent
= y_percent
* highx_float
;
2529 for (k
= 0, temp_index
= temp
; k
< components
;
2530 k
++, temp_index
+= element_size
) {
2532 totals
[k
] += __GLU_SWAP_4_BYTES(temp_index
) * percent
;
2534 totals
[k
] += *(const GLuint
*)temp_index
* percent
;
2538 /* calculate the value for pixels in the 1st and last column */
2539 for(m
= lowy_int
+1; m
< highy_int
; m
++) {
2542 for (k
= 0; k
< components
;
2543 k
++, left
+= element_size
, right
+= element_size
) {
2546 __GLU_SWAP_4_BYTES(left
) * (1-lowx_float
)
2547 + __GLU_SWAP_4_BYTES(right
) * highx_float
;
2549 totals
[k
] += *(const GLuint
*)left
* (1-lowx_float
)
2550 + *(const GLuint
*)right
* highx_float
;
2554 } else if (highy_int
> lowy_int
) {
2555 x_percent
= highx_float
- lowx_float
;
2556 percent
= (1-lowy_float
)*x_percent
;
2557 temp
= (const char *)datain
+ xindex
+ lowy_int
*ysize
;
2558 for (k
= 0, temp_index
= temp
; k
< components
;
2559 k
++, temp_index
+= element_size
) {
2561 totals
[k
] += __GLU_SWAP_4_BYTES(temp_index
) * percent
;
2563 totals
[k
] += *(const GLuint
*)temp_index
* percent
;
2566 for(m
= lowy_int
+1; m
< highy_int
; m
++) {
2568 for (k
= 0, temp_index
= temp
; k
< components
;
2569 k
++, temp_index
+= element_size
) {
2572 __GLU_SWAP_4_BYTES(temp_index
) * x_percent
;
2574 totals
[k
] += *(const GLuint
*)temp_index
* x_percent
;
2578 percent
= x_percent
* highy_float
;
2580 for (k
= 0, temp_index
= temp
; k
< components
;
2581 k
++, temp_index
+= element_size
) {
2583 totals
[k
] += __GLU_SWAP_4_BYTES(temp_index
) * percent
;
2585 totals
[k
] += *(const GLuint
*)temp_index
* percent
;
2588 } else if (highx_int
> lowx_int
) {
2589 y_percent
= highy_float
- lowy_float
;
2590 percent
= (1-lowx_float
)*y_percent
;
2592 temp
= (const char *)datain
+ xindex
+ lowy_int
*ysize
;
2593 for (k
= 0, temp_index
= temp
; k
< components
;
2594 k
++, temp_index
+= element_size
) {
2596 totals
[k
] += __GLU_SWAP_4_BYTES(temp_index
) * percent
;
2598 totals
[k
] += *(const GLuint
*)temp_index
* percent
;
2601 for (l
= lowx_int
+1; l
< highx_int
; l
++) {
2603 for (k
= 0, temp_index
= temp
; k
< components
;
2604 k
++, temp_index
+= element_size
) {
2607 __GLU_SWAP_4_BYTES(temp_index
) * y_percent
;
2609 totals
[k
] += *(const GLuint
*)temp_index
* y_percent
;
2614 percent
= y_percent
* highx_float
;
2615 for (k
= 0, temp_index
= temp
; k
< components
;
2616 k
++, temp_index
+= element_size
) {
2618 totals
[k
] += __GLU_SWAP_4_BYTES(temp_index
) * percent
;
2620 totals
[k
] += *(const GLuint
*)temp_index
* percent
;
2624 percent
= (highy_float
-lowy_float
)*(highx_float
-lowx_float
);
2625 temp
= (const char *)datain
+ xindex
+ lowy_int
* ysize
;
2626 for (k
= 0, temp_index
= temp
; k
< components
;
2627 k
++, temp_index
+= element_size
) {
2629 totals
[k
] += __GLU_SWAP_4_BYTES(temp_index
) * percent
;
2631 totals
[k
] += *(const GLuint
*)temp_index
* percent
;
2636 /* this is for the pixels in the body */
2637 temp0
= (const char *)datain
+ xindex
+ group_size
+
2639 for (m
= lowy_int
+1; m
< highy_int
; m
++) {
2641 for(l
= lowx_int
+1; l
< highx_int
; l
++) {
2642 for (k
= 0, temp_index
= temp
; k
< components
;
2643 k
++, temp_index
+= element_size
) {
2645 totals
[k
] += __GLU_SWAP_4_BYTES(temp_index
);
2647 totals
[k
] += *(const GLuint
*)temp_index
;
2655 outindex
= (j
+ (i
* widthout
)) * components
;
2656 for (k
= 0; k
< components
; k
++) {
2657 /* clamp at UINT_MAX */
2658 float value
= totals
[k
]/area
;
2659 if (value
>= (float) UINT_MAX
) { /* need '=' */
2660 dataout
[outindex
+ k
] = UINT_MAX
;
2662 else dataout
[outindex
+ k
] = value
;
2664 lowx_int
= highx_int
;
2665 lowx_float
= highx_float
;
2666 highx_int
+= convx_int
;
2667 highx_float
+= convx_float
;
2668 if(highx_float
> 1) {
2673 lowy_int
= highy_int
;
2674 lowy_float
= highy_float
;
2675 highy_int
+= convy_int
;
2676 highy_float
+= convy_float
;
2677 if(highy_float
> 1) {
2686 static void scale_internal_int(GLint components
, GLint widthin
,
2687 GLint heightin
, const GLint
*datain
,
2688 GLint widthout
, GLint heightout
,
2689 GLint
*dataout
, GLint element_size
,
2690 GLint ysize
, GLint group_size
,
2696 /* Max components in a format is 4, so... */
2701 const char *temp
, *temp0
;
2702 const char *temp_index
;
2705 int lowx_int
, highx_int
, lowy_int
, highy_int
;
2706 float x_percent
, y_percent
;
2707 float lowx_float
, highx_float
, lowy_float
, highy_float
;
2708 float convy_float
, convx_float
;
2709 int convy_int
, convx_int
;
2711 const char *left
, *right
;
2713 GLuint swapbuf
; /* unsigned buffer */
2715 if (widthin
== widthout
*2 && heightin
== heightout
*2) {
2716 halveImage_int(components
, widthin
, heightin
,
2717 (const GLint
*)datain
, (GLint
*)dataout
,
2718 element_size
, ysize
, group_size
, myswap_bytes
);
2721 convy
= (float) heightin
/heightout
;
2722 convx
= (float) widthin
/widthout
;
2723 convy_int
= floor(convy
);
2724 convy_float
= convy
- convy_int
;
2725 convx_int
= floor(convx
);
2726 convx_float
= convx
- convx_int
;
2728 area
= convx
* convy
;
2732 highy_int
= convy_int
;
2733 highy_float
= convy_float
;
2735 for (i
= 0; i
< heightout
; i
++) {
2736 /* Clamp here to be sure we don't read beyond input buffer. */
2737 if (highy_int
>= heightin
)
2738 highy_int
= heightin
- 1;
2741 highx_int
= convx_int
;
2742 highx_float
= convx_float
;
2744 for (j
= 0; j
< widthout
; j
++) {
2746 ** Ok, now apply box filter to box that goes from (lowx, lowy)
2747 ** to (highx, highy) on input data into this pixel on output
2750 totals
[0] = totals
[1] = totals
[2] = totals
[3] = 0.0;
2752 /* calculate the value for pixels in the 1st row */
2753 xindex
= lowx_int
*group_size
;
2754 if((highy_int
>lowy_int
) && (highx_int
>lowx_int
)) {
2756 y_percent
= 1-lowy_float
;
2757 temp
= (const char *)datain
+ xindex
+ lowy_int
* ysize
;
2758 percent
= y_percent
* (1-lowx_float
);
2759 for (k
= 0, temp_index
= temp
; k
< components
;
2760 k
++, temp_index
+= element_size
) {
2762 swapbuf
= __GLU_SWAP_4_BYTES(temp_index
);
2763 totals
[k
] += *(const GLint
*)&swapbuf
* percent
;
2765 totals
[k
] += *(const GLint
*)temp_index
* percent
;
2769 for(l
= lowx_int
+1; l
< highx_int
; l
++) {
2771 for (k
= 0, temp_index
= temp
; k
< components
;
2772 k
++, temp_index
+= element_size
) {
2774 swapbuf
= __GLU_SWAP_4_BYTES(temp_index
);
2775 totals
[k
] += *(const GLint
*)&swapbuf
* y_percent
;
2777 totals
[k
] += *(const GLint
*)temp_index
* y_percent
;
2783 percent
= y_percent
* highx_float
;
2784 for (k
= 0, temp_index
= temp
; k
< components
;
2785 k
++, temp_index
+= element_size
) {
2787 swapbuf
= __GLU_SWAP_4_BYTES(temp_index
);
2788 totals
[k
] += *(const GLint
*)&swapbuf
* percent
;
2790 totals
[k
] += *(const GLint
*)temp_index
* percent
;
2794 /* calculate the value for pixels in the last row */
2795 y_percent
= highy_float
;
2796 percent
= y_percent
* (1-lowx_float
);
2797 temp
= (const char *)datain
+ xindex
+ highy_int
* ysize
;
2798 for (k
= 0, temp_index
= temp
; k
< components
;
2799 k
++, temp_index
+= element_size
) {
2801 swapbuf
= __GLU_SWAP_4_BYTES(temp_index
);
2802 totals
[k
] += *(const GLint
*)&swapbuf
* percent
;
2804 totals
[k
] += *(const GLint
*)temp_index
* percent
;
2807 for(l
= lowx_int
+1; l
< highx_int
; l
++) {
2809 for (k
= 0, temp_index
= temp
; k
< components
;
2810 k
++, temp_index
+= element_size
) {
2812 swapbuf
= __GLU_SWAP_4_BYTES(temp_index
);
2813 totals
[k
] += *(const GLint
*)&swapbuf
* y_percent
;
2815 totals
[k
] += *(const GLint
*)temp_index
* y_percent
;
2820 percent
= y_percent
* highx_float
;
2821 for (k
= 0, temp_index
= temp
; k
< components
;
2822 k
++, temp_index
+= element_size
) {
2824 swapbuf
= __GLU_SWAP_4_BYTES(temp_index
);
2825 totals
[k
] += *(const GLint
*)&swapbuf
* percent
;
2827 totals
[k
] += *(const GLint
*)temp_index
* percent
;
2831 /* calculate the value for pixels in the 1st and last column */
2832 for(m
= lowy_int
+1; m
< highy_int
; m
++) {
2835 for (k
= 0; k
< components
;
2836 k
++, left
+= element_size
, right
+= element_size
) {
2838 swapbuf
= __GLU_SWAP_4_BYTES(left
);
2839 totals
[k
] += *(const GLint
*)&swapbuf
* (1-lowx_float
);
2840 swapbuf
= __GLU_SWAP_4_BYTES(right
);
2841 totals
[k
] += *(const GLint
*)&swapbuf
* highx_float
;
2843 totals
[k
] += *(const GLint
*)left
* (1-lowx_float
)
2844 + *(const GLint
*)right
* highx_float
;
2848 } else if (highy_int
> lowy_int
) {
2849 x_percent
= highx_float
- lowx_float
;
2850 percent
= (1-lowy_float
)*x_percent
;
2851 temp
= (const char *)datain
+ xindex
+ lowy_int
*ysize
;
2852 for (k
= 0, temp_index
= temp
; k
< components
;
2853 k
++, temp_index
+= element_size
) {
2855 swapbuf
= __GLU_SWAP_4_BYTES(temp_index
);
2856 totals
[k
] += *(const GLint
*)&swapbuf
* percent
;
2858 totals
[k
] += *(const GLint
*)temp_index
* percent
;
2861 for(m
= lowy_int
+1; m
< highy_int
; m
++) {
2863 for (k
= 0, temp_index
= temp
; k
< components
;
2864 k
++, temp_index
+= element_size
) {
2866 swapbuf
= __GLU_SWAP_4_BYTES(temp_index
);
2867 totals
[k
] += *(const GLint
*)&swapbuf
* x_percent
;
2869 totals
[k
] += *(const GLint
*)temp_index
* x_percent
;
2873 percent
= x_percent
* highy_float
;
2875 for (k
= 0, temp_index
= temp
; k
< components
;
2876 k
++, temp_index
+= element_size
) {
2878 swapbuf
= __GLU_SWAP_4_BYTES(temp_index
);
2879 totals
[k
] += *(const GLint
*)&swapbuf
* percent
;
2881 totals
[k
] += *(const GLint
*)temp_index
* percent
;
2884 } else if (highx_int
> lowx_int
) {
2885 y_percent
= highy_float
- lowy_float
;
2886 percent
= (1-lowx_float
)*y_percent
;
2888 temp
= (const char *)datain
+ xindex
+ lowy_int
*ysize
;
2889 for (k
= 0, temp_index
= temp
; k
< components
;
2890 k
++, temp_index
+= element_size
) {
2892 swapbuf
= __GLU_SWAP_4_BYTES(temp_index
);
2893 totals
[k
] += *(const GLint
*)&swapbuf
* percent
;
2895 totals
[k
] += *(const GLint
*)temp_index
* percent
;
2898 for (l
= lowx_int
+1; l
< highx_int
; l
++) {
2900 for (k
= 0, temp_index
= temp
; k
< components
;
2901 k
++, temp_index
+= element_size
) {
2903 swapbuf
= __GLU_SWAP_4_BYTES(temp_index
);
2904 totals
[k
] += *(const GLint
*)&swapbuf
* y_percent
;
2906 totals
[k
] += *(const GLint
*)temp_index
* y_percent
;
2911 percent
= y_percent
* highx_float
;
2912 for (k
= 0, temp_index
= temp
; k
< components
;
2913 k
++, temp_index
+= element_size
) {
2915 swapbuf
= __GLU_SWAP_4_BYTES(temp_index
);
2916 totals
[k
] += *(const GLint
*)&swapbuf
* percent
;
2918 totals
[k
] += *(const GLint
*)temp_index
* percent
;
2922 percent
= (highy_float
-lowy_float
)*(highx_float
-lowx_float
);
2923 temp
= (const char *)datain
+ xindex
+ lowy_int
* ysize
;
2924 for (k
= 0, temp_index
= temp
; k
< components
;
2925 k
++, temp_index
+= element_size
) {
2927 swapbuf
= __GLU_SWAP_4_BYTES(temp_index
);
2928 totals
[k
] += *(const GLint
*)&swapbuf
* percent
;
2930 totals
[k
] += *(const GLint
*)temp_index
* percent
;
2935 /* this is for the pixels in the body */
2936 temp0
= (const char *)datain
+ xindex
+ group_size
+
2938 for (m
= lowy_int
+1; m
< highy_int
; m
++) {
2940 for(l
= lowx_int
+1; l
< highx_int
; l
++) {
2941 for (k
= 0, temp_index
= temp
; k
< components
;
2942 k
++, temp_index
+= element_size
) {
2944 swapbuf
= __GLU_SWAP_4_BYTES(temp_index
);
2945 totals
[k
] += *(const GLint
*)&swapbuf
;
2947 totals
[k
] += *(const GLint
*)temp_index
;
2955 outindex
= (j
+ (i
* widthout
)) * components
;
2956 for (k
= 0; k
< components
; k
++) {
2957 dataout
[outindex
+ k
] = totals
[k
]/area
;
2958 /*printf("totals[%d] = %f\n", k, totals[k]);*/
2960 lowx_int
= highx_int
;
2961 lowx_float
= highx_float
;
2962 highx_int
+= convx_int
;
2963 highx_float
+= convx_float
;
2964 if(highx_float
> 1) {
2969 lowy_int
= highy_int
;
2970 lowy_float
= highy_float
;
2971 highy_int
+= convy_int
;
2972 highy_float
+= convy_float
;
2973 if(highy_float
> 1) {
2982 static void scale_internal_float(GLint components
, GLint widthin
,
2983 GLint heightin
, const GLfloat
*datain
,
2984 GLint widthout
, GLint heightout
,
2985 GLfloat
*dataout
, GLint element_size
,
2986 GLint ysize
, GLint group_size
,
2992 /* Max components in a format is 4, so... */
2997 const char *temp
, *temp0
;
2998 const char *temp_index
;
3001 int lowx_int
, highx_int
, lowy_int
, highy_int
;
3002 float x_percent
, y_percent
;
3003 float lowx_float
, highx_float
, lowy_float
, highy_float
;
3004 float convy_float
, convx_float
;
3005 int convy_int
, convx_int
;
3007 const char *left
, *right
;
3009 union { GLuint b
; GLfloat f
; } swapbuf
;
3011 if (widthin
== widthout
*2 && heightin
== heightout
*2) {
3012 halveImage_float(components
, widthin
, heightin
,
3013 (const GLfloat
*)datain
, (GLfloat
*)dataout
,
3014 element_size
, ysize
, group_size
, myswap_bytes
);
3017 convy
= (float) heightin
/heightout
;
3018 convx
= (float) widthin
/widthout
;
3019 convy_int
= floor(convy
);
3020 convy_float
= convy
- convy_int
;
3021 convx_int
= floor(convx
);
3022 convx_float
= convx
- convx_int
;
3024 area
= convx
* convy
;
3028 highy_int
= convy_int
;
3029 highy_float
= convy_float
;
3031 for (i
= 0; i
< heightout
; i
++) {
3032 /* Clamp here to be sure we don't read beyond input buffer. */
3033 if (highy_int
>= heightin
)
3034 highy_int
= heightin
- 1;
3037 highx_int
= convx_int
;
3038 highx_float
= convx_float
;
3040 for (j
= 0; j
< widthout
; j
++) {
3042 ** Ok, now apply box filter to box that goes from (lowx, lowy)
3043 ** to (highx, highy) on input data into this pixel on output
3046 totals
[0] = totals
[1] = totals
[2] = totals
[3] = 0.0;
3048 /* calculate the value for pixels in the 1st row */
3049 xindex
= lowx_int
*group_size
;
3050 if((highy_int
>lowy_int
) && (highx_int
>lowx_int
)) {
3052 y_percent
= 1-lowy_float
;
3053 temp
= (const char *)datain
+ xindex
+ lowy_int
* ysize
;
3054 percent
= y_percent
* (1-lowx_float
);
3055 for (k
= 0, temp_index
= temp
; k
< components
;
3056 k
++, temp_index
+= element_size
) {
3058 swapbuf
.b
= __GLU_SWAP_4_BYTES(temp_index
);
3059 totals
[k
] += swapbuf
.f
* percent
;
3061 totals
[k
] += *(const GLfloat
*)temp_index
* percent
;
3065 for(l
= lowx_int
+1; l
< highx_int
; l
++) {
3067 for (k
= 0, temp_index
= temp
; k
< components
;
3068 k
++, temp_index
+= element_size
) {
3070 swapbuf
.b
= __GLU_SWAP_4_BYTES(temp_index
);
3071 totals
[k
] += swapbuf
.f
* y_percent
;
3073 totals
[k
] += *(const GLfloat
*)temp_index
* y_percent
;
3079 percent
= y_percent
* highx_float
;
3080 for (k
= 0, temp_index
= temp
; k
< components
;
3081 k
++, temp_index
+= element_size
) {
3083 swapbuf
.b
= __GLU_SWAP_4_BYTES(temp_index
);
3084 totals
[k
] += swapbuf
.f
* percent
;
3086 totals
[k
] += *(const GLfloat
*)temp_index
* percent
;
3090 /* calculate the value for pixels in the last row */
3091 y_percent
= highy_float
;
3092 percent
= y_percent
* (1-lowx_float
);
3093 temp
= (const char *)datain
+ xindex
+ highy_int
* ysize
;
3094 for (k
= 0, temp_index
= temp
; k
< components
;
3095 k
++, temp_index
+= element_size
) {
3097 swapbuf
.b
= __GLU_SWAP_4_BYTES(temp_index
);
3098 totals
[k
] += swapbuf
.f
* percent
;
3100 totals
[k
] += *(const GLfloat
*)temp_index
* percent
;
3103 for(l
= lowx_int
+1; l
< highx_int
; l
++) {
3105 for (k
= 0, temp_index
= temp
; k
< components
;
3106 k
++, temp_index
+= element_size
) {
3108 swapbuf
.b
= __GLU_SWAP_4_BYTES(temp_index
);
3109 totals
[k
] += swapbuf
.f
* y_percent
;
3111 totals
[k
] += *(const GLfloat
*)temp_index
* y_percent
;
3116 percent
= y_percent
* highx_float
;
3117 for (k
= 0, temp_index
= temp
; k
< components
;
3118 k
++, temp_index
+= element_size
) {
3120 swapbuf
.b
= __GLU_SWAP_4_BYTES(temp_index
);
3121 totals
[k
] += swapbuf
.f
* percent
;
3123 totals
[k
] += *(const GLfloat
*)temp_index
* percent
;
3127 /* calculate the value for pixels in the 1st and last column */
3128 for(m
= lowy_int
+1; m
< highy_int
; m
++) {
3131 for (k
= 0; k
< components
;
3132 k
++, left
+= element_size
, right
+= element_size
) {
3134 swapbuf
.b
= __GLU_SWAP_4_BYTES(left
);
3135 totals
[k
] += swapbuf
.f
* (1-lowx_float
);
3136 swapbuf
.b
= __GLU_SWAP_4_BYTES(right
);
3137 totals
[k
] += swapbuf
.f
* highx_float
;
3139 totals
[k
] += *(const GLfloat
*)left
* (1-lowx_float
)
3140 + *(const GLfloat
*)right
* highx_float
;
3144 } else if (highy_int
> lowy_int
) {
3145 x_percent
= highx_float
- lowx_float
;
3146 percent
= (1-lowy_float
)*x_percent
;
3147 temp
= (const char *)datain
+ xindex
+ lowy_int
*ysize
;
3148 for (k
= 0, temp_index
= temp
; k
< components
;
3149 k
++, temp_index
+= element_size
) {
3151 swapbuf
.b
= __GLU_SWAP_4_BYTES(temp_index
);
3152 totals
[k
] += swapbuf
.f
* percent
;
3154 totals
[k
] += *(const GLfloat
*)temp_index
* percent
;
3157 for(m
= lowy_int
+1; m
< highy_int
; m
++) {
3159 for (k
= 0, temp_index
= temp
; k
< components
;
3160 k
++, temp_index
+= element_size
) {
3162 swapbuf
.b
= __GLU_SWAP_4_BYTES(temp_index
);
3163 totals
[k
] += swapbuf
.f
* x_percent
;
3165 totals
[k
] += *(const GLfloat
*)temp_index
* x_percent
;
3169 percent
= x_percent
* highy_float
;
3171 for (k
= 0, temp_index
= temp
; k
< components
;
3172 k
++, temp_index
+= element_size
) {
3174 swapbuf
.b
= __GLU_SWAP_4_BYTES(temp_index
);
3175 totals
[k
] += swapbuf
.f
* percent
;
3177 totals
[k
] += *(const GLfloat
*)temp_index
* percent
;
3180 } else if (highx_int
> lowx_int
) {
3181 y_percent
= highy_float
- lowy_float
;
3182 percent
= (1-lowx_float
)*y_percent
;
3184 temp
= (const char *)datain
+ xindex
+ lowy_int
*ysize
;
3185 for (k
= 0, temp_index
= temp
; k
< components
;
3186 k
++, temp_index
+= element_size
) {
3188 swapbuf
.b
= __GLU_SWAP_4_BYTES(temp_index
);
3189 totals
[k
] += swapbuf
.f
* percent
;
3191 totals
[k
] += *(const GLfloat
*)temp_index
* percent
;
3194 for (l
= lowx_int
+1; l
< highx_int
; l
++) {
3196 for (k
= 0, temp_index
= temp
; k
< components
;
3197 k
++, temp_index
+= element_size
) {
3199 swapbuf
.b
= __GLU_SWAP_4_BYTES(temp_index
);
3200 totals
[k
] += swapbuf
.f
* y_percent
;
3202 totals
[k
] += *(const GLfloat
*)temp_index
* y_percent
;
3207 percent
= y_percent
* highx_float
;
3208 for (k
= 0, temp_index
= temp
; k
< components
;
3209 k
++, temp_index
+= element_size
) {
3211 swapbuf
.b
= __GLU_SWAP_4_BYTES(temp_index
);
3212 totals
[k
] += swapbuf
.f
* percent
;
3214 totals
[k
] += *(const GLfloat
*)temp_index
* percent
;
3218 percent
= (highy_float
-lowy_float
)*(highx_float
-lowx_float
);
3219 temp
= (const char *)datain
+ xindex
+ lowy_int
* ysize
;
3220 for (k
= 0, temp_index
= temp
; k
< components
;
3221 k
++, temp_index
+= element_size
) {
3223 swapbuf
.b
= __GLU_SWAP_4_BYTES(temp_index
);
3224 totals
[k
] += swapbuf
.f
* percent
;
3226 totals
[k
] += *(const GLfloat
*)temp_index
* percent
;
3231 /* this is for the pixels in the body */
3232 temp0
= (const char *)datain
+ xindex
+ group_size
+
3234 for (m
= lowy_int
+1; m
< highy_int
; m
++) {
3236 for(l
= lowx_int
+1; l
< highx_int
; l
++) {
3237 for (k
= 0, temp_index
= temp
; k
< components
;
3238 k
++, temp_index
+= element_size
) {
3240 swapbuf
.b
= __GLU_SWAP_4_BYTES(temp_index
);
3241 totals
[k
] += swapbuf
.f
;
3243 totals
[k
] += *(const GLfloat
*)temp_index
;
3251 outindex
= (j
+ (i
* widthout
)) * components
;
3252 for (k
= 0; k
< components
; k
++) {
3253 dataout
[outindex
+ k
] = totals
[k
]/area
;
3254 /*printf("totals[%d] = %f\n", k, totals[k]);*/
3256 lowx_int
= highx_int
;
3257 lowx_float
= highx_float
;
3258 highx_int
+= convx_int
;
3259 highx_float
+= convx_float
;
3260 if(highx_float
> 1) {
3265 lowy_int
= highy_int
;
3266 lowy_float
= highy_float
;
3267 highy_int
+= convy_int
;
3268 highy_float
+= convy_float
;
3269 if(highy_float
> 1) {
3276 static int checkMipmapArgs(GLenum internalFormat
, GLenum format
, GLenum type
)
3278 if (!legalFormat(format
) || !legalType(type
)) {
3279 return GLU_INVALID_ENUM
;
3281 if (format
== GL_STENCIL_INDEX
) {
3282 return GLU_INVALID_ENUM
;
3285 if (!isLegalFormatForPackedPixelType(format
, type
)) {
3286 return GLU_INVALID_OPERATION
;
3290 } /* checkMipmapArgs() */
3292 static GLboolean
legalFormat(GLenum format
)
3295 case GL_COLOR_INDEX
:
3296 case GL_STENCIL_INDEX
:
3297 case GL_DEPTH_COMPONENT
:
3305 case GL_LUMINANCE_ALPHA
:
3315 static GLboolean
legalType(GLenum type
)
3320 case GL_UNSIGNED_BYTE
:
3322 case GL_UNSIGNED_SHORT
:
3324 case GL_UNSIGNED_INT
:
3326 case GL_UNSIGNED_BYTE_3_3_2
:
3327 case GL_UNSIGNED_BYTE_2_3_3_REV
:
3328 case GL_UNSIGNED_SHORT_5_6_5
:
3329 case GL_UNSIGNED_SHORT_5_6_5_REV
:
3330 case GL_UNSIGNED_SHORT_4_4_4_4
:
3331 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
3332 case GL_UNSIGNED_SHORT_5_5_5_1
:
3333 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
3334 case GL_UNSIGNED_INT_8_8_8_8
:
3335 case GL_UNSIGNED_INT_8_8_8_8_REV
:
3336 case GL_UNSIGNED_INT_10_10_10_2
:
3337 case GL_UNSIGNED_INT_2_10_10_10_REV
:
3345 static GLboolean
isTypePackedPixel(GLenum type
)
3347 assert(legalType(type
));
3349 if (type
== GL_UNSIGNED_BYTE_3_3_2
||
3350 type
== GL_UNSIGNED_BYTE_2_3_3_REV
||
3351 type
== GL_UNSIGNED_SHORT_5_6_5
||
3352 type
== GL_UNSIGNED_SHORT_5_6_5_REV
||
3353 type
== GL_UNSIGNED_SHORT_4_4_4_4
||
3354 type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
||
3355 type
== GL_UNSIGNED_SHORT_5_5_5_1
||
3356 type
== GL_UNSIGNED_SHORT_1_5_5_5_REV
||
3357 type
== GL_UNSIGNED_INT_8_8_8_8
||
3358 type
== GL_UNSIGNED_INT_8_8_8_8_REV
||
3359 type
== GL_UNSIGNED_INT_10_10_10_2
||
3360 type
== GL_UNSIGNED_INT_2_10_10_10_REV
) {
3364 } /* isTypePackedPixel() */
3366 /* Determines if the packed pixel type is compatible with the format */
3367 static GLboolean
isLegalFormatForPackedPixelType(GLenum format
, GLenum type
)
3369 /* if not a packed pixel type then return true */
3370 if (!isTypePackedPixel(type
)) {
3374 /* 3_3_2/2_3_3_REV & 5_6_5/5_6_5_REV are only compatible with RGB */
3375 if ((type
== GL_UNSIGNED_BYTE_3_3_2
|| type
== GL_UNSIGNED_BYTE_2_3_3_REV
||
3376 type
== GL_UNSIGNED_SHORT_5_6_5
|| type
== GL_UNSIGNED_SHORT_5_6_5_REV
)
3377 && format
!= GL_RGB
)
3380 /* 4_4_4_4/4_4_4_4_REV & 5_5_5_1/1_5_5_5_REV & 8_8_8_8/8_8_8_8_REV &
3381 * 10_10_10_2/2_10_10_10_REV are only compatible with RGBA, BGRA & ABGR_EXT.
3383 if ((type
== GL_UNSIGNED_SHORT_4_4_4_4
||
3384 type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
||
3385 type
== GL_UNSIGNED_SHORT_5_5_5_1
||
3386 type
== GL_UNSIGNED_SHORT_1_5_5_5_REV
||
3387 type
== GL_UNSIGNED_INT_8_8_8_8
||
3388 type
== GL_UNSIGNED_INT_8_8_8_8_REV
||
3389 type
== GL_UNSIGNED_INT_10_10_10_2
||
3390 type
== GL_UNSIGNED_INT_2_10_10_10_REV
) &&
3391 (format
!= GL_RGBA
&&
3392 format
!= GL_BGRA
)) {
3397 } /* isLegalFormatForPackedPixelType() */
3399 static GLboolean
isLegalLevels(GLint userLevel
,GLint baseLevel
,GLint maxLevel
,
3402 if (baseLevel
< 0 || baseLevel
< userLevel
|| maxLevel
< baseLevel
||
3403 totalLevels
< maxLevel
)
3405 else return GL_TRUE
;
3406 } /* isLegalLevels() */
3408 /* Given user requested texture size, determine if it fits. If it
3409 * doesn't then halve both sides and make the determination again
3410 * until it does fit (for IR only).
3411 * Note that proxy textures are not implemented in RE* even though
3412 * they advertise the texture extension.
3413 * Note that proxy textures are implemented but not according to spec in
3416 static void closestFit(GLenum target
, GLint width
, GLint height
,
3417 GLint internalFormat
, GLenum format
, GLenum type
,
3418 GLint
*newWidth
, GLint
*newHeight
)
3420 /* Use proxy textures if OpenGL version is >= 1.1 */
3421 if ( (strtod((const char *)glGetString(GL_VERSION
),NULL
) >= 1.1)
3423 GLint widthPowerOf2
= nearestPower(width
);
3424 GLint heightPowerOf2
= nearestPower(height
);
3428 /* compute level 1 width & height, clamping each at 1 */
3429 GLint widthAtLevelOne
= (widthPowerOf2
> 1) ?
3430 widthPowerOf2
>> 1 :
3432 GLint heightAtLevelOne
= (heightPowerOf2
> 1) ?
3433 heightPowerOf2
>> 1 :
3436 assert(widthAtLevelOne
> 0); assert(heightAtLevelOne
> 0);
3438 /* does width x height at level 1 & all their mipmaps fit? */
3439 if (target
== GL_TEXTURE_2D
|| target
== GL_PROXY_TEXTURE_2D
) {
3440 proxyTarget
= GL_PROXY_TEXTURE_2D
;
3441 glTexImage2D(proxyTarget
, 1, /* must be non-zero */
3443 widthAtLevelOne
,heightAtLevelOne
,0,format
,type
,NULL
);
3445 #if defined(GL_ARB_texture_cube_map)
3446 if ((target
== GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
) ||
3447 (target
== GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
) ||
3448 (target
== GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
) ||
3449 (target
== GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
) ||
3450 (target
== GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
) ||
3451 (target
== GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
)) {
3452 proxyTarget
= GL_PROXY_TEXTURE_CUBE_MAP_ARB
;
3453 glTexImage2D(proxyTarget
, 1, /* must be non-zero */
3455 widthAtLevelOne
,heightAtLevelOne
,0,format
,type
,NULL
);
3457 #endif /* GL_ARB_texture_cube_map */
3459 assert(target
== GL_TEXTURE_1D
|| target
== GL_PROXY_TEXTURE_1D
);
3460 proxyTarget
= GL_PROXY_TEXTURE_1D
;
3461 glTexImage1D(proxyTarget
, 1, /* must be non-zero */
3462 internalFormat
,widthAtLevelOne
,0,format
,type
,NULL
);
3464 glGetTexLevelParameteriv(proxyTarget
, 1,GL_TEXTURE_WIDTH
,&proxyWidth
);
3465 /* does it fit??? */
3466 if (proxyWidth
== 0) { /* nope, so try again with these sizes */
3467 if (widthPowerOf2
== 1 && heightPowerOf2
== 1) {
3468 /* An 1x1 texture couldn't fit for some reason, so
3469 * break out. This should never happen. But things
3470 * happen. The disadvantage with this if-statement is
3471 * that we will never be aware of when this happens
3472 * since it will silently branch out.
3474 goto noProxyTextures
;
3476 widthPowerOf2
= widthAtLevelOne
;
3477 heightPowerOf2
= heightAtLevelOne
;
3479 /* else it does fit */
3480 } while (proxyWidth
== 0);
3481 /* loop must terminate! */
3483 /* return the width & height at level 0 that fits */
3484 *newWidth
= widthPowerOf2
;
3485 *newHeight
= heightPowerOf2
;
3486 /*printf("Proxy Textures\n");*/
3487 } /* if gluCheckExtension() */
3488 else { /* no texture extension, so do this instead */
3493 glGetIntegerv(GL_MAX_TEXTURE_SIZE
, &maxsize
);
3494 /* clamp user's texture sizes to maximum sizes, if necessary */
3495 *newWidth
= nearestPower(width
);
3496 if (*newWidth
> maxsize
) *newWidth
= maxsize
;
3497 *newHeight
= nearestPower(height
);
3498 if (*newHeight
> maxsize
) *newHeight
= maxsize
;
3499 /*printf("NO proxy textures\n");*/
3501 } /* closestFit() */
3504 gluScaleImage(GLenum format
, GLsizei widthin
, GLsizei heightin
,
3505 GLenum typein
, const void *datain
,
3506 GLsizei widthout
, GLsizei heightout
, GLenum typeout
,
3510 GLushort
*beforeImage
;
3511 GLushort
*afterImage
;
3512 PixelStorageModes psm
;
3514 if (widthin
== 0 || heightin
== 0 || widthout
== 0 || heightout
== 0) {
3517 if (widthin
< 0 || heightin
< 0 || widthout
< 0 || heightout
< 0) {
3518 return GLU_INVALID_VALUE
;
3520 if (!legalFormat(format
) || !legalType(typein
) || !legalType(typeout
)) {
3521 return GLU_INVALID_ENUM
;
3523 if (!isLegalFormatForPackedPixelType(format
, typein
)) {
3524 return GLU_INVALID_OPERATION
;
3526 if (!isLegalFormatForPackedPixelType(format
, typeout
)) {
3527 return GLU_INVALID_OPERATION
;
3530 malloc(image_size(widthin
, heightin
, format
, GL_UNSIGNED_SHORT
));
3532 malloc(image_size(widthout
, heightout
, format
, GL_UNSIGNED_SHORT
));
3533 if (beforeImage
== NULL
|| afterImage
== NULL
) {
3534 return GLU_OUT_OF_MEMORY
;
3537 retrieveStoreModes(&psm
);
3538 fill_image(&psm
,widthin
, heightin
, format
, typein
, is_index(format
),
3539 datain
, beforeImage
);
3540 components
= elements_per_group(format
, 0);
3541 scale_internal(components
, widthin
, heightin
, beforeImage
,
3542 widthout
, heightout
, afterImage
);
3543 empty_image(&psm
,widthout
, heightout
, format
, typeout
,
3544 is_index(format
), afterImage
, dataout
);
3545 free((GLbyte
*) beforeImage
);
3546 free((GLbyte
*) afterImage
);
3551 int gluBuild1DMipmapLevelsCore(GLenum target
, GLint internalFormat
,
3553 GLsizei widthPowerOf2
,
3554 GLenum format
, GLenum type
,
3555 GLint userLevel
, GLint baseLevel
,GLint maxLevel
,
3559 GLint level
, levels
;
3561 GLint newImage_width
;
3562 GLushort
*otherImage
;
3563 GLushort
*imageTemp
;
3566 PixelStorageModes psm
;
3568 assert(checkMipmapArgs(internalFormat
,format
,type
) == 0);
3573 newwidth
= widthPowerOf2
;
3574 levels
= computeLog(newwidth
);
3578 retrieveStoreModes(&psm
);
3579 newImage
= (GLushort
*)
3580 malloc(image_size(width
, 1, format
, GL_UNSIGNED_SHORT
));
3581 newImage_width
= width
;
3582 if (newImage
== NULL
) {
3583 return GLU_OUT_OF_MEMORY
;
3585 fill_image(&psm
,width
, 1, format
, type
, is_index(format
),
3587 cmpts
= elements_per_group(format
,type
);
3588 glPixelStorei(GL_UNPACK_ALIGNMENT
, 2);
3589 glPixelStorei(GL_UNPACK_SKIP_ROWS
, 0);
3590 glPixelStorei(GL_UNPACK_SKIP_PIXELS
, 0);
3591 glPixelStorei(GL_UNPACK_ROW_LENGTH
, 0);
3593 ** If swap_bytes was set, swapping occurred in fill_image.
3595 glPixelStorei(GL_UNPACK_SWAP_BYTES
, GL_FALSE
);
3597 for (level
= userLevel
; level
<= levels
; level
++) {
3598 if (newImage_width
== newwidth
) {
3599 /* Use newImage for this level */
3600 if (baseLevel
<= level
&& level
<= maxLevel
) {
3601 glTexImage1D(target
, level
, internalFormat
, newImage_width
,
3602 0, format
, GL_UNSIGNED_SHORT
, (void *) newImage
);
3605 if (otherImage
== NULL
) {
3606 memreq
= image_size(newwidth
, 1, format
, GL_UNSIGNED_SHORT
);
3607 otherImage
= (GLushort
*) malloc(memreq
);
3608 if (otherImage
== NULL
) {
3609 glPixelStorei(GL_UNPACK_ALIGNMENT
, psm
.unpack_alignment
);
3610 glPixelStorei(GL_UNPACK_SKIP_ROWS
, psm
.unpack_skip_rows
);
3611 glPixelStorei(GL_UNPACK_SKIP_PIXELS
,psm
.unpack_skip_pixels
);
3612 glPixelStorei(GL_UNPACK_ROW_LENGTH
, psm
.unpack_row_length
);
3613 glPixelStorei(GL_UNPACK_SWAP_BYTES
, psm
.unpack_swap_bytes
);
3614 return GLU_OUT_OF_MEMORY
;
3617 scale_internal(cmpts
, newImage_width
, 1, newImage
,
3618 newwidth
, 1, otherImage
);
3619 /* Swap newImage and otherImage */
3620 imageTemp
= otherImage
;
3621 otherImage
= newImage
;
3622 newImage
= imageTemp
;
3624 newImage_width
= newwidth
;
3625 if (baseLevel
<= level
&& level
<= maxLevel
) {
3626 glTexImage1D(target
, level
, internalFormat
, newImage_width
,
3627 0, format
, GL_UNSIGNED_SHORT
, (void *) newImage
);
3630 if (newwidth
> 1) newwidth
/= 2;
3632 glPixelStorei(GL_UNPACK_ALIGNMENT
, psm
.unpack_alignment
);
3633 glPixelStorei(GL_UNPACK_SKIP_ROWS
, psm
.unpack_skip_rows
);
3634 glPixelStorei(GL_UNPACK_SKIP_PIXELS
, psm
.unpack_skip_pixels
);
3635 glPixelStorei(GL_UNPACK_ROW_LENGTH
, psm
.unpack_row_length
);
3636 glPixelStorei(GL_UNPACK_SWAP_BYTES
, psm
.unpack_swap_bytes
);
3638 free((GLbyte
*) newImage
);
3640 free((GLbyte
*) otherImage
);
3646 gluBuild1DMipmapLevels(GLenum target
, GLint internalFormat
,
3648 GLenum format
, GLenum type
,
3649 GLint userLevel
, GLint baseLevel
, GLint maxLevel
,
3654 int rc
= checkMipmapArgs(internalFormat
,format
,type
);
3655 if (rc
!= 0) return rc
;
3658 return GLU_INVALID_VALUE
;
3661 levels
= computeLog(width
);
3664 if (!isLegalLevels(userLevel
,baseLevel
,maxLevel
,levels
))
3665 return GLU_INVALID_VALUE
;
3667 return gluBuild1DMipmapLevelsCore(target
, internalFormat
,
3670 userLevel
, baseLevel
, maxLevel
,
3672 } /* gluBuild1DMipmapLevels() */
3675 gluBuild1DMipmaps(GLenum target
, GLint internalFormat
, GLsizei width
,
3676 GLenum format
, GLenum type
,
3679 GLint widthPowerOf2
;
3683 int rc
= checkMipmapArgs(internalFormat
,format
,type
);
3684 if (rc
!= 0) return rc
;
3687 return GLU_INVALID_VALUE
;
3690 closestFit(target
,width
,1,internalFormat
,format
,type
,&widthPowerOf2
,&dummy
);
3691 levels
= computeLog(widthPowerOf2
);
3693 return gluBuild1DMipmapLevelsCore(target
,internalFormat
,
3696 format
,type
,0,0,levels
,data
);
3699 static int bitmapBuild2DMipmaps(GLenum target
, GLint internalFormat
,
3700 GLint width
, GLint height
, GLenum format
,
3701 GLenum type
, const void *data
)
3703 GLint newwidth
, newheight
;
3704 GLint level
, levels
;
3706 GLint newImage_width
;
3707 GLint newImage_height
;
3708 GLushort
*otherImage
;
3709 GLushort
*imageTemp
;
3712 PixelStorageModes psm
;
3714 retrieveStoreModes(&psm
);
3717 glGetIntegerv(GL_MAX_TEXTURE_SIZE
, &maxsize
);
3718 newwidth
= nearestPower(width
);
3719 if (newwidth
> maxsize
) newwidth
= maxsize
;
3720 newheight
= nearestPower(height
);
3721 if (newheight
> maxsize
) newheight
= maxsize
;
3723 closestFit(target
,width
,height
,internalFormat
,format
,type
,
3724 &newwidth
,&newheight
);
3726 levels
= computeLog(newwidth
);
3727 level
= computeLog(newheight
);
3728 if (level
> levels
) levels
=level
;
3731 newImage
= (GLushort
*)
3732 malloc(image_size(width
, height
, format
, GL_UNSIGNED_SHORT
));
3733 newImage_width
= width
;
3734 newImage_height
= height
;
3735 if (newImage
== NULL
) {
3736 return GLU_OUT_OF_MEMORY
;
3739 fill_image(&psm
,width
, height
, format
, type
, is_index(format
),
3742 cmpts
= elements_per_group(format
,type
);
3743 glPixelStorei(GL_UNPACK_ALIGNMENT
, 2);
3744 glPixelStorei(GL_UNPACK_SKIP_ROWS
, 0);
3745 glPixelStorei(GL_UNPACK_SKIP_PIXELS
, 0);
3746 glPixelStorei(GL_UNPACK_ROW_LENGTH
, 0);
3748 ** If swap_bytes was set, swapping occurred in fill_image.
3750 glPixelStorei(GL_UNPACK_SWAP_BYTES
, GL_FALSE
);
3752 for (level
= 0; level
<= levels
; level
++) {
3753 if (newImage_width
== newwidth
&& newImage_height
== newheight
) { /* Use newImage for this level */
3754 glTexImage2D(target
, level
, internalFormat
, newImage_width
,
3755 newImage_height
, 0, format
, GL_UNSIGNED_SHORT
,
3758 if (otherImage
== NULL
) {
3760 image_size(newwidth
, newheight
, format
, GL_UNSIGNED_SHORT
);
3761 otherImage
= (GLushort
*) malloc(memreq
);
3762 if (otherImage
== NULL
) {
3763 glPixelStorei(GL_UNPACK_ALIGNMENT
, psm
.unpack_alignment
);
3764 glPixelStorei(GL_UNPACK_SKIP_ROWS
, psm
.unpack_skip_rows
);
3765 glPixelStorei(GL_UNPACK_SKIP_PIXELS
,psm
.unpack_skip_pixels
);
3766 glPixelStorei(GL_UNPACK_ROW_LENGTH
, psm
.unpack_row_length
);
3767 glPixelStorei(GL_UNPACK_SWAP_BYTES
, psm
.unpack_swap_bytes
);
3768 return GLU_OUT_OF_MEMORY
;
3771 scale_internal(cmpts
, newImage_width
, newImage_height
, newImage
,
3772 newwidth
, newheight
, otherImage
);
3773 /* Swap newImage and otherImage */
3774 imageTemp
= otherImage
;
3775 otherImage
= newImage
;
3776 newImage
= imageTemp
;
3778 newImage_width
= newwidth
;
3779 newImage_height
= newheight
;
3780 glTexImage2D(target
, level
, internalFormat
, newImage_width
,
3781 newImage_height
, 0, format
, GL_UNSIGNED_SHORT
,
3784 if (newwidth
> 1) newwidth
/= 2;
3785 if (newheight
> 1) newheight
/= 2;
3787 glPixelStorei(GL_UNPACK_ALIGNMENT
, psm
.unpack_alignment
);
3788 glPixelStorei(GL_UNPACK_SKIP_ROWS
, psm
.unpack_skip_rows
);
3789 glPixelStorei(GL_UNPACK_SKIP_PIXELS
, psm
.unpack_skip_pixels
);
3790 glPixelStorei(GL_UNPACK_ROW_LENGTH
, psm
.unpack_row_length
);
3791 glPixelStorei(GL_UNPACK_SWAP_BYTES
, psm
.unpack_swap_bytes
);
3793 free((GLbyte
*) newImage
);
3795 free((GLbyte
*) otherImage
);
3800 /* To make swapping images less error prone */
3801 #define __GLU_INIT_SWAP_IMAGE void *tmpImage
3802 #define __GLU_SWAP_IMAGE(a,b) tmpImage = a; a = b; b = tmpImage;
3804 static int gluBuild2DMipmapLevelsCore(GLenum target
, GLint internalFormat
,
3805 GLsizei width
, GLsizei height
,
3806 GLsizei widthPowerOf2
,
3807 GLsizei heightPowerOf2
,
3808 GLenum format
, GLenum type
,
3810 GLint baseLevel
,GLint maxLevel
,
3813 GLint newwidth
, newheight
;
3814 GLint level
, levels
;
3815 const void *usersImage
; /* passed from user. Don't touch! */
3816 void *srcImage
, *dstImage
; /* scratch area to build mipmapped images */
3817 __GLU_INIT_SWAP_IMAGE
;
3821 GLint myswap_bytes
, groups_per_line
, element_size
, group_size
;
3822 GLint rowsize
, padding
;
3823 PixelStorageModes psm
;
3825 assert(checkMipmapArgs(internalFormat
,format
,type
) == 0);
3826 assert(width
>= 1 && height
>= 1);
3828 if(type
== GL_BITMAP
) {
3829 return bitmapBuild2DMipmaps(target
, internalFormat
, width
, height
,
3830 format
, type
, data
);
3833 srcImage
= dstImage
= NULL
;
3835 newwidth
= widthPowerOf2
;
3836 newheight
= heightPowerOf2
;
3837 levels
= computeLog(newwidth
);
3838 level
= computeLog(newheight
);
3839 if (level
> levels
) levels
=level
;
3843 retrieveStoreModes(&psm
);
3844 myswap_bytes
= psm
.unpack_swap_bytes
;
3845 cmpts
= elements_per_group(format
,type
);
3846 if (psm
.unpack_row_length
> 0) {
3847 groups_per_line
= psm
.unpack_row_length
;
3849 groups_per_line
= width
;
3852 element_size
= bytes_per_element(type
);
3853 group_size
= element_size
* cmpts
;
3854 if (element_size
== 1) myswap_bytes
= 0;
3856 rowsize
= groups_per_line
* group_size
;
3857 padding
= (rowsize
% psm
.unpack_alignment
);
3859 rowsize
+= psm
.unpack_alignment
- padding
;
3861 usersImage
= (const GLubyte
*) data
+ psm
.unpack_skip_rows
* rowsize
+
3862 psm
.unpack_skip_pixels
* group_size
;
3864 glPixelStorei(GL_UNPACK_SKIP_ROWS
, 0);
3865 glPixelStorei(GL_UNPACK_SKIP_PIXELS
, 0);
3866 glPixelStorei(GL_UNPACK_ROW_LENGTH
, 0);
3870 /* already power-of-two square */
3871 if (width
== newwidth
&& height
== newheight
) {
3872 /* Use usersImage for level userLevel */
3873 if (baseLevel
<= level
&& level
<= maxLevel
) {
3874 glPixelStorei(GL_UNPACK_ROW_LENGTH
, psm
.unpack_row_length
);
3875 glTexImage2D(target
, level
, internalFormat
, width
,
3876 height
, 0, format
, type
,
3879 glPixelStorei(GL_UNPACK_ROW_LENGTH
, 0);
3880 if(levels
== 0) { /* we're done. clean up and return */
3881 glPixelStorei(GL_UNPACK_ALIGNMENT
, psm
.unpack_alignment
);
3882 glPixelStorei(GL_UNPACK_SKIP_ROWS
, psm
.unpack_skip_rows
);
3883 glPixelStorei(GL_UNPACK_SKIP_PIXELS
, psm
.unpack_skip_pixels
);
3884 glPixelStorei(GL_UNPACK_ROW_LENGTH
, psm
.unpack_row_length
);
3885 glPixelStorei(GL_UNPACK_SWAP_BYTES
, psm
.unpack_swap_bytes
);
3889 int nextWidth
= newwidth
/2;
3890 int nextHeight
= newheight
/2;
3893 if (nextWidth
< 1) nextWidth
= 1;
3894 if (nextHeight
< 1) nextHeight
= 1;
3895 memreq
= image_size(nextWidth
, nextHeight
, format
, type
);
3899 case GL_UNSIGNED_BYTE
:
3900 dstImage
= (GLubyte
*)malloc(memreq
);
3903 dstImage
= (GLbyte
*)malloc(memreq
);
3905 case GL_UNSIGNED_SHORT
:
3906 dstImage
= (GLushort
*)malloc(memreq
);
3909 dstImage
= (GLshort
*)malloc(memreq
);
3911 case GL_UNSIGNED_INT
:
3912 dstImage
= (GLuint
*)malloc(memreq
);
3915 dstImage
= (GLint
*)malloc(memreq
);
3918 dstImage
= (GLfloat
*)malloc(memreq
);
3920 case GL_UNSIGNED_BYTE_3_3_2
:
3921 case GL_UNSIGNED_BYTE_2_3_3_REV
:
3922 dstImage
= (GLubyte
*)malloc(memreq
);
3924 case GL_UNSIGNED_SHORT_5_6_5
:
3925 case GL_UNSIGNED_SHORT_5_6_5_REV
:
3926 case GL_UNSIGNED_SHORT_4_4_4_4
:
3927 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
3928 case GL_UNSIGNED_SHORT_5_5_5_1
:
3929 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
3930 dstImage
= (GLushort
*)malloc(memreq
);
3932 case GL_UNSIGNED_INT_8_8_8_8
:
3933 case GL_UNSIGNED_INT_8_8_8_8_REV
:
3934 case GL_UNSIGNED_INT_10_10_10_2
:
3935 case GL_UNSIGNED_INT_2_10_10_10_REV
:
3936 dstImage
= (GLuint
*)malloc(memreq
);
3939 return GLU_INVALID_ENUM
;
3941 if (dstImage
== NULL
) {
3942 glPixelStorei(GL_UNPACK_ALIGNMENT
, psm
.unpack_alignment
);
3943 glPixelStorei(GL_UNPACK_SKIP_ROWS
, psm
.unpack_skip_rows
);
3944 glPixelStorei(GL_UNPACK_SKIP_PIXELS
, psm
.unpack_skip_pixels
);
3945 glPixelStorei(GL_UNPACK_ROW_LENGTH
, psm
.unpack_row_length
);
3946 glPixelStorei(GL_UNPACK_SWAP_BYTES
, psm
.unpack_swap_bytes
);
3947 return GLU_OUT_OF_MEMORY
;
3951 case GL_UNSIGNED_BYTE
:
3952 halveImage_ubyte(cmpts
, width
, height
,
3953 (const GLubyte
*)usersImage
, (GLubyte
*)dstImage
,
3954 element_size
, rowsize
, group_size
);
3957 halveImage_byte(cmpts
, width
, height
,
3958 (const GLbyte
*)usersImage
, (GLbyte
*)dstImage
,
3959 element_size
, rowsize
, group_size
);
3961 case GL_UNSIGNED_SHORT
:
3962 halveImage_ushort(cmpts
, width
, height
,
3963 (const GLushort
*)usersImage
, (GLushort
*)dstImage
,
3964 element_size
, rowsize
, group_size
, myswap_bytes
);
3967 halveImage_short(cmpts
, width
, height
,
3968 (const GLshort
*)usersImage
, (GLshort
*)dstImage
,
3969 element_size
, rowsize
, group_size
, myswap_bytes
);
3971 case GL_UNSIGNED_INT
:
3972 halveImage_uint(cmpts
, width
, height
,
3973 (const GLuint
*)usersImage
, (GLuint
*)dstImage
,
3974 element_size
, rowsize
, group_size
, myswap_bytes
);
3977 halveImage_int(cmpts
, width
, height
,
3978 (const GLint
*)usersImage
, (GLint
*)dstImage
,
3979 element_size
, rowsize
, group_size
, myswap_bytes
);
3982 halveImage_float(cmpts
, width
, height
,
3983 (const GLfloat
*)usersImage
, (GLfloat
*)dstImage
,
3984 element_size
, rowsize
, group_size
, myswap_bytes
);
3986 case GL_UNSIGNED_BYTE_3_3_2
:
3987 assert(format
== GL_RGB
);
3988 halveImagePackedPixel(3,extract332
,shove332
,
3989 width
,height
,usersImage
,dstImage
,
3990 element_size
,rowsize
,myswap_bytes
);
3992 case GL_UNSIGNED_BYTE_2_3_3_REV
:
3993 assert(format
== GL_RGB
);
3994 halveImagePackedPixel(3,extract233rev
,shove233rev
,
3995 width
,height
,usersImage
,dstImage
,
3996 element_size
,rowsize
,myswap_bytes
);
3998 case GL_UNSIGNED_SHORT_5_6_5
:
3999 halveImagePackedPixel(3,extract565
,shove565
,
4000 width
,height
,usersImage
,dstImage
,
4001 element_size
,rowsize
,myswap_bytes
);
4003 case GL_UNSIGNED_SHORT_5_6_5_REV
:
4004 halveImagePackedPixel(3,extract565rev
,shove565rev
,
4005 width
,height
,usersImage
,dstImage
,
4006 element_size
,rowsize
,myswap_bytes
);
4008 case GL_UNSIGNED_SHORT_4_4_4_4
:
4009 halveImagePackedPixel(4,extract4444
,shove4444
,
4010 width
,height
,usersImage
,dstImage
,
4011 element_size
,rowsize
,myswap_bytes
);
4013 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
4014 halveImagePackedPixel(4,extract4444rev
,shove4444rev
,
4015 width
,height
,usersImage
,dstImage
,
4016 element_size
,rowsize
,myswap_bytes
);
4018 case GL_UNSIGNED_SHORT_5_5_5_1
:
4019 halveImagePackedPixel(4,extract5551
,shove5551
,
4020 width
,height
,usersImage
,dstImage
,
4021 element_size
,rowsize
,myswap_bytes
);
4023 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
4024 halveImagePackedPixel(4,extract1555rev
,shove1555rev
,
4025 width
,height
,usersImage
,dstImage
,
4026 element_size
,rowsize
,myswap_bytes
);
4028 case GL_UNSIGNED_INT_8_8_8_8
:
4029 halveImagePackedPixel(4,extract8888
,shove8888
,
4030 width
,height
,usersImage
,dstImage
,
4031 element_size
,rowsize
,myswap_bytes
);
4033 case GL_UNSIGNED_INT_8_8_8_8_REV
:
4034 halveImagePackedPixel(4,extract8888rev
,shove8888rev
,
4035 width
,height
,usersImage
,dstImage
,
4036 element_size
,rowsize
,myswap_bytes
);
4038 case GL_UNSIGNED_INT_10_10_10_2
:
4039 halveImagePackedPixel(4,extract1010102
,shove1010102
,
4040 width
,height
,usersImage
,dstImage
,
4041 element_size
,rowsize
,myswap_bytes
);
4043 case GL_UNSIGNED_INT_2_10_10_10_REV
:
4044 halveImagePackedPixel(4,extract2101010rev
,shove2101010rev
,
4045 width
,height
,usersImage
,dstImage
,
4046 element_size
,rowsize
,myswap_bytes
);
4053 newheight
= height
/2;
4055 if (newwidth
< 1) newwidth
= 1;
4056 if (newheight
< 1) newheight
= 1;
4059 rowsize
= newwidth
* group_size
;
4060 memreq
= image_size(newwidth
, newheight
, format
, type
);
4061 /* Swap srcImage and dstImage */
4062 __GLU_SWAP_IMAGE(srcImage
,dstImage
);
4064 case GL_UNSIGNED_BYTE
:
4065 dstImage
= (GLubyte
*)malloc(memreq
);
4068 dstImage
= (GLbyte
*)malloc(memreq
);
4070 case GL_UNSIGNED_SHORT
:
4071 dstImage
= (GLushort
*)malloc(memreq
);
4074 dstImage
= (GLshort
*)malloc(memreq
);
4076 case GL_UNSIGNED_INT
:
4077 dstImage
= (GLuint
*)malloc(memreq
);
4080 dstImage
= (GLint
*)malloc(memreq
);
4083 dstImage
= (GLfloat
*)malloc(memreq
);
4085 case GL_UNSIGNED_BYTE_3_3_2
:
4086 case GL_UNSIGNED_BYTE_2_3_3_REV
:
4087 dstImage
= (GLubyte
*)malloc(memreq
);
4089 case GL_UNSIGNED_SHORT_5_6_5
:
4090 case GL_UNSIGNED_SHORT_5_6_5_REV
:
4091 case GL_UNSIGNED_SHORT_4_4_4_4
:
4092 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
4093 case GL_UNSIGNED_SHORT_5_5_5_1
:
4094 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
4095 dstImage
= (GLushort
*)malloc(memreq
);
4097 case GL_UNSIGNED_INT_8_8_8_8
:
4098 case GL_UNSIGNED_INT_8_8_8_8_REV
:
4099 case GL_UNSIGNED_INT_10_10_10_2
:
4100 case GL_UNSIGNED_INT_2_10_10_10_REV
:
4101 dstImage
= (GLuint
*)malloc(memreq
);
4104 return GLU_INVALID_ENUM
;
4106 if (dstImage
== NULL
) {
4107 glPixelStorei(GL_UNPACK_ALIGNMENT
, psm
.unpack_alignment
);
4108 glPixelStorei(GL_UNPACK_SKIP_ROWS
, psm
.unpack_skip_rows
);
4109 glPixelStorei(GL_UNPACK_SKIP_PIXELS
, psm
.unpack_skip_pixels
);
4110 glPixelStorei(GL_UNPACK_ROW_LENGTH
, psm
.unpack_row_length
);
4111 glPixelStorei(GL_UNPACK_SWAP_BYTES
, psm
.unpack_swap_bytes
);
4112 return GLU_OUT_OF_MEMORY
;
4114 /* level userLevel+1 is in srcImage; level userLevel already saved */
4115 level
= userLevel
+1;
4116 } else { /* user's image is *not* nice power-of-2 sized square */
4117 memreq
= image_size(newwidth
, newheight
, format
, type
);
4119 case GL_UNSIGNED_BYTE
:
4120 dstImage
= (GLubyte
*)malloc(memreq
);
4123 dstImage
= (GLbyte
*)malloc(memreq
);
4125 case GL_UNSIGNED_SHORT
:
4126 dstImage
= (GLushort
*)malloc(memreq
);
4129 dstImage
= (GLshort
*)malloc(memreq
);
4131 case GL_UNSIGNED_INT
:
4132 dstImage
= (GLuint
*)malloc(memreq
);
4135 dstImage
= (GLint
*)malloc(memreq
);
4138 dstImage
= (GLfloat
*)malloc(memreq
);
4140 case GL_UNSIGNED_BYTE_3_3_2
:
4141 case GL_UNSIGNED_BYTE_2_3_3_REV
:
4142 dstImage
= (GLubyte
*)malloc(memreq
);
4144 case GL_UNSIGNED_SHORT_5_6_5
:
4145 case GL_UNSIGNED_SHORT_5_6_5_REV
:
4146 case GL_UNSIGNED_SHORT_4_4_4_4
:
4147 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
4148 case GL_UNSIGNED_SHORT_5_5_5_1
:
4149 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
4150 dstImage
= (GLushort
*)malloc(memreq
);
4152 case GL_UNSIGNED_INT_8_8_8_8
:
4153 case GL_UNSIGNED_INT_8_8_8_8_REV
:
4154 case GL_UNSIGNED_INT_10_10_10_2
:
4155 case GL_UNSIGNED_INT_2_10_10_10_REV
:
4156 dstImage
= (GLuint
*)malloc(memreq
);
4159 return GLU_INVALID_ENUM
;
4162 if (dstImage
== NULL
) {
4163 glPixelStorei(GL_UNPACK_ALIGNMENT
, psm
.unpack_alignment
);
4164 glPixelStorei(GL_UNPACK_SKIP_ROWS
, psm
.unpack_skip_rows
);
4165 glPixelStorei(GL_UNPACK_SKIP_PIXELS
, psm
.unpack_skip_pixels
);
4166 glPixelStorei(GL_UNPACK_ROW_LENGTH
, psm
.unpack_row_length
);
4167 glPixelStorei(GL_UNPACK_SWAP_BYTES
, psm
.unpack_swap_bytes
);
4168 return GLU_OUT_OF_MEMORY
;
4172 case GL_UNSIGNED_BYTE
:
4173 scale_internal_ubyte(cmpts
, width
, height
,
4174 (const GLubyte
*)usersImage
, newwidth
, newheight
,
4175 (GLubyte
*)dstImage
, element_size
,
4176 rowsize
, group_size
);
4179 scale_internal_byte(cmpts
, width
, height
,
4180 (const GLbyte
*)usersImage
, newwidth
, newheight
,
4181 (GLbyte
*)dstImage
, element_size
,
4182 rowsize
, group_size
);
4184 case GL_UNSIGNED_SHORT
:
4185 scale_internal_ushort(cmpts
, width
, height
,
4186 (const GLushort
*)usersImage
, newwidth
, newheight
,
4187 (GLushort
*)dstImage
, element_size
,
4188 rowsize
, group_size
, myswap_bytes
);
4191 scale_internal_short(cmpts
, width
, height
,
4192 (const GLshort
*)usersImage
, newwidth
, newheight
,
4193 (GLshort
*)dstImage
, element_size
,
4194 rowsize
, group_size
, myswap_bytes
);
4196 case GL_UNSIGNED_INT
:
4197 scale_internal_uint(cmpts
, width
, height
,
4198 (const GLuint
*)usersImage
, newwidth
, newheight
,
4199 (GLuint
*)dstImage
, element_size
,
4200 rowsize
, group_size
, myswap_bytes
);
4203 scale_internal_int(cmpts
, width
, height
,
4204 (const GLint
*)usersImage
, newwidth
, newheight
,
4205 (GLint
*)dstImage
, element_size
,
4206 rowsize
, group_size
, myswap_bytes
);
4209 scale_internal_float(cmpts
, width
, height
,
4210 (const GLfloat
*)usersImage
, newwidth
, newheight
,
4211 (GLfloat
*)dstImage
, element_size
,
4212 rowsize
, group_size
, myswap_bytes
);
4214 case GL_UNSIGNED_BYTE_3_3_2
:
4215 scaleInternalPackedPixel(3,extract332
,shove332
,
4216 width
, height
,usersImage
,
4217 newwidth
,newheight
,(void *)dstImage
,
4218 element_size
,rowsize
,myswap_bytes
);
4220 case GL_UNSIGNED_BYTE_2_3_3_REV
:
4221 scaleInternalPackedPixel(3,extract233rev
,shove233rev
,
4222 width
, height
,usersImage
,
4223 newwidth
,newheight
,(void *)dstImage
,
4224 element_size
,rowsize
,myswap_bytes
);
4226 case GL_UNSIGNED_SHORT_5_6_5
:
4227 scaleInternalPackedPixel(3,extract565
,shove565
,
4228 width
, height
,usersImage
,
4229 newwidth
,newheight
,(void *)dstImage
,
4230 element_size
,rowsize
,myswap_bytes
);
4232 case GL_UNSIGNED_SHORT_5_6_5_REV
:
4233 scaleInternalPackedPixel(3,extract565rev
,shove565rev
,
4234 width
, height
,usersImage
,
4235 newwidth
,newheight
,(void *)dstImage
,
4236 element_size
,rowsize
,myswap_bytes
);
4238 case GL_UNSIGNED_SHORT_4_4_4_4
:
4239 scaleInternalPackedPixel(4,extract4444
,shove4444
,
4240 width
, height
,usersImage
,
4241 newwidth
,newheight
,(void *)dstImage
,
4242 element_size
,rowsize
,myswap_bytes
);
4244 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
4245 scaleInternalPackedPixel(4,extract4444rev
,shove4444rev
,
4246 width
, height
,usersImage
,
4247 newwidth
,newheight
,(void *)dstImage
,
4248 element_size
,rowsize
,myswap_bytes
);
4250 case GL_UNSIGNED_SHORT_5_5_5_1
:
4251 scaleInternalPackedPixel(4,extract5551
,shove5551
,
4252 width
, height
,usersImage
,
4253 newwidth
,newheight
,(void *)dstImage
,
4254 element_size
,rowsize
,myswap_bytes
);
4256 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
4257 scaleInternalPackedPixel(4,extract1555rev
,shove1555rev
,
4258 width
, height
,usersImage
,
4259 newwidth
,newheight
,(void *)dstImage
,
4260 element_size
,rowsize
,myswap_bytes
);
4262 case GL_UNSIGNED_INT_8_8_8_8
:
4263 scaleInternalPackedPixel(4,extract8888
,shove8888
,
4264 width
, height
,usersImage
,
4265 newwidth
,newheight
,(void *)dstImage
,
4266 element_size
,rowsize
,myswap_bytes
);
4268 case GL_UNSIGNED_INT_8_8_8_8_REV
:
4269 scaleInternalPackedPixel(4,extract8888rev
,shove8888rev
,
4270 width
, height
,usersImage
,
4271 newwidth
,newheight
,(void *)dstImage
,
4272 element_size
,rowsize
,myswap_bytes
);
4274 case GL_UNSIGNED_INT_10_10_10_2
:
4275 scaleInternalPackedPixel(4,extract1010102
,shove1010102
,
4276 width
, height
,usersImage
,
4277 newwidth
,newheight
,(void *)dstImage
,
4278 element_size
,rowsize
,myswap_bytes
);
4280 case GL_UNSIGNED_INT_2_10_10_10_REV
:
4281 scaleInternalPackedPixel(4,extract2101010rev
,shove2101010rev
,
4282 width
, height
,usersImage
,
4283 newwidth
,newheight
,(void *)dstImage
,
4284 element_size
,rowsize
,myswap_bytes
);
4291 rowsize
= newwidth
* group_size
;
4292 /* Swap dstImage and srcImage */
4293 __GLU_SWAP_IMAGE(srcImage
,dstImage
);
4295 if(levels
!= 0) { /* use as little memory as possible */
4297 int nextWidth
= newwidth
/2;
4298 int nextHeight
= newheight
/2;
4299 if (nextWidth
< 1) nextWidth
= 1;
4300 if (nextHeight
< 1) nextHeight
= 1;
4302 memreq
= image_size(nextWidth
, nextHeight
, format
, type
);
4306 case GL_UNSIGNED_BYTE
:
4307 dstImage
= (GLubyte
*)malloc(memreq
);
4310 dstImage
= (GLbyte
*)malloc(memreq
);
4312 case GL_UNSIGNED_SHORT
:
4313 dstImage
= (GLushort
*)malloc(memreq
);
4316 dstImage
= (GLshort
*)malloc(memreq
);
4318 case GL_UNSIGNED_INT
:
4319 dstImage
= (GLuint
*)malloc(memreq
);
4322 dstImage
= (GLint
*)malloc(memreq
);
4325 dstImage
= (GLfloat
*)malloc(memreq
);
4327 case GL_UNSIGNED_BYTE_3_3_2
:
4328 case GL_UNSIGNED_BYTE_2_3_3_REV
:
4329 dstImage
= (GLubyte
*)malloc(memreq
);
4331 case GL_UNSIGNED_SHORT_5_6_5
:
4332 case GL_UNSIGNED_SHORT_5_6_5_REV
:
4333 case GL_UNSIGNED_SHORT_4_4_4_4
:
4334 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
4335 case GL_UNSIGNED_SHORT_5_5_5_1
:
4336 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
4337 dstImage
= (GLushort
*)malloc(memreq
);
4339 case GL_UNSIGNED_INT_8_8_8_8
:
4340 case GL_UNSIGNED_INT_8_8_8_8_REV
:
4341 case GL_UNSIGNED_INT_10_10_10_2
:
4342 case GL_UNSIGNED_INT_2_10_10_10_REV
:
4343 dstImage
= (GLuint
*)malloc(memreq
);
4346 return GLU_INVALID_ENUM
;
4348 if (dstImage
== NULL
) {
4349 glPixelStorei(GL_UNPACK_ALIGNMENT
, psm
.unpack_alignment
);
4350 glPixelStorei(GL_UNPACK_SKIP_ROWS
, psm
.unpack_skip_rows
);
4351 glPixelStorei(GL_UNPACK_SKIP_PIXELS
, psm
.unpack_skip_pixels
);
4352 glPixelStorei(GL_UNPACK_ROW_LENGTH
, psm
.unpack_row_length
);
4353 glPixelStorei(GL_UNPACK_SWAP_BYTES
, psm
.unpack_swap_bytes
);
4354 return GLU_OUT_OF_MEMORY
;
4357 /* level userLevel is in srcImage; nothing saved yet */
4361 glPixelStorei(GL_UNPACK_SWAP_BYTES
, GL_FALSE
);
4362 if (baseLevel
<= level
&& level
<= maxLevel
) {
4363 glTexImage2D(target
, level
, internalFormat
, newwidth
, newheight
, 0,
4364 format
, type
, (void *)srcImage
);
4367 level
++; /* update current level for the loop */
4368 for (; level
<= levels
; level
++) {
4370 case GL_UNSIGNED_BYTE
:
4371 halveImage_ubyte(cmpts
, newwidth
, newheight
,
4372 (GLubyte
*)srcImage
, (GLubyte
*)dstImage
, element_size
,
4373 rowsize
, group_size
);
4376 halveImage_byte(cmpts
, newwidth
, newheight
,
4377 (GLbyte
*)srcImage
, (GLbyte
*)dstImage
, element_size
,
4378 rowsize
, group_size
);
4380 case GL_UNSIGNED_SHORT
:
4381 halveImage_ushort(cmpts
, newwidth
, newheight
,
4382 (GLushort
*)srcImage
, (GLushort
*)dstImage
, element_size
,
4383 rowsize
, group_size
, myswap_bytes
);
4386 halveImage_short(cmpts
, newwidth
, newheight
,
4387 (GLshort
*)srcImage
, (GLshort
*)dstImage
, element_size
,
4388 rowsize
, group_size
, myswap_bytes
);
4390 case GL_UNSIGNED_INT
:
4391 halveImage_uint(cmpts
, newwidth
, newheight
,
4392 (GLuint
*)srcImage
, (GLuint
*)dstImage
, element_size
,
4393 rowsize
, group_size
, myswap_bytes
);
4396 halveImage_int(cmpts
, newwidth
, newheight
,
4397 (GLint
*)srcImage
, (GLint
*)dstImage
, element_size
,
4398 rowsize
, group_size
, myswap_bytes
);
4401 halveImage_float(cmpts
, newwidth
, newheight
,
4402 (GLfloat
*)srcImage
, (GLfloat
*)dstImage
, element_size
,
4403 rowsize
, group_size
, myswap_bytes
);
4405 case GL_UNSIGNED_BYTE_3_3_2
:
4406 halveImagePackedPixel(3,extract332
,shove332
,
4408 srcImage
,dstImage
,element_size
,rowsize
,
4411 case GL_UNSIGNED_BYTE_2_3_3_REV
:
4412 halveImagePackedPixel(3,extract233rev
,shove233rev
,
4414 srcImage
,dstImage
,element_size
,rowsize
,
4417 case GL_UNSIGNED_SHORT_5_6_5
:
4418 halveImagePackedPixel(3,extract565
,shove565
,
4420 srcImage
,dstImage
,element_size
,rowsize
,
4423 case GL_UNSIGNED_SHORT_5_6_5_REV
:
4424 halveImagePackedPixel(3,extract565rev
,shove565rev
,
4426 srcImage
,dstImage
,element_size
,rowsize
,
4429 case GL_UNSIGNED_SHORT_4_4_4_4
:
4430 halveImagePackedPixel(4,extract4444
,shove4444
,
4432 srcImage
,dstImage
,element_size
,rowsize
,
4435 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
4436 halveImagePackedPixel(4,extract4444rev
,shove4444rev
,
4438 srcImage
,dstImage
,element_size
,rowsize
,
4441 case GL_UNSIGNED_SHORT_5_5_5_1
:
4442 halveImagePackedPixel(4,extract5551
,shove5551
,
4444 srcImage
,dstImage
,element_size
,rowsize
,
4447 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
4448 halveImagePackedPixel(4,extract1555rev
,shove1555rev
,
4450 srcImage
,dstImage
,element_size
,rowsize
,
4453 case GL_UNSIGNED_INT_8_8_8_8
:
4454 halveImagePackedPixel(4,extract8888
,shove8888
,
4456 srcImage
,dstImage
,element_size
,rowsize
,
4459 case GL_UNSIGNED_INT_8_8_8_8_REV
:
4460 halveImagePackedPixel(4,extract8888rev
,shove8888rev
,
4462 srcImage
,dstImage
,element_size
,rowsize
,
4465 case GL_UNSIGNED_INT_10_10_10_2
:
4466 halveImagePackedPixel(4,extract1010102
,shove1010102
,
4468 srcImage
,dstImage
,element_size
,rowsize
,
4471 case GL_UNSIGNED_INT_2_10_10_10_REV
:
4472 halveImagePackedPixel(4,extract2101010rev
,shove2101010rev
,
4474 srcImage
,dstImage
,element_size
,rowsize
,
4482 __GLU_SWAP_IMAGE(srcImage
,dstImage
);
4484 if (newwidth
> 1) { newwidth
/= 2; rowsize
/= 2;}
4485 if (newheight
> 1) newheight
/= 2;
4487 /* compute amount to pad per row, if any */
4488 int rowPad
= rowsize
% psm
.unpack_alignment
;
4490 /* should row be padded? */
4491 if (rowPad
== 0) { /* nope, row should not be padded */
4492 /* call tex image with srcImage untouched since it's not padded */
4493 if (baseLevel
<= level
&& level
<= maxLevel
) {
4494 glTexImage2D(target
, level
, internalFormat
, newwidth
, newheight
, 0,
4495 format
, type
, (void *) srcImage
);
4498 else { /* yes, row should be padded */
4499 /* compute length of new row in bytes, including padding */
4500 int newRowLength
= rowsize
+ psm
.unpack_alignment
- rowPad
;
4501 int ii
; unsigned char *dstTrav
, *srcTrav
; /* indices for copying */
4503 /* allocate new image for mipmap of size newRowLength x newheight */
4504 void *newMipmapImage
= malloc((size_t) (newRowLength
*newheight
));
4505 if (newMipmapImage
== NULL
) {
4506 /* out of memory so return */
4507 glPixelStorei(GL_UNPACK_ALIGNMENT
, psm
.unpack_alignment
);
4508 glPixelStorei(GL_UNPACK_SKIP_ROWS
, psm
.unpack_skip_rows
);
4509 glPixelStorei(GL_UNPACK_SKIP_PIXELS
, psm
.unpack_skip_pixels
);
4510 glPixelStorei(GL_UNPACK_ROW_LENGTH
, psm
.unpack_row_length
);
4511 glPixelStorei(GL_UNPACK_SWAP_BYTES
, psm
.unpack_swap_bytes
);
4512 return GLU_OUT_OF_MEMORY
;
4515 /* copy image from srcImage into newMipmapImage by rows */
4517 dstTrav
= (unsigned char *) newMipmapImage
,
4518 srcTrav
= (unsigned char *) srcImage
;
4521 dstTrav
+= newRowLength
, /* make sure the correct distance... */
4522 srcTrav
+= rowsize
) { /* ...is skipped */
4523 memcpy(dstTrav
,srcTrav
,rowsize
);
4524 /* note that the pad bytes are not visited and will contain
4525 * garbage, which is ok.
4529 /* ...and use this new image for mipmapping instead */
4530 if (baseLevel
<= level
&& level
<= maxLevel
) {
4531 glTexImage2D(target
, level
, internalFormat
, newwidth
, newheight
, 0,
4532 format
, type
, newMipmapImage
);
4534 free(newMipmapImage
); /* don't forget to free it! */
4538 glPixelStorei(GL_UNPACK_ALIGNMENT
, psm
.unpack_alignment
);
4539 glPixelStorei(GL_UNPACK_SKIP_ROWS
, psm
.unpack_skip_rows
);
4540 glPixelStorei(GL_UNPACK_SKIP_PIXELS
, psm
.unpack_skip_pixels
);
4541 glPixelStorei(GL_UNPACK_ROW_LENGTH
, psm
.unpack_row_length
);
4542 glPixelStorei(GL_UNPACK_SWAP_BYTES
, psm
.unpack_swap_bytes
);
4544 free(srcImage
); /*if you get to here, a srcImage has always been malloc'ed*/
4545 if (dstImage
) { /* if it's non-rectangular and only 1 level */
4549 } /* gluBuild2DMipmapLevelsCore() */
4552 gluBuild2DMipmapLevels(GLenum target
, GLint internalFormat
,
4553 GLsizei width
, GLsizei height
,
4554 GLenum format
, GLenum type
,
4555 GLint userLevel
, GLint baseLevel
, GLint maxLevel
,
4560 int rc
= checkMipmapArgs(internalFormat
,format
,type
);
4561 if (rc
!= 0) return rc
;
4563 if (width
< 1 || height
< 1) {
4564 return GLU_INVALID_VALUE
;
4567 levels
= computeLog(width
);
4568 level
= computeLog(height
);
4569 if (level
> levels
) levels
=level
;
4572 if (!isLegalLevels(userLevel
,baseLevel
,maxLevel
,levels
))
4573 return GLU_INVALID_VALUE
;
4575 return gluBuild2DMipmapLevelsCore(target
, internalFormat
,
4579 userLevel
, baseLevel
, maxLevel
,
4581 } /* gluBuild2DMipmapLevels() */
4584 gluBuild2DMipmaps(GLenum target
, GLint internalFormat
,
4585 GLsizei width
, GLsizei height
,
4586 GLenum format
, GLenum type
,
4589 GLint widthPowerOf2
, heightPowerOf2
;
4592 int rc
= checkMipmapArgs(internalFormat
,format
,type
);
4593 if (rc
!= 0) return rc
;
4595 if (width
< 1 || height
< 1) {
4596 return GLU_INVALID_VALUE
;
4599 closestFit(target
,width
,height
,internalFormat
,format
,type
,
4600 &widthPowerOf2
,&heightPowerOf2
);
4602 levels
= computeLog(widthPowerOf2
);
4603 level
= computeLog(heightPowerOf2
);
4604 if (level
> levels
) levels
=level
;
4606 return gluBuild2DMipmapLevelsCore(target
,internalFormat
,
4608 widthPowerOf2
,heightPowerOf2
,
4611 } /* gluBuild2DMipmaps() */
4615 ** This routine is for the limited case in which
4616 ** type == GL_UNSIGNED_BYTE && format != index &&
4617 ** unpack_alignment = 1 && unpack_swap_bytes == false
4619 ** so all of the work data can be kept as ubytes instead of shorts.
4621 static int fastBuild2DMipmaps(const PixelStorageModes
*psm
,
4622 GLenum target
, GLint components
, GLint width
,
4623 GLint height
, GLenum format
,
4624 GLenum type
, void *data
)
4626 GLint newwidth
, newheight
;
4627 GLint level
, levels
;
4629 GLint newImage_width
;
4630 GLint newImage_height
;
4631 GLubyte
*otherImage
;
4638 glGetIntegerv(GL_MAX_TEXTURE_SIZE
, &maxsize
);
4639 newwidth
= nearestPower(width
);
4640 if (newwidth
> maxsize
) newwidth
= maxsize
;
4641 newheight
= nearestPower(height
);
4642 if (newheight
> maxsize
) newheight
= maxsize
;
4644 closestFit(target
,width
,height
,components
,format
,type
,
4645 &newwidth
,&newheight
);
4647 levels
= computeLog(newwidth
);
4648 level
= computeLog(newheight
);
4649 if (level
> levels
) levels
=level
;
4651 cmpts
= elements_per_group(format
,type
);
4655 ** No need to copy the user data if its in the packed correctly.
4656 ** Make sure that later routines don't change that data.
4658 if (psm
->unpack_skip_rows
== 0 && psm
->unpack_skip_pixels
== 0) {
4659 newImage
= (GLubyte
*)data
;
4660 newImage_width
= width
;
4661 newImage_height
= height
;
4664 GLint groups_per_line
;
4665 GLint elements_per_line
;
4666 const GLubyte
*start
;
4667 const GLubyte
*iter
;
4671 newImage
= (GLubyte
*)
4672 malloc(image_size(width
, height
, format
, GL_UNSIGNED_BYTE
));
4673 newImage_width
= width
;
4674 newImage_height
= height
;
4675 if (newImage
== NULL
) {
4676 return GLU_OUT_OF_MEMORY
;
4680 ** Abbreviated version of fill_image for this restricted case.
4682 if (psm
->unpack_row_length
> 0) {
4683 groups_per_line
= psm
->unpack_row_length
;
4685 groups_per_line
= width
;
4687 rowsize
= groups_per_line
* cmpts
;
4688 elements_per_line
= width
* cmpts
;
4689 start
= (const GLubyte
*) data
+ psm
->unpack_skip_rows
* rowsize
+
4690 psm
->unpack_skip_pixels
* cmpts
;
4693 for (i
= 0; i
< height
; i
++) {
4695 for (j
= 0; j
< elements_per_line
; j
++) {
4705 glPixelStorei(GL_UNPACK_ALIGNMENT
, 1);
4706 glPixelStorei(GL_UNPACK_SKIP_ROWS
, 0);
4707 glPixelStorei(GL_UNPACK_SKIP_PIXELS
, 0);
4708 glPixelStorei(GL_UNPACK_ROW_LENGTH
, 0);
4709 glPixelStorei(GL_UNPACK_SWAP_BYTES
, GL_FALSE
);
4711 for (level
= 0; level
<= levels
; level
++) {
4712 if (newImage_width
== newwidth
&& newImage_height
== newheight
) {
4713 /* Use newImage for this level */
4714 glTexImage2D(target
, level
, components
, newImage_width
,
4715 newImage_height
, 0, format
, GL_UNSIGNED_BYTE
,
4718 if (otherImage
== NULL
) {
4720 image_size(newwidth
, newheight
, format
, GL_UNSIGNED_BYTE
);
4721 otherImage
= (GLubyte
*) malloc(memreq
);
4722 if (otherImage
== NULL
) {
4723 glPixelStorei(GL_UNPACK_ALIGNMENT
, psm
->unpack_alignment
);
4724 glPixelStorei(GL_UNPACK_SKIP_ROWS
, psm
->unpack_skip_rows
);
4725 glPixelStorei(GL_UNPACK_SKIP_PIXELS
, psm
->unpack_skip_pixels
);
4726 glPixelStorei(GL_UNPACK_ROW_LENGTH
,psm
->unpack_row_length
);
4727 glPixelStorei(GL_UNPACK_SWAP_BYTES
,psm
->unpack_swap_bytes
);
4728 return GLU_OUT_OF_MEMORY
;
4732 scale_internal_ubyte(cmpts, newImage_width, newImage_height,
4733 newImage, newwidth, newheight, otherImage);
4735 /* Swap newImage and otherImage */
4736 imageTemp
= otherImage
;
4737 otherImage
= newImage
;
4738 newImage
= imageTemp
;
4740 newImage_width
= newwidth
;
4741 newImage_height
= newheight
;
4742 glTexImage2D(target
, level
, components
, newImage_width
,
4743 newImage_height
, 0, format
, GL_UNSIGNED_BYTE
,
4746 if (newwidth
> 1) newwidth
/= 2;
4747 if (newheight
> 1) newheight
/= 2;
4749 glPixelStorei(GL_UNPACK_ALIGNMENT
, psm
->unpack_alignment
);
4750 glPixelStorei(GL_UNPACK_SKIP_ROWS
, psm
->unpack_skip_rows
);
4751 glPixelStorei(GL_UNPACK_SKIP_PIXELS
, psm
->unpack_skip_pixels
);
4752 glPixelStorei(GL_UNPACK_ROW_LENGTH
, psm
->unpack_row_length
);
4753 glPixelStorei(GL_UNPACK_SWAP_BYTES
, psm
->unpack_swap_bytes
);
4755 if (newImage
!= (const GLubyte
*)data
) {
4756 free((GLbyte
*) newImage
);
4758 if (otherImage
&& otherImage
!= (const GLubyte
*)data
) {
4759 free((GLbyte
*) otherImage
);
4768 static GLint
elements_per_group(GLenum format
, GLenum type
)
4771 * Return the number of elements per group of a specified format
4774 /* If the type is packedpixels then answer is 1 (ignore format) */
4775 if (type
== GL_UNSIGNED_BYTE_3_3_2
||
4776 type
== GL_UNSIGNED_BYTE_2_3_3_REV
||
4777 type
== GL_UNSIGNED_SHORT_5_6_5
||
4778 type
== GL_UNSIGNED_SHORT_5_6_5_REV
||
4779 type
== GL_UNSIGNED_SHORT_4_4_4_4
||
4780 type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
||
4781 type
== GL_UNSIGNED_SHORT_5_5_5_1
||
4782 type
== GL_UNSIGNED_SHORT_1_5_5_5_REV
||
4783 type
== GL_UNSIGNED_INT_8_8_8_8
||
4784 type
== GL_UNSIGNED_INT_8_8_8_8_REV
||
4785 type
== GL_UNSIGNED_INT_10_10_10_2
||
4786 type
== GL_UNSIGNED_INT_2_10_10_10_REV
) {
4790 /* Types are not packed pixels, so get elements per group */
4795 case GL_LUMINANCE_ALPHA
:
4805 static GLfloat
bytes_per_element(GLenum type
)
4808 * Return the number of bytes per element, based on the element type
4813 case GL_UNSIGNED_SHORT
:
4814 return(sizeof(GLushort
));
4816 return(sizeof(GLshort
));
4817 case GL_UNSIGNED_BYTE
:
4818 return(sizeof(GLubyte
));
4820 return(sizeof(GLbyte
));
4822 return(sizeof(GLint
));
4823 case GL_UNSIGNED_INT
:
4824 return(sizeof(GLuint
));
4826 return(sizeof(GLfloat
));
4827 case GL_UNSIGNED_BYTE_3_3_2
:
4828 case GL_UNSIGNED_BYTE_2_3_3_REV
:
4829 return(sizeof(GLubyte
));
4830 case GL_UNSIGNED_SHORT_5_6_5
:
4831 case GL_UNSIGNED_SHORT_5_6_5_REV
:
4832 case GL_UNSIGNED_SHORT_4_4_4_4
:
4833 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
4834 case GL_UNSIGNED_SHORT_5_5_5_1
:
4835 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
4836 return(sizeof(GLushort
));
4837 case GL_UNSIGNED_INT_8_8_8_8
:
4838 case GL_UNSIGNED_INT_8_8_8_8_REV
:
4839 case GL_UNSIGNED_INT_10_10_10_2
:
4840 case GL_UNSIGNED_INT_2_10_10_10_REV
:
4841 return(sizeof(GLuint
));
4847 static GLint
is_index(GLenum format
)
4849 return format
== GL_COLOR_INDEX
|| format
== GL_STENCIL_INDEX
;
4853 ** Compute memory required for internal packed array of data of given type
4856 static GLint
image_size(GLint width
, GLint height
, GLenum format
, GLenum type
)
4863 components
= elements_per_group(format
,type
);
4864 if (type
== GL_BITMAP
) {
4865 bytes_per_row
= (width
+ 7) / 8;
4867 bytes_per_row
= bytes_per_element(type
) * width
;
4869 return bytes_per_row
* height
* components
;
4873 ** Extract array from user's data applying all pixel store modes.
4874 ** The internal format used is an array of unsigned shorts.
4876 static void fill_image(const PixelStorageModes
*psm
,
4877 GLint width
, GLint height
, GLenum format
,
4878 GLenum type
, GLboolean index_format
,
4879 const void *userdata
, GLushort
*newimage
)
4885 GLint groups_per_line
;
4887 GLint elements_per_line
;
4888 const GLubyte
*start
;
4889 const GLubyte
*iter
;
4894 myswap_bytes
= psm
->unpack_swap_bytes
;
4895 components
= elements_per_group(format
,type
);
4896 if (psm
->unpack_row_length
> 0) {
4897 groups_per_line
= psm
->unpack_row_length
;
4899 groups_per_line
= width
;
4902 /* All formats except GL_BITMAP fall out trivially */
4903 if (type
== GL_BITMAP
) {
4907 rowsize
= (groups_per_line
* components
+ 7) / 8;
4908 padding
= (rowsize
% psm
->unpack_alignment
);
4910 rowsize
+= psm
->unpack_alignment
- padding
;
4912 start
= (const GLubyte
*) userdata
+ psm
->unpack_skip_rows
* rowsize
+
4913 (psm
->unpack_skip_pixels
* components
/ 8);
4914 elements_per_line
= width
* components
;
4916 for (i
= 0; i
< height
; i
++) {
4918 bit_offset
= (psm
->unpack_skip_pixels
* components
) % 8;
4919 for (j
= 0; j
< elements_per_line
; j
++) {
4921 if (psm
->unpack_lsb_first
) {
4922 current_bit
= iter
[0] & (1 << bit_offset
);
4924 current_bit
= iter
[0] & (1 << (7 - bit_offset
));
4936 if (bit_offset
== 8) {
4945 element_size
= bytes_per_element(type
);
4946 group_size
= element_size
* components
;
4947 if (element_size
== 1) myswap_bytes
= 0;
4949 rowsize
= groups_per_line
* group_size
;
4950 padding
= (rowsize
% psm
->unpack_alignment
);
4952 rowsize
+= psm
->unpack_alignment
- padding
;
4954 start
= (const GLubyte
*) userdata
+ psm
->unpack_skip_rows
* rowsize
+
4955 psm
->unpack_skip_pixels
* group_size
;
4956 elements_per_line
= width
* components
;
4959 for (i
= 0; i
< height
; i
++) {
4961 for (j
= 0; j
< elements_per_line
; j
++) {
4963 float extractComponents
[4];
4966 case GL_UNSIGNED_BYTE_3_3_2
:
4967 extract332(0,iter
,extractComponents
);
4968 for (k
= 0; k
< 3; k
++) {
4969 *iter2
++ = (GLushort
)(extractComponents
[k
]*65535);
4972 case GL_UNSIGNED_BYTE_2_3_3_REV
:
4973 extract233rev(0,iter
,extractComponents
);
4974 for (k
= 0; k
< 3; k
++) {
4975 *iter2
++ = (GLushort
)(extractComponents
[k
]*65535);
4978 case GL_UNSIGNED_BYTE
:
4982 *iter2
++ = (*iter
) * 257;
4987 *iter2
++ = *((const GLbyte
*) iter
);
4990 *iter2
++ = (*((const GLbyte
*) iter
)) * 516;
4993 case GL_UNSIGNED_SHORT_5_6_5
:
4994 extract565(myswap_bytes
,iter
,extractComponents
);
4995 for (k
= 0; k
< 3; k
++) {
4996 *iter2
++ = (GLushort
)(extractComponents
[k
]*65535);
4999 case GL_UNSIGNED_SHORT_5_6_5_REV
:
5000 extract565rev(myswap_bytes
,iter
,extractComponents
);
5001 for (k
= 0; k
< 3; k
++) {
5002 *iter2
++ = (GLushort
)(extractComponents
[k
]*65535);
5005 case GL_UNSIGNED_SHORT_4_4_4_4
:
5006 extract4444(myswap_bytes
,iter
,extractComponents
);
5007 for (k
= 0; k
< 4; k
++) {
5008 *iter2
++ = (GLushort
)(extractComponents
[k
]*65535);
5011 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
5012 extract4444rev(myswap_bytes
,iter
,extractComponents
);
5013 for (k
= 0; k
< 4; k
++) {
5014 *iter2
++ = (GLushort
)(extractComponents
[k
]*65535);
5017 case GL_UNSIGNED_SHORT_5_5_5_1
:
5018 extract5551(myswap_bytes
,iter
,extractComponents
);
5019 for (k
= 0; k
< 4; k
++) {
5020 *iter2
++ = (GLushort
)(extractComponents
[k
]*65535);
5023 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
5024 extract1555rev(myswap_bytes
,iter
,extractComponents
);
5025 for (k
= 0; k
< 4; k
++) {
5026 *iter2
++ = (GLushort
)(extractComponents
[k
]*65535);
5029 case GL_UNSIGNED_SHORT
:
5032 widget
.ub
[0] = iter
[1];
5033 widget
.ub
[1] = iter
[0];
5035 widget
.ub
[0] = iter
[0];
5036 widget
.ub
[1] = iter
[1];
5038 if (type
== GL_SHORT
) {
5040 *iter2
++ = widget
.s
[0];
5043 *iter2
++ = widget
.s
[0]*2;
5046 *iter2
++ = widget
.us
[0];
5049 case GL_UNSIGNED_INT_8_8_8_8
:
5050 extract8888(myswap_bytes
,iter
,extractComponents
);
5051 for (k
= 0; k
< 4; k
++) {
5052 *iter2
++ = (GLushort
)(extractComponents
[k
]*65535);
5055 case GL_UNSIGNED_INT_8_8_8_8_REV
:
5056 extract8888rev(myswap_bytes
,iter
,extractComponents
);
5057 for (k
= 0; k
< 4; k
++) {
5058 *iter2
++ = (GLushort
)(extractComponents
[k
]*65535);
5061 case GL_UNSIGNED_INT_10_10_10_2
:
5062 extract1010102(myswap_bytes
,iter
,extractComponents
);
5063 for (k
= 0; k
< 4; k
++) {
5064 *iter2
++ = (GLushort
)(extractComponents
[k
]*65535);
5067 case GL_UNSIGNED_INT_2_10_10_10_REV
:
5068 extract2101010rev(myswap_bytes
,iter
,extractComponents
);
5069 for (k
= 0; k
< 4; k
++) {
5070 *iter2
++ = (GLushort
)(extractComponents
[k
]*65535);
5074 case GL_UNSIGNED_INT
:
5077 widget
.ub
[0] = iter
[3];
5078 widget
.ub
[1] = iter
[2];
5079 widget
.ub
[2] = iter
[1];
5080 widget
.ub
[3] = iter
[0];
5082 widget
.ub
[0] = iter
[0];
5083 widget
.ub
[1] = iter
[1];
5084 widget
.ub
[2] = iter
[2];
5085 widget
.ub
[3] = iter
[3];
5087 if (type
== GL_FLOAT
) {
5089 *iter2
++ = widget
.f
;
5091 *iter2
++ = 65535 * widget
.f
;
5093 } else if (type
== GL_UNSIGNED_INT
) {
5095 *iter2
++ = widget
.ui
;
5097 *iter2
++ = widget
.ui
>> 16;
5101 *iter2
++ = widget
.i
;
5103 *iter2
++ = widget
.i
>> 15;
5108 iter
+= element_size
;
5112 /* want 'iter' pointing at start, not within, row for assertion
5119 /* iterators should be one byte past end */
5120 if (!isTypePackedPixel(type
)) {
5121 assert(iter2
== &newimage
[width
*height
*components
]);
5124 assert(iter2
== &newimage
[width
*height
*
5125 elements_per_group(format
,0)]);
5127 assert( iter
== &((const GLubyte
*)userdata
)[rowsize
*height
+
5128 psm
->unpack_skip_rows
* rowsize
+
5129 psm
->unpack_skip_pixels
* group_size
] );
5132 } /* fill_image() */
5135 ** Insert array into user's data applying all pixel store modes.
5136 ** The internal format is an array of unsigned shorts.
5137 ** empty_image() because it is the opposite of fill_image().
5139 static void empty_image(const PixelStorageModes
*psm
,
5140 GLint width
, GLint height
, GLenum format
,
5141 GLenum type
, GLboolean index_format
,
5142 const GLushort
*oldimage
, void *userdata
)
5148 GLint groups_per_line
;
5150 GLint elements_per_line
;
5153 const GLushort
*iter2
;
5157 myswap_bytes
= psm
->pack_swap_bytes
;
5158 components
= elements_per_group(format
,type
);
5159 if (psm
->pack_row_length
> 0) {
5160 groups_per_line
= psm
->pack_row_length
;
5162 groups_per_line
= width
;
5165 /* All formats except GL_BITMAP fall out trivially */
5166 if (type
== GL_BITMAP
) {
5170 rowsize
= (groups_per_line
* components
+ 7) / 8;
5171 padding
= (rowsize
% psm
->pack_alignment
);
5173 rowsize
+= psm
->pack_alignment
- padding
;
5175 start
= (GLubyte
*) userdata
+ psm
->pack_skip_rows
* rowsize
+
5176 (psm
->pack_skip_pixels
* components
/ 8);
5177 elements_per_line
= width
* components
;
5179 for (i
= 0; i
< height
; i
++) {
5181 bit_offset
= (psm
->pack_skip_pixels
* components
) % 8;
5182 for (j
= 0; j
< elements_per_line
; j
++) {
5184 current_bit
= iter2
[0] & 1;
5186 if (iter2
[0] > 32767) {
5194 if (psm
->pack_lsb_first
) {
5195 *iter
|= (1 << bit_offset
);
5197 *iter
|= (1 << (7 - bit_offset
));
5200 if (psm
->pack_lsb_first
) {
5201 *iter
&= ~(1 << bit_offset
);
5203 *iter
&= ~(1 << (7 - bit_offset
));
5208 if (bit_offset
== 8) {
5217 float shoveComponents
[4];
5219 element_size
= bytes_per_element(type
);
5220 group_size
= element_size
* components
;
5221 if (element_size
== 1) myswap_bytes
= 0;
5223 rowsize
= groups_per_line
* group_size
;
5224 padding
= (rowsize
% psm
->pack_alignment
);
5226 rowsize
+= psm
->pack_alignment
- padding
;
5228 start
= (GLubyte
*) userdata
+ psm
->pack_skip_rows
* rowsize
+
5229 psm
->pack_skip_pixels
* group_size
;
5230 elements_per_line
= width
* components
;
5233 for (i
= 0; i
< height
; i
++) {
5235 for (j
= 0; j
< elements_per_line
; j
++) {
5239 case GL_UNSIGNED_BYTE_3_3_2
:
5240 for (k
= 0; k
< 3; k
++) {
5241 shoveComponents
[k
]= *iter2
++ / 65535.0;
5243 shove332(shoveComponents
,0,(void *)iter
);
5245 case GL_UNSIGNED_BYTE_2_3_3_REV
:
5246 for (k
= 0; k
< 3; k
++) {
5247 shoveComponents
[k
]= *iter2
++ / 65535.0;
5249 shove233rev(shoveComponents
,0,(void *)iter
);
5251 case GL_UNSIGNED_BYTE
:
5255 *iter
= *iter2
++ >> 8;
5260 *((GLbyte
*) iter
) = *iter2
++;
5262 *((GLbyte
*) iter
) = *iter2
++ >> 9;
5265 case GL_UNSIGNED_SHORT_5_6_5
:
5266 for (k
= 0; k
< 3; k
++) {
5267 shoveComponents
[k
]= *iter2
++ / 65535.0;
5269 shove565(shoveComponents
,0,(void *)&widget
.us
[0]);
5271 iter
[0] = widget
.ub
[1];
5272 iter
[1] = widget
.ub
[0];
5275 *(GLushort
*)iter
= widget
.us
[0];
5278 case GL_UNSIGNED_SHORT_5_6_5_REV
:
5279 for (k
= 0; k
< 3; k
++) {
5280 shoveComponents
[k
]= *iter2
++ / 65535.0;
5282 shove565rev(shoveComponents
,0,(void *)&widget
.us
[0]);
5284 iter
[0] = widget
.ub
[1];
5285 iter
[1] = widget
.ub
[0];
5288 *(GLushort
*)iter
= widget
.us
[0];
5291 case GL_UNSIGNED_SHORT_4_4_4_4
:
5292 for (k
= 0; k
< 4; k
++) {
5293 shoveComponents
[k
]= *iter2
++ / 65535.0;
5295 shove4444(shoveComponents
,0,(void *)&widget
.us
[0]);
5297 iter
[0] = widget
.ub
[1];
5298 iter
[1] = widget
.ub
[0];
5300 *(GLushort
*)iter
= widget
.us
[0];
5303 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
5304 for (k
= 0; k
< 4; k
++) {
5305 shoveComponents
[k
]= *iter2
++ / 65535.0;
5307 shove4444rev(shoveComponents
,0,(void *)&widget
.us
[0]);
5309 iter
[0] = widget
.ub
[1];
5310 iter
[1] = widget
.ub
[0];
5312 *(GLushort
*)iter
= widget
.us
[0];
5315 case GL_UNSIGNED_SHORT_5_5_5_1
:
5316 for (k
= 0; k
< 4; k
++) {
5317 shoveComponents
[k
]= *iter2
++ / 65535.0;
5319 shove5551(shoveComponents
,0,(void *)&widget
.us
[0]);
5321 iter
[0] = widget
.ub
[1];
5322 iter
[1] = widget
.ub
[0];
5324 *(GLushort
*)iter
= widget
.us
[0];
5327 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
5328 for (k
= 0; k
< 4; k
++) {
5329 shoveComponents
[k
]= *iter2
++ / 65535.0;
5331 shove1555rev(shoveComponents
,0,(void *)&widget
.us
[0]);
5333 iter
[0] = widget
.ub
[1];
5334 iter
[1] = widget
.ub
[0];
5336 *(GLushort
*)iter
= widget
.us
[0];
5339 case GL_UNSIGNED_SHORT
:
5341 if (type
== GL_SHORT
) {
5343 widget
.s
[0] = *iter2
++;
5345 widget
.s
[0] = *iter2
++ >> 1;
5348 widget
.us
[0] = *iter2
++;
5351 iter
[0] = widget
.ub
[1];
5352 iter
[1] = widget
.ub
[0];
5354 iter
[0] = widget
.ub
[0];
5355 iter
[1] = widget
.ub
[1];
5358 case GL_UNSIGNED_INT_8_8_8_8
:
5359 for (k
= 0; k
< 4; k
++) {
5360 shoveComponents
[k
]= *iter2
++ / 65535.0;
5362 shove8888(shoveComponents
,0,(void *)&widget
.ui
);
5364 iter
[3] = widget
.ub
[0];
5365 iter
[2] = widget
.ub
[1];
5366 iter
[1] = widget
.ub
[2];
5367 iter
[0] = widget
.ub
[3];
5369 *(GLuint
*)iter
= widget
.ui
;
5373 case GL_UNSIGNED_INT_8_8_8_8_REV
:
5374 for (k
= 0; k
< 4; k
++) {
5375 shoveComponents
[k
]= *iter2
++ / 65535.0;
5377 shove8888rev(shoveComponents
,0,(void *)&widget
.ui
);
5379 iter
[3] = widget
.ub
[0];
5380 iter
[2] = widget
.ub
[1];
5381 iter
[1] = widget
.ub
[2];
5382 iter
[0] = widget
.ub
[3];
5384 *(GLuint
*)iter
= widget
.ui
;
5387 case GL_UNSIGNED_INT_10_10_10_2
:
5388 for (k
= 0; k
< 4; k
++) {
5389 shoveComponents
[k
]= *iter2
++ / 65535.0;
5391 shove1010102(shoveComponents
,0,(void *)&widget
.ui
);
5393 iter
[3] = widget
.ub
[0];
5394 iter
[2] = widget
.ub
[1];
5395 iter
[1] = widget
.ub
[2];
5396 iter
[0] = widget
.ub
[3];
5398 *(GLuint
*)iter
= widget
.ui
;
5401 case GL_UNSIGNED_INT_2_10_10_10_REV
:
5402 for (k
= 0; k
< 4; k
++) {
5403 shoveComponents
[k
]= *iter2
++ / 65535.0;
5405 shove2101010rev(shoveComponents
,0,(void *)&widget
.ui
);
5407 iter
[3] = widget
.ub
[0];
5408 iter
[2] = widget
.ub
[1];
5409 iter
[1] = widget
.ub
[2];
5410 iter
[0] = widget
.ub
[3];
5412 *(GLuint
*)iter
= widget
.ui
;
5416 case GL_UNSIGNED_INT
:
5418 if (type
== GL_FLOAT
) {
5420 widget
.f
= *iter2
++;
5422 widget
.f
= *iter2
++ / (float) 65535.0;
5424 } else if (type
== GL_UNSIGNED_INT
) {
5426 widget
.ui
= *iter2
++;
5428 widget
.ui
= (unsigned int) *iter2
++ * 65537;
5432 widget
.i
= *iter2
++;
5434 widget
.i
= ((unsigned int) *iter2
++ * 65537)/2;
5438 iter
[3] = widget
.ub
[0];
5439 iter
[2] = widget
.ub
[1];
5440 iter
[1] = widget
.ub
[2];
5441 iter
[0] = widget
.ub
[3];
5443 iter
[0] = widget
.ub
[0];
5444 iter
[1] = widget
.ub
[1];
5445 iter
[2] = widget
.ub
[2];
5446 iter
[3] = widget
.ub
[3];
5450 iter
+= element_size
;
5454 /* want 'iter' pointing at start, not within, row for assertion
5461 /* iterators should be one byte past end */
5462 if (!isTypePackedPixel(type
)) {
5463 assert(iter2
== &oldimage
[width
*height
*components
]);
5466 assert(iter2
== &oldimage
[width
*height
*
5467 elements_per_group(format
,0)]);
5469 assert( iter
== &((GLubyte
*)userdata
)[rowsize
*height
+
5470 psm
->pack_skip_rows
* rowsize
+
5471 psm
->pack_skip_pixels
* group_size
] );
5474 } /* empty_image() */
5476 /*--------------------------------------------------------------------------
5477 * Decimation of packed pixel types
5478 *--------------------------------------------------------------------------
5480 static void extract332(int isSwap
,
5481 const void *packedPixel
, GLfloat extractComponents
[])
5483 GLubyte ubyte
= *(const GLubyte
*)packedPixel
;
5485 isSwap
= isSwap
; /* turn off warnings */
5487 /* 11100000 == 0xe0 */
5488 /* 00011100 == 0x1c */
5489 /* 00000011 == 0x03 */
5491 extractComponents
[0]= (float)((ubyte
& 0xe0) >> 5) / 7.0;
5492 extractComponents
[1]= (float)((ubyte
& 0x1c) >> 2) / 7.0; /* 7 = 2^3-1 */
5493 extractComponents
[2]= (float)((ubyte
& 0x03) ) / 3.0; /* 3 = 2^2-1 */
5494 } /* extract332() */
5496 static void shove332(const GLfloat shoveComponents
[],
5497 int index
, void *packedPixel
)
5499 /* 11100000 == 0xe0 */
5500 /* 00011100 == 0x1c */
5501 /* 00000011 == 0x03 */
5503 assert(0.0 <= shoveComponents
[0] && shoveComponents
[0] <= 1.0);
5504 assert(0.0 <= shoveComponents
[1] && shoveComponents
[1] <= 1.0);
5505 assert(0.0 <= shoveComponents
[2] && shoveComponents
[2] <= 1.0);
5507 /* due to limited precision, need to round before shoving */
5508 ((GLubyte
*)packedPixel
)[index
] =
5509 ((GLubyte
)((shoveComponents
[0] * 7)+0.5) << 5) & 0xe0;
5510 ((GLubyte
*)packedPixel
)[index
] |=
5511 ((GLubyte
)((shoveComponents
[1] * 7)+0.5) << 2) & 0x1c;
5512 ((GLubyte
*)packedPixel
)[index
] |=
5513 ((GLubyte
)((shoveComponents
[2] * 3)+0.5) ) & 0x03;
5516 static void extract233rev(int isSwap
,
5517 const void *packedPixel
, GLfloat extractComponents
[])
5519 GLubyte ubyte
= *(const GLubyte
*)packedPixel
;
5521 isSwap
= isSwap
; /* turn off warnings */
5523 /* 0000,0111 == 0x07 */
5524 /* 0011,1000 == 0x38 */
5525 /* 1100,0000 == 0xC0 */
5527 extractComponents
[0]= (float)((ubyte
& 0x07) ) / 7.0;
5528 extractComponents
[1]= (float)((ubyte
& 0x38) >> 3) / 7.0;
5529 extractComponents
[2]= (float)((ubyte
& 0xC0) >> 6) / 3.0;
5530 } /* extract233rev() */
5532 static void shove233rev(const GLfloat shoveComponents
[],
5533 int index
, void *packedPixel
)
5535 /* 0000,0111 == 0x07 */
5536 /* 0011,1000 == 0x38 */
5537 /* 1100,0000 == 0xC0 */
5539 assert(0.0 <= shoveComponents
[0] && shoveComponents
[0] <= 1.0);
5540 assert(0.0 <= shoveComponents
[1] && shoveComponents
[1] <= 1.0);
5541 assert(0.0 <= shoveComponents
[2] && shoveComponents
[2] <= 1.0);
5543 /* due to limited precision, need to round before shoving */
5544 ((GLubyte
*)packedPixel
)[index
] =
5545 ((GLubyte
)((shoveComponents
[0] * 7.0)+0.5) ) & 0x07;
5546 ((GLubyte
*)packedPixel
)[index
]|=
5547 ((GLubyte
)((shoveComponents
[1] * 7.0)+0.5) << 3) & 0x38;
5548 ((GLubyte
*)packedPixel
)[index
]|=
5549 ((GLubyte
)((shoveComponents
[2] * 3.0)+0.5) << 6) & 0xC0;
5550 } /* shove233rev() */
5552 static void extract565(int isSwap
,
5553 const void *packedPixel
, GLfloat extractComponents
[])
5555 GLushort ushort
= *(const GLushort
*)packedPixel
;
5558 ushort
= __GLU_SWAP_2_BYTES(packedPixel
);
5561 ushort
= *(const GLushort
*)packedPixel
;
5564 /* 11111000,00000000 == 0xf800 */
5565 /* 00000111,11100000 == 0x07e0 */
5566 /* 00000000,00011111 == 0x001f */
5568 extractComponents
[0]=(float)((ushort
& 0xf800) >> 11) / 31.0;/* 31 = 2^5-1*/
5569 extractComponents
[1]=(float)((ushort
& 0x07e0) >> 5) / 63.0;/* 63 = 2^6-1*/
5570 extractComponents
[2]=(float)((ushort
& 0x001f) ) / 31.0;
5571 } /* extract565() */
5573 static void shove565(const GLfloat shoveComponents
[],
5574 int index
,void *packedPixel
)
5576 /* 11111000,00000000 == 0xf800 */
5577 /* 00000111,11100000 == 0x07e0 */
5578 /* 00000000,00011111 == 0x001f */
5580 assert(0.0 <= shoveComponents
[0] && shoveComponents
[0] <= 1.0);
5581 assert(0.0 <= shoveComponents
[1] && shoveComponents
[1] <= 1.0);
5582 assert(0.0 <= shoveComponents
[2] && shoveComponents
[2] <= 1.0);
5584 /* due to limited precision, need to round before shoving */
5585 ((GLushort
*)packedPixel
)[index
] =
5586 ((GLushort
)((shoveComponents
[0] * 31)+0.5) << 11) & 0xf800;
5587 ((GLushort
*)packedPixel
)[index
]|=
5588 ((GLushort
)((shoveComponents
[1] * 63)+0.5) << 5) & 0x07e0;
5589 ((GLushort
*)packedPixel
)[index
]|=
5590 ((GLushort
)((shoveComponents
[2] * 31)+0.5) ) & 0x001f;
5593 static void extract565rev(int isSwap
,
5594 const void *packedPixel
, GLfloat extractComponents
[])
5596 GLushort ushort
= *(const GLushort
*)packedPixel
;
5599 ushort
= __GLU_SWAP_2_BYTES(packedPixel
);
5602 ushort
= *(const GLushort
*)packedPixel
;
5605 /* 00000000,00011111 == 0x001f */
5606 /* 00000111,11100000 == 0x07e0 */
5607 /* 11111000,00000000 == 0xf800 */
5609 extractComponents
[0]= (float)((ushort
& 0x001F) ) / 31.0;
5610 extractComponents
[1]= (float)((ushort
& 0x07E0) >> 5) / 63.0;
5611 extractComponents
[2]= (float)((ushort
& 0xF800) >> 11) / 31.0;
5612 } /* extract565rev() */
5614 static void shove565rev(const GLfloat shoveComponents
[],
5615 int index
,void *packedPixel
)
5617 /* 00000000,00011111 == 0x001f */
5618 /* 00000111,11100000 == 0x07e0 */
5619 /* 11111000,00000000 == 0xf800 */
5621 assert(0.0 <= shoveComponents
[0] && shoveComponents
[0] <= 1.0);
5622 assert(0.0 <= shoveComponents
[1] && shoveComponents
[1] <= 1.0);
5623 assert(0.0 <= shoveComponents
[2] && shoveComponents
[2] <= 1.0);
5625 /* due to limited precision, need to round before shoving */
5626 ((GLushort
*)packedPixel
)[index
] =
5627 ((GLushort
)((shoveComponents
[0] * 31.0)+0.5) ) & 0x001F;
5628 ((GLushort
*)packedPixel
)[index
]|=
5629 ((GLushort
)((shoveComponents
[1] * 63.0)+0.5) << 5) & 0x07E0;
5630 ((GLushort
*)packedPixel
)[index
]|=
5631 ((GLushort
)((shoveComponents
[2] * 31.0)+0.5) << 11) & 0xF800;
5632 } /* shove565rev() */
5634 static void extract4444(int isSwap
,const void *packedPixel
,
5635 GLfloat extractComponents
[])
5640 ushort
= __GLU_SWAP_2_BYTES(packedPixel
);
5643 ushort
= *(const GLushort
*)packedPixel
;
5646 /* 11110000,00000000 == 0xf000 */
5647 /* 00001111,00000000 == 0x0f00 */
5648 /* 00000000,11110000 == 0x00f0 */
5649 /* 00000000,00001111 == 0x000f */
5651 extractComponents
[0]= (float)((ushort
& 0xf000) >> 12) / 15.0;/* 15=2^4-1 */
5652 extractComponents
[1]= (float)((ushort
& 0x0f00) >> 8) / 15.0;
5653 extractComponents
[2]= (float)((ushort
& 0x00f0) >> 4) / 15.0;
5654 extractComponents
[3]= (float)((ushort
& 0x000f) ) / 15.0;
5655 } /* extract4444() */
5657 static void shove4444(const GLfloat shoveComponents
[],
5658 int index
,void *packedPixel
)
5660 assert(0.0 <= shoveComponents
[0] && shoveComponents
[0] <= 1.0);
5661 assert(0.0 <= shoveComponents
[1] && shoveComponents
[1] <= 1.0);
5662 assert(0.0 <= shoveComponents
[2] && shoveComponents
[2] <= 1.0);
5663 assert(0.0 <= shoveComponents
[3] && shoveComponents
[3] <= 1.0);
5665 /* due to limited precision, need to round before shoving */
5666 ((GLushort
*)packedPixel
)[index
] =
5667 ((GLushort
)((shoveComponents
[0] * 15)+0.5) << 12) & 0xf000;
5668 ((GLushort
*)packedPixel
)[index
]|=
5669 ((GLushort
)((shoveComponents
[1] * 15)+0.5) << 8) & 0x0f00;
5670 ((GLushort
*)packedPixel
)[index
]|=
5671 ((GLushort
)((shoveComponents
[2] * 15)+0.5) << 4) & 0x00f0;
5672 ((GLushort
*)packedPixel
)[index
]|=
5673 ((GLushort
)((shoveComponents
[3] * 15)+0.5) ) & 0x000f;
5676 static void extract4444rev(int isSwap
,const void *packedPixel
,
5677 GLfloat extractComponents
[])
5682 ushort
= __GLU_SWAP_2_BYTES(packedPixel
);
5685 ushort
= *(const GLushort
*)packedPixel
;
5688 /* 00000000,00001111 == 0x000f */
5689 /* 00000000,11110000 == 0x00f0 */
5690 /* 00001111,00000000 == 0x0f00 */
5691 /* 11110000,00000000 == 0xf000 */
5694 extractComponents
[0]= (float)((ushort
& 0x000F) ) / 15.0;
5695 extractComponents
[1]= (float)((ushort
& 0x00F0) >> 4) / 15.0;
5696 extractComponents
[2]= (float)((ushort
& 0x0F00) >> 8) / 15.0;
5697 extractComponents
[3]= (float)((ushort
& 0xF000) >> 12) / 15.0;
5698 } /* extract4444rev() */
5700 static void shove4444rev(const GLfloat shoveComponents
[],
5701 int index
,void *packedPixel
)
5703 /* 00000000,00001111 == 0x000f */
5704 /* 00000000,11110000 == 0x00f0 */
5705 /* 00001111,00000000 == 0x0f00 */
5706 /* 11110000,00000000 == 0xf000 */
5708 assert(0.0 <= shoveComponents
[0] && shoveComponents
[0] <= 1.0);
5709 assert(0.0 <= shoveComponents
[1] && shoveComponents
[1] <= 1.0);
5710 assert(0.0 <= shoveComponents
[2] && shoveComponents
[2] <= 1.0);
5711 assert(0.0 <= shoveComponents
[3] && shoveComponents
[3] <= 1.0);
5713 /* due to limited precision, need to round before shoving */
5714 ((GLushort
*)packedPixel
)[index
] =
5715 ((GLushort
)((shoveComponents
[0] * 15)+0.5) ) & 0x000F;
5716 ((GLushort
*)packedPixel
)[index
]|=
5717 ((GLushort
)((shoveComponents
[1] * 15)+0.5) << 4) & 0x00F0;
5718 ((GLushort
*)packedPixel
)[index
]|=
5719 ((GLushort
)((shoveComponents
[2] * 15)+0.5) << 8) & 0x0F00;
5720 ((GLushort
*)packedPixel
)[index
]|=
5721 ((GLushort
)((shoveComponents
[3] * 15)+0.5) << 12) & 0xF000;
5722 } /* shove4444rev() */
5724 static void extract5551(int isSwap
,const void *packedPixel
,
5725 GLfloat extractComponents
[])
5730 ushort
= __GLU_SWAP_2_BYTES(packedPixel
);
5733 ushort
= *(const GLushort
*)packedPixel
;
5736 /* 11111000,00000000 == 0xf800 */
5737 /* 00000111,11000000 == 0x07c0 */
5738 /* 00000000,00111110 == 0x003e */
5739 /* 00000000,00000001 == 0x0001 */
5741 extractComponents
[0]=(float)((ushort
& 0xf800) >> 11) / 31.0;/* 31 = 2^5-1*/
5742 extractComponents
[1]=(float)((ushort
& 0x07c0) >> 6) / 31.0;
5743 extractComponents
[2]=(float)((ushort
& 0x003e) >> 1) / 31.0;
5744 extractComponents
[3]=(float)((ushort
& 0x0001) );
5745 } /* extract5551() */
5747 static void shove5551(const GLfloat shoveComponents
[],
5748 int index
,void *packedPixel
)
5750 /* 11111000,00000000 == 0xf800 */
5751 /* 00000111,11000000 == 0x07c0 */
5752 /* 00000000,00111110 == 0x003e */
5753 /* 00000000,00000001 == 0x0001 */
5755 assert(0.0 <= shoveComponents
[0] && shoveComponents
[0] <= 1.0);
5756 assert(0.0 <= shoveComponents
[1] && shoveComponents
[1] <= 1.0);
5757 assert(0.0 <= shoveComponents
[2] && shoveComponents
[2] <= 1.0);
5758 assert(0.0 <= shoveComponents
[3] && shoveComponents
[3] <= 1.0);
5760 /* due to limited precision, need to round before shoving */
5761 ((GLushort
*)packedPixel
)[index
] =
5762 ((GLushort
)((shoveComponents
[0] * 31)+0.5) << 11) & 0xf800;
5763 ((GLushort
*)packedPixel
)[index
]|=
5764 ((GLushort
)((shoveComponents
[1] * 31)+0.5) << 6) & 0x07c0;
5765 ((GLushort
*)packedPixel
)[index
]|=
5766 ((GLushort
)((shoveComponents
[2] * 31)+0.5) << 1) & 0x003e;
5767 ((GLushort
*)packedPixel
)[index
]|=
5768 ((GLushort
)((shoveComponents
[3])+0.5) ) & 0x0001;
5771 static void extract1555rev(int isSwap
,const void *packedPixel
,
5772 GLfloat extractComponents
[])
5777 ushort
= __GLU_SWAP_2_BYTES(packedPixel
);
5780 ushort
= *(const GLushort
*)packedPixel
;
5783 /* 00000000,00011111 == 0x001F */
5784 /* 00000011,11100000 == 0x03E0 */
5785 /* 01111100,00000000 == 0x7C00 */
5786 /* 10000000,00000000 == 0x8000 */
5789 extractComponents
[0]= (float)((ushort
& 0x001F) ) / 31.0;
5790 extractComponents
[1]= (float)((ushort
& 0x03E0) >> 5) / 31.0;
5791 extractComponents
[2]= (float)((ushort
& 0x7C00) >> 10) / 31.0;
5792 extractComponents
[3]= (float)((ushort
& 0x8000) >> 15);
5793 } /* extract1555rev() */
5795 static void shove1555rev(const GLfloat shoveComponents
[],
5796 int index
,void *packedPixel
)
5798 /* 00000000,00011111 == 0x001F */
5799 /* 00000011,11100000 == 0x03E0 */
5800 /* 01111100,00000000 == 0x7C00 */
5801 /* 10000000,00000000 == 0x8000 */
5803 assert(0.0 <= shoveComponents
[0] && shoveComponents
[0] <= 1.0);
5804 assert(0.0 <= shoveComponents
[1] && shoveComponents
[1] <= 1.0);
5805 assert(0.0 <= shoveComponents
[2] && shoveComponents
[2] <= 1.0);
5806 assert(0.0 <= shoveComponents
[3] && shoveComponents
[3] <= 1.0);
5808 /* due to limited precision, need to round before shoving */
5809 ((GLushort
*)packedPixel
)[index
] =
5810 ((GLushort
)((shoveComponents
[0] * 31)+0.5) ) & 0x001F;
5811 ((GLushort
*)packedPixel
)[index
]|=
5812 ((GLushort
)((shoveComponents
[1] * 31)+0.5) << 5) & 0x03E0;
5813 ((GLushort
*)packedPixel
)[index
]|=
5814 ((GLushort
)((shoveComponents
[2] * 31)+0.5) << 10) & 0x7C00;
5815 ((GLushort
*)packedPixel
)[index
]|=
5816 ((GLushort
)((shoveComponents
[3])+0.5) << 15) & 0x8000;
5817 } /* shove1555rev() */
5819 static void extract8888(int isSwap
,
5820 const void *packedPixel
, GLfloat extractComponents
[])
5825 uint
= __GLU_SWAP_4_BYTES(packedPixel
);
5828 uint
= *(const GLuint
*)packedPixel
;
5831 /* 11111111,00000000,00000000,00000000 == 0xff000000 */
5832 /* 00000000,11111111,00000000,00000000 == 0x00ff0000 */
5833 /* 00000000,00000000,11111111,00000000 == 0x0000ff00 */
5834 /* 00000000,00000000,00000000,11111111 == 0x000000ff */
5837 extractComponents
[0]= (float)((uint
& 0xff000000) >> 24) / 255.0;
5838 extractComponents
[1]= (float)((uint
& 0x00ff0000) >> 16) / 255.0;
5839 extractComponents
[2]= (float)((uint
& 0x0000ff00) >> 8) / 255.0;
5840 extractComponents
[3]= (float)((uint
& 0x000000ff) ) / 255.0;
5841 } /* extract8888() */
5843 static void shove8888(const GLfloat shoveComponents
[],
5844 int index
,void *packedPixel
)
5846 /* 11111111,00000000,00000000,00000000 == 0xff000000 */
5847 /* 00000000,11111111,00000000,00000000 == 0x00ff0000 */
5848 /* 00000000,00000000,11111111,00000000 == 0x0000ff00 */
5849 /* 00000000,00000000,00000000,11111111 == 0x000000ff */
5851 assert(0.0 <= shoveComponents
[0] && shoveComponents
[0] <= 1.0);
5852 assert(0.0 <= shoveComponents
[1] && shoveComponents
[1] <= 1.0);
5853 assert(0.0 <= shoveComponents
[2] && shoveComponents
[2] <= 1.0);
5854 assert(0.0 <= shoveComponents
[3] && shoveComponents
[3] <= 1.0);
5856 /* due to limited precision, need to round before shoving */
5857 ((GLuint
*)packedPixel
)[index
] =
5858 ((GLuint
)((shoveComponents
[0] * 255)+0.5) << 24) & 0xff000000;
5859 ((GLuint
*)packedPixel
)[index
]|=
5860 ((GLuint
)((shoveComponents
[1] * 255)+0.5) << 16) & 0x00ff0000;
5861 ((GLuint
*)packedPixel
)[index
]|=
5862 ((GLuint
)((shoveComponents
[2] * 255)+0.5) << 8) & 0x0000ff00;
5863 ((GLuint
*)packedPixel
)[index
]|=
5864 ((GLuint
)((shoveComponents
[3] * 255)+0.5) ) & 0x000000ff;
5867 static void extract8888rev(int isSwap
,
5868 const void *packedPixel
,GLfloat extractComponents
[])
5873 uint
= __GLU_SWAP_4_BYTES(packedPixel
);
5876 uint
= *(const GLuint
*)packedPixel
;
5879 /* 00000000,00000000,00000000,11111111 == 0x000000ff */
5880 /* 00000000,00000000,11111111,00000000 == 0x0000ff00 */
5881 /* 00000000,11111111,00000000,00000000 == 0x00ff0000 */
5882 /* 11111111,00000000,00000000,00000000 == 0xff000000 */
5885 extractComponents
[0]= (float)((uint
& 0x000000FF) ) / 255.0;
5886 extractComponents
[1]= (float)((uint
& 0x0000FF00) >> 8) / 255.0;
5887 extractComponents
[2]= (float)((uint
& 0x00FF0000) >> 16) / 255.0;
5888 extractComponents
[3]= (float)((uint
& 0xFF000000) >> 24) / 255.0;
5889 } /* extract8888rev() */
5891 static void shove8888rev(const GLfloat shoveComponents
[],
5892 int index
,void *packedPixel
)
5894 /* 00000000,00000000,00000000,11111111 == 0x000000ff */
5895 /* 00000000,00000000,11111111,00000000 == 0x0000ff00 */
5896 /* 00000000,11111111,00000000,00000000 == 0x00ff0000 */
5897 /* 11111111,00000000,00000000,00000000 == 0xff000000 */
5899 assert(0.0 <= shoveComponents
[0] && shoveComponents
[0] <= 1.0);
5900 assert(0.0 <= shoveComponents
[1] && shoveComponents
[1] <= 1.0);
5901 assert(0.0 <= shoveComponents
[2] && shoveComponents
[2] <= 1.0);
5902 assert(0.0 <= shoveComponents
[3] && shoveComponents
[3] <= 1.0);
5904 /* due to limited precision, need to round before shoving */
5905 ((GLuint
*)packedPixel
)[index
] =
5906 ((GLuint
)((shoveComponents
[0] * 255)+0.5) ) & 0x000000FF;
5907 ((GLuint
*)packedPixel
)[index
]|=
5908 ((GLuint
)((shoveComponents
[1] * 255)+0.5) << 8) & 0x0000FF00;
5909 ((GLuint
*)packedPixel
)[index
]|=
5910 ((GLuint
)((shoveComponents
[2] * 255)+0.5) << 16) & 0x00FF0000;
5911 ((GLuint
*)packedPixel
)[index
]|=
5912 ((GLuint
)((shoveComponents
[3] * 255)+0.5) << 24) & 0xFF000000;
5913 } /* shove8888rev() */
5915 static void extract1010102(int isSwap
,
5916 const void *packedPixel
,GLfloat extractComponents
[])
5921 uint
= __GLU_SWAP_4_BYTES(packedPixel
);
5924 uint
= *(const GLuint
*)packedPixel
;
5927 /* 11111111,11000000,00000000,00000000 == 0xffc00000 */
5928 /* 00000000,00111111,11110000,00000000 == 0x003ff000 */
5929 /* 00000000,00000000,00001111,11111100 == 0x00000ffc */
5930 /* 00000000,00000000,00000000,00000011 == 0x00000003 */
5933 extractComponents
[0]= (float)((uint
& 0xffc00000) >> 22) / 1023.0;
5934 extractComponents
[1]= (float)((uint
& 0x003ff000) >> 12) / 1023.0;
5935 extractComponents
[2]= (float)((uint
& 0x00000ffc) >> 2) / 1023.0;
5936 extractComponents
[3]= (float)((uint
& 0x00000003) ) / 3.0;
5937 } /* extract1010102() */
5939 static void shove1010102(const GLfloat shoveComponents
[],
5940 int index
,void *packedPixel
)
5942 /* 11111111,11000000,00000000,00000000 == 0xffc00000 */
5943 /* 00000000,00111111,11110000,00000000 == 0x003ff000 */
5944 /* 00000000,00000000,00001111,11111100 == 0x00000ffc */
5945 /* 00000000,00000000,00000000,00000011 == 0x00000003 */
5947 assert(0.0 <= shoveComponents
[0] && shoveComponents
[0] <= 1.0);
5948 assert(0.0 <= shoveComponents
[1] && shoveComponents
[1] <= 1.0);
5949 assert(0.0 <= shoveComponents
[2] && shoveComponents
[2] <= 1.0);
5950 assert(0.0 <= shoveComponents
[3] && shoveComponents
[3] <= 1.0);
5952 /* due to limited precision, need to round before shoving */
5953 ((GLuint
*)packedPixel
)[index
] =
5954 ((GLuint
)((shoveComponents
[0] * 1023)+0.5) << 22) & 0xffc00000;
5955 ((GLuint
*)packedPixel
)[index
]|=
5956 ((GLuint
)((shoveComponents
[1] * 1023)+0.5) << 12) & 0x003ff000;
5957 ((GLuint
*)packedPixel
)[index
]|=
5958 ((GLuint
)((shoveComponents
[2] * 1023)+0.5) << 2) & 0x00000ffc;
5959 ((GLuint
*)packedPixel
)[index
]|=
5960 ((GLuint
)((shoveComponents
[3] * 3)+0.5) ) & 0x00000003;
5961 } /* shove1010102() */
5963 static void extract2101010rev(int isSwap
,
5964 const void *packedPixel
,
5965 GLfloat extractComponents
[])
5970 uint
= __GLU_SWAP_4_BYTES(packedPixel
);
5973 uint
= *(const GLuint
*)packedPixel
;
5976 /* 00000000,00000000,00000011,11111111 == 0x000003FF */
5977 /* 00000000,00001111,11111100,00000000 == 0x000FFC00 */
5978 /* 00111111,11110000,00000000,00000000 == 0x3FF00000 */
5979 /* 11000000,00000000,00000000,00000000 == 0xC0000000 */
5982 extractComponents
[0]= (float)((uint
& 0x000003FF) ) / 1023.0;
5983 extractComponents
[1]= (float)((uint
& 0x000FFC00) >> 10) / 1023.0;
5984 extractComponents
[2]= (float)((uint
& 0x3FF00000) >> 20) / 1023.0;
5985 extractComponents
[3]= (float)((uint
& 0xC0000000) >> 30) / 3.0;
5987 } /* extract2101010rev() */
5989 static void shove2101010rev(const GLfloat shoveComponents
[],
5990 int index
,void *packedPixel
)
5992 /* 00000000,00000000,00000011,11111111 == 0x000003FF */
5993 /* 00000000,00001111,11111100,00000000 == 0x000FFC00 */
5994 /* 00111111,11110000,00000000,00000000 == 0x3FF00000 */
5995 /* 11000000,00000000,00000000,00000000 == 0xC0000000 */
5997 assert(0.0 <= shoveComponents
[0] && shoveComponents
[0] <= 1.0);
5998 assert(0.0 <= shoveComponents
[1] && shoveComponents
[1] <= 1.0);
5999 assert(0.0 <= shoveComponents
[2] && shoveComponents
[2] <= 1.0);
6000 assert(0.0 <= shoveComponents
[3] && shoveComponents
[3] <= 1.0);
6002 /* due to limited precision, need to round before shoving */
6003 ((GLuint
*)packedPixel
)[index
] =
6004 ((GLuint
)((shoveComponents
[0] * 1023)+0.5) ) & 0x000003FF;
6005 ((GLuint
*)packedPixel
)[index
]|=
6006 ((GLuint
)((shoveComponents
[1] * 1023)+0.5) << 10) & 0x000FFC00;
6007 ((GLuint
*)packedPixel
)[index
]|=
6008 ((GLuint
)((shoveComponents
[2] * 1023)+0.5) << 20) & 0x3FF00000;
6009 ((GLuint
*)packedPixel
)[index
]|=
6010 ((GLuint
)((shoveComponents
[3] * 3)+0.5) << 30) & 0xC0000000;
6011 } /* shove2101010rev() */
6013 static void scaleInternalPackedPixel(int components
,
6014 void (*extractPackedPixel
)
6015 (int, const void *,GLfloat
[]),
6016 void (*shovePackedPixel
)
6017 (const GLfloat
[], int, void *),
6018 GLint widthIn
,GLint heightIn
,
6020 GLint widthOut
,GLint heightOut
,
6022 GLint pixelSizeInBytes
,
6023 GLint rowSizeInBytes
,GLint isSwap
)
6029 /* Max components in a format is 4, so... */
6031 float extractTotals
[4], extractMoreTotals
[4], shoveTotals
[4];
6036 const char *temp
, *temp0
;
6039 int lowx_int
, highx_int
, lowy_int
, highy_int
;
6040 float x_percent
, y_percent
;
6041 float lowx_float
, highx_float
, lowy_float
, highy_float
;
6042 float convy_float
, convx_float
;
6043 int convy_int
, convx_int
;
6045 const char *left
, *right
;
6047 if (widthIn
== widthOut
*2 && heightIn
== heightOut
*2) {
6048 halveImagePackedPixel(components
,extractPackedPixel
,shovePackedPixel
,
6049 widthIn
, heightIn
, dataIn
, dataOut
,
6050 pixelSizeInBytes
,rowSizeInBytes
,isSwap
);
6053 convy
= (float) heightIn
/heightOut
;
6054 convx
= (float) widthIn
/widthOut
;
6055 convy_int
= floor(convy
);
6056 convy_float
= convy
- convy_int
;
6057 convx_int
= floor(convx
);
6058 convx_float
= convx
- convx_int
;
6060 area
= convx
* convy
;
6064 highy_int
= convy_int
;
6065 highy_float
= convy_float
;
6067 for (i
= 0; i
< heightOut
; i
++) {
6070 highx_int
= convx_int
;
6071 highx_float
= convx_float
;
6073 for (j
= 0; j
< widthOut
; j
++) {
6075 ** Ok, now apply box filter to box that goes from (lowx, lowy)
6076 ** to (highx, highy) on input data into this pixel on output
6079 totals
[0] = totals
[1] = totals
[2] = totals
[3] = 0.0;
6081 /* calculate the value for pixels in the 1st row */
6082 xindex
= lowx_int
*pixelSizeInBytes
;
6083 if((highy_int
>lowy_int
) && (highx_int
>lowx_int
)) {
6085 y_percent
= 1-lowy_float
;
6086 temp
= (const char *)dataIn
+ xindex
+ lowy_int
* rowSizeInBytes
;
6087 percent
= y_percent
* (1-lowx_float
);
6089 for (k
= 0, temp_index
= temp
; k
< components
;
6090 k
++, temp_index
+= element_size
) {
6092 totals
[k
] += __GLU_SWAP_2_BYTES(temp_index
) * percent
;
6094 totals
[k
] += *(const GLushort
*)temp_index
* percent
;
6098 (*extractPackedPixel
)(isSwap
,temp
,extractTotals
);
6099 for (k
= 0; k
< components
; k
++) {
6100 totals
[k
]+= extractTotals
[k
] * percent
;
6104 for(l
= lowx_int
+1; l
< highx_int
; l
++) {
6105 temp
+= pixelSizeInBytes
;
6107 for (k
= 0, temp_index
= temp
; k
< components
;
6108 k
++, temp_index
+= element_size
) {
6111 __GLU_SWAP_2_BYTES(temp_index
) * y_percent
;
6113 totals
[k
] += *(const GLushort
*)temp_index
* y_percent
;
6117 (*extractPackedPixel
)(isSwap
,temp
,extractTotals
);
6118 for (k
= 0; k
< components
; k
++) {
6119 totals
[k
]+= extractTotals
[k
] * y_percent
;
6123 temp
+= pixelSizeInBytes
;
6125 percent
= y_percent
* highx_float
;
6127 for (k
= 0, temp_index
= temp
; k
< components
;
6128 k
++, temp_index
+= element_size
) {
6130 totals
[k
] += __GLU_SWAP_2_BYTES(temp_index
) * percent
;
6132 totals
[k
] += *(const GLushort
*)temp_index
* percent
;
6136 (*extractPackedPixel
)(isSwap
,temp
,extractTotals
);
6137 for (k
= 0; k
< components
; k
++) {
6138 totals
[k
]+= extractTotals
[k
] * percent
;
6142 /* calculate the value for pixels in the last row */
6144 y_percent
= highy_float
;
6145 percent
= y_percent
* (1-lowx_float
);
6146 temp
= (const char *)dataIn
+ xindex
+ highy_int
* rowSizeInBytes
;
6148 for (k
= 0, temp_index
= temp
; k
< components
;
6149 k
++, temp_index
+= element_size
) {
6151 totals
[k
] += __GLU_SWAP_2_BYTES(temp_index
) * percent
;
6153 totals
[k
] += *(const GLushort
*)temp_index
* percent
;
6157 (*extractPackedPixel
)(isSwap
,temp
,extractTotals
);
6158 for (k
= 0; k
< components
; k
++) {
6159 totals
[k
]+= extractTotals
[k
] * percent
;
6162 for(l
= lowx_int
+1; l
< highx_int
; l
++) {
6163 temp
+= pixelSizeInBytes
;
6165 for (k
= 0, temp_index
= temp
; k
< components
;
6166 k
++, temp_index
+= element_size
) {
6169 __GLU_SWAP_2_BYTES(temp_index
) * y_percent
;
6171 totals
[k
] += *(const GLushort
*)temp_index
* y_percent
;
6175 (*extractPackedPixel
)(isSwap
,temp
,extractTotals
);
6176 for (k
= 0; k
< components
; k
++) {
6177 totals
[k
]+= extractTotals
[k
] * y_percent
;
6182 temp
+= pixelSizeInBytes
;
6183 percent
= y_percent
* highx_float
;
6185 for (k
= 0, temp_index
= temp
; k
< components
;
6186 k
++, temp_index
+= element_size
) {
6188 totals
[k
] += __GLU_SWAP_2_BYTES(temp_index
) * percent
;
6190 totals
[k
] += *(const GLushort
*)temp_index
* percent
;
6194 (*extractPackedPixel
)(isSwap
,temp
,extractTotals
);
6195 for (k
= 0; k
< components
; k
++) {
6196 totals
[k
]+= extractTotals
[k
] * percent
;
6200 /* calculate the value for pixels in the 1st and last column */
6201 for(m
= lowy_int
+1; m
< highy_int
; m
++) {
6202 left
+= rowSizeInBytes
;
6203 right
+= rowSizeInBytes
;
6205 for (k
= 0; k
< components
;
6206 k
++, left
+= element_size
, right
+= element_size
) {
6209 __GLU_SWAP_2_BYTES(left
) * (1-lowx_float
) +
6210 __GLU_SWAP_2_BYTES(right
) * highx_float
;
6212 totals
[k
] += *(const GLushort
*)left
* (1-lowx_float
)
6213 + *(const GLushort
*)right
* highx_float
;
6217 (*extractPackedPixel
)(isSwap
,left
,extractTotals
);
6218 (*extractPackedPixel
)(isSwap
,right
,extractMoreTotals
);
6219 for (k
= 0; k
< components
; k
++) {
6220 totals
[k
]+= (extractTotals
[k
]*(1-lowx_float
) +
6221 extractMoreTotals
[k
]*highx_float
);
6225 } else if (highy_int
> lowy_int
) {
6226 x_percent
= highx_float
- lowx_float
;
6227 percent
= (1-lowy_float
)*x_percent
;
6228 temp
= (const char *)dataIn
+ xindex
+ lowy_int
*rowSizeInBytes
;
6230 for (k
= 0, temp_index
= temp
; k
< components
;
6231 k
++, temp_index
+= element_size
) {
6233 totals
[k
] += __GLU_SWAP_2_BYTES(temp_index
) * percent
;
6235 totals
[k
] += *(const GLushort
*)temp_index
* percent
;
6239 (*extractPackedPixel
)(isSwap
,temp
,extractTotals
);
6240 for (k
= 0; k
< components
; k
++) {
6241 totals
[k
]+= extractTotals
[k
] * percent
;
6244 for(m
= lowy_int
+1; m
< highy_int
; m
++) {
6245 temp
+= rowSizeInBytes
;
6247 for (k
= 0, temp_index
= temp
; k
< components
;
6248 k
++, temp_index
+= element_size
) {
6251 __GLU_SWAP_2_BYTES(temp_index
) * x_percent
;
6253 totals
[k
] += *(const GLushort
*)temp_index
* x_percent
;
6257 (*extractPackedPixel
)(isSwap
,temp
,extractTotals
);
6258 for (k
= 0; k
< components
; k
++) {
6259 totals
[k
]+= extractTotals
[k
] * x_percent
;
6263 percent
= x_percent
* highy_float
;
6264 temp
+= rowSizeInBytes
;
6266 for (k
= 0, temp_index
= temp
; k
< components
;
6267 k
++, temp_index
+= element_size
) {
6269 totals
[k
] += __GLU_SWAP_2_BYTES(temp_index
) * percent
;
6271 totals
[k
] += *(const GLushort
*)temp_index
* percent
;
6275 (*extractPackedPixel
)(isSwap
,temp
,extractTotals
);
6276 for (k
= 0; k
< components
; k
++) {
6277 totals
[k
]+= extractTotals
[k
] * percent
;
6280 } else if (highx_int
> lowx_int
) {
6281 y_percent
= highy_float
- lowy_float
;
6282 percent
= (1-lowx_float
)*y_percent
;
6283 temp
= (const char *)dataIn
+ xindex
+ lowy_int
*rowSizeInBytes
;
6285 for (k
= 0, temp_index
= temp
; k
< components
;
6286 k
++, temp_index
+= element_size
) {
6288 totals
[k
] += __GLU_SWAP_2_BYTES(temp_index
) * percent
;
6290 totals
[k
] += *(const GLushort
*)temp_index
* percent
;
6294 (*extractPackedPixel
)(isSwap
,temp
,extractTotals
);
6295 for (k
= 0; k
< components
; k
++) {
6296 totals
[k
]+= extractTotals
[k
] * percent
;
6299 for (l
= lowx_int
+1; l
< highx_int
; l
++) {
6300 temp
+= pixelSizeInBytes
;
6302 for (k
= 0, temp_index
= temp
; k
< components
;
6303 k
++, temp_index
+= element_size
) {
6306 __GLU_SWAP_2_BYTES(temp_index
) * y_percent
;
6308 totals
[k
] += *(const GLushort
*)temp_index
* y_percent
;
6312 (*extractPackedPixel
)(isSwap
,temp
,extractTotals
);
6313 for (k
= 0; k
< components
; k
++) {
6314 totals
[k
]+= extractTotals
[k
] * y_percent
;
6318 temp
+= pixelSizeInBytes
;
6319 percent
= y_percent
* highx_float
;
6321 for (k
= 0, temp_index
= temp
; k
< components
;
6322 k
++, temp_index
+= element_size
) {
6324 totals
[k
] += __GLU_SWAP_2_BYTES(temp_index
) * percent
;
6326 totals
[k
] += *(const GLushort
*)temp_index
* percent
;
6330 (*extractPackedPixel
)(isSwap
,temp
,extractTotals
);
6331 for (k
= 0; k
< components
; k
++) {
6332 totals
[k
]+= extractTotals
[k
] * percent
;
6336 percent
= (highy_float
-lowy_float
)*(highx_float
-lowx_float
);
6337 temp
= (const char *)dataIn
+ xindex
+ lowy_int
* rowSizeInBytes
;
6339 for (k
= 0, temp_index
= temp
; k
< components
;
6340 k
++, temp_index
+= element_size
) {
6342 totals
[k
] += __GLU_SWAP_2_BYTES(temp_index
) * percent
;
6344 totals
[k
] += *(const GLushort
*)temp_index
* percent
;
6348 (*extractPackedPixel
)(isSwap
,temp
,extractTotals
);
6349 for (k
= 0; k
< components
; k
++) {
6350 totals
[k
]+= extractTotals
[k
] * percent
;
6355 /* this is for the pixels in the body */
6356 temp0
= (const char *)dataIn
+ xindex
+ pixelSizeInBytes
+ (lowy_int
+1)*rowSizeInBytes
;
6357 for (m
= lowy_int
+1; m
< highy_int
; m
++) {
6359 for(l
= lowx_int
+1; l
< highx_int
; l
++) {
6361 for (k
= 0, temp_index
= temp
; k
< components
;
6362 k
++, temp_index
+= element_size
) {
6364 totals
[k
] += __GLU_SWAP_2_BYTES(temp_index
);
6366 totals
[k
] += *(const GLushort
*)temp_index
;
6370 (*extractPackedPixel
)(isSwap
,temp
,extractTotals
);
6371 for (k
= 0; k
< components
; k
++) {
6372 totals
[k
]+= extractTotals
[k
];
6375 temp
+= pixelSizeInBytes
;
6377 temp0
+= rowSizeInBytes
;
6380 outindex
= (j
+ (i
* widthOut
)); /* * (components == 1) */
6382 for (k
= 0; k
< components
; k
++) {
6383 dataout
[outindex
+ k
] = totals
[k
]/area
;
6384 /*printf("totals[%d] = %f\n", k, totals[k]);*/
6387 for (k
= 0; k
< components
; k
++) {
6388 shoveTotals
[k
]= totals
[k
]/area
;
6390 (*shovePackedPixel
)(shoveTotals
,outindex
,(void *)dataOut
);
6392 lowx_int
= highx_int
;
6393 lowx_float
= highx_float
;
6394 highx_int
+= convx_int
;
6395 highx_float
+= convx_float
;
6396 if(highx_float
> 1) {
6401 lowy_int
= highy_int
;
6402 lowy_float
= highy_float
;
6403 highy_int
+= convy_int
;
6404 highy_float
+= convy_float
;
6405 if(highy_float
> 1) {
6411 assert(outindex
== (widthOut
*heightOut
- 1));
6412 } /* scaleInternalPackedPixel() */
6414 /* rowSizeInBytes is at least the width (in bytes) due to padding on
6415 * inputs; not always equal. Output NEVER has row padding.
6417 static void halveImagePackedPixel(int components
,
6418 void (*extractPackedPixel
)
6419 (int, const void *,GLfloat
[]),
6420 void (*shovePackedPixel
)
6421 (const GLfloat
[],int, void *),
6422 GLint width
, GLint height
,
6423 const void *dataIn
, void *dataOut
,
6424 GLint pixelSizeInBytes
,
6425 GLint rowSizeInBytes
, GLint isSwap
)
6427 /* handle case where there is only 1 column/row */
6428 if (width
== 1 || height
== 1) {
6429 assert(!(width
== 1 && height
== 1)); /* can't be 1x1 */
6430 halve1DimagePackedPixel(components
,extractPackedPixel
,shovePackedPixel
,
6431 width
,height
,dataIn
,dataOut
,pixelSizeInBytes
,
6432 rowSizeInBytes
,isSwap
);
6439 int halfWidth
= width
/ 2;
6440 int halfHeight
= height
/ 2;
6441 const char *src
= (const char *) dataIn
;
6442 int padBytes
= rowSizeInBytes
- (width
*pixelSizeInBytes
);
6445 for (ii
= 0; ii
< halfHeight
; ii
++) {
6446 for (jj
= 0; jj
< halfWidth
; jj
++) {
6448 float totals
[4]; /* 4 is maximum components */
6449 float extractTotals
[BOX4
][4]; /* 4 is maximum components */
6452 (*extractPackedPixel
)(isSwap
,src
,
6453 &extractTotals
[0][0]);
6454 (*extractPackedPixel
)(isSwap
,(src
+pixelSizeInBytes
),
6455 &extractTotals
[1][0]);
6456 (*extractPackedPixel
)(isSwap
,(src
+rowSizeInBytes
),
6457 &extractTotals
[2][0]);
6458 (*extractPackedPixel
)(isSwap
,
6459 (src
+rowSizeInBytes
+pixelSizeInBytes
),
6460 &extractTotals
[3][0]);
6461 for (cc
= 0; cc
< components
; cc
++) {
6464 /* grab 4 pixels to average */
6466 /* totals[RED]= extractTotals[0][RED]+extractTotals[1][RED]+
6467 * extractTotals[2][RED]+extractTotals[3][RED];
6468 * totals[RED]/= 4.0;
6470 for (kk
= 0; kk
< BOX4
; kk
++) {
6471 totals
[cc
]+= extractTotals
[kk
][cc
];
6473 totals
[cc
]/= (float)BOX4
;
6475 (*shovePackedPixel
)(totals
,outIndex
,dataOut
);
6478 /* skip over to next square of 4 */
6479 src
+= pixelSizeInBytes
+ pixelSizeInBytes
;
6481 /* skip past pad bytes, if any, to get to next row */
6484 /* src is at beginning of a row here, but it's the second row of
6485 * the square block of 4 pixels that we just worked on so we
6486 * need to go one more row.
6494 src
+= rowSizeInBytes
;
6497 /* both pointers must reach one byte after the end */
6498 assert(src
== &((const char *)dataIn
)[rowSizeInBytes
*height
]);
6499 assert(outIndex
== halfWidth
* halfHeight
);
6501 } /* halveImagePackedPixel() */
6503 static void halve1DimagePackedPixel(int components
,
6504 void (*extractPackedPixel
)
6505 (int, const void *,GLfloat
[]),
6506 void (*shovePackedPixel
)
6507 (const GLfloat
[],int, void *),
6508 GLint width
, GLint height
,
6509 const void *dataIn
, void *dataOut
,
6510 GLint pixelSizeInBytes
,
6511 GLint rowSizeInBytes
, GLint isSwap
)
6513 int halfWidth
= width
/ 2;
6514 int halfHeight
= height
/ 2;
6515 const char *src
= (const char *) dataIn
;
6518 assert(width
== 1 || height
== 1); /* must be 1D */
6519 assert(width
!= height
); /* can't be square */
6521 if (height
== 1) { /* 1 row */
6524 assert(width
!= 1); /* widthxheight can't be 1x1 */
6527 /* one horizontal row with possible pad bytes */
6529 for (jj
= 0; jj
< halfWidth
; jj
++) {
6531 float totals
[4]; /* 4 is maximum components */
6532 float extractTotals
[BOX2
][4]; /* 4 is maximum components */
6535 /* average two at a time, instead of four */
6536 (*extractPackedPixel
)(isSwap
,src
,
6537 &extractTotals
[0][0]);
6538 (*extractPackedPixel
)(isSwap
,(src
+pixelSizeInBytes
),
6539 &extractTotals
[1][0]);
6540 for (cc
= 0; cc
< components
; cc
++) {
6543 /* grab 2 pixels to average */
6545 /* totals[RED]= extractTotals[0][RED]+extractTotals[1][RED];
6546 * totals[RED]/= 2.0;
6548 for (kk
= 0; kk
< BOX2
; kk
++) {
6549 totals
[cc
]+= extractTotals
[kk
][cc
];
6551 totals
[cc
]/= (float)BOX2
;
6553 (*shovePackedPixel
)(totals
,outIndex
,dataOut
);
6556 /* skip over to next group of 2 */
6557 src
+= pixelSizeInBytes
+ pixelSizeInBytes
;
6561 int padBytes
= rowSizeInBytes
- (width
*pixelSizeInBytes
);
6562 src
+= padBytes
; /* for assertion only */
6564 assert(src
== &((const char *)dataIn
)[rowSizeInBytes
]);
6565 assert(outIndex
== halfWidth
* halfHeight
);
6567 else if (width
== 1) { /* 1 column */
6570 assert(height
!= 1); /* widthxheight can't be 1x1 */
6572 /* one vertical column with possible pad bytes per row */
6573 /* average two at a time */
6575 for (jj
= 0; jj
< halfHeight
; jj
++) {
6577 float totals
[4]; /* 4 is maximum components */
6578 float extractTotals
[BOX2
][4]; /* 4 is maximum components */
6581 /* average two at a time, instead of four */
6582 (*extractPackedPixel
)(isSwap
,src
,
6583 &extractTotals
[0][0]);
6584 (*extractPackedPixel
)(isSwap
,(src
+rowSizeInBytes
),
6585 &extractTotals
[1][0]);
6586 for (cc
= 0; cc
< components
; cc
++) {
6589 /* grab 2 pixels to average */
6591 /* totals[RED]= extractTotals[0][RED]+extractTotals[1][RED];
6592 * totals[RED]/= 2.0;
6594 for (kk
= 0; kk
< BOX2
; kk
++) {
6595 totals
[cc
]+= extractTotals
[kk
][cc
];
6597 totals
[cc
]/= (float)BOX2
;
6599 (*shovePackedPixel
)(totals
,outIndex
,dataOut
);
6602 src
+= rowSizeInBytes
+ rowSizeInBytes
; /* go to row after next */
6605 assert(src
== &((const char *)dataIn
)[rowSizeInBytes
*height
]);
6606 assert(outIndex
== halfWidth
* halfHeight
);
6608 } /* halve1DimagePackedPixel() */
6610 /*===========================================================================*/
6612 #ifdef RESOLVE_3D_TEXTURE_SUPPORT
6614 * This section ensures that GLU 1.3 will load and run on
6615 * a GL 1.1 implementation. It dynamically resolves the
6616 * call to glTexImage3D() which might not be available.
6617 * Or is it might be supported as an extension.
6618 * Contributed by Gerk Huisma <gerk@five-d.demon.nl>.
6621 typedef void (GLAPIENTRY
*TexImage3Dproc
)( GLenum target
, GLint level
,
6622 GLenum internalFormat
,
6623 GLsizei width
, GLsizei height
,
6624 GLsizei depth
, GLint border
,
6625 GLenum format
, GLenum type
,
6626 const GLvoid
*pixels
);
6628 static TexImage3Dproc pTexImage3D
= 0;
6632 # include <sys/types.h>
6634 WINGDIAPI PROC WINAPI
wglGetProcAddress(LPCSTR
);
6637 static void gluTexImage3D( GLenum target
, GLint level
,
6638 GLenum internalFormat
,
6639 GLsizei width
, GLsizei height
,
6640 GLsizei depth
, GLint border
,
6641 GLenum format
, GLenum type
,
6642 const GLvoid
*pixels
)
6646 pTexImage3D
= (TexImage3Dproc
) wglGetProcAddress("glTexImage3D");
6648 pTexImage3D
= (TexImage3Dproc
) wglGetProcAddress("glTexImage3DEXT");
6650 void *libHandle
= dlopen("libgl.so", RTLD_LAZY
);
6651 pTexImage3D
= TexImage3Dproc
) dlsym(libHandle
, "glTexImage3D" );
6653 pTexImage3D
= (TexImage3Dproc
) dlsym(libHandle
,"glTexImage3DEXT");
6658 /* Now call glTexImage3D */
6660 pTexImage3D(target
, level
, internalFormat
, width
, height
,
6661 depth
, border
, format
, type
, pixels
);
6666 /* Only bind to a GL 1.2 implementation: */
6667 #define gluTexImage3D glTexImage3D
6671 static GLint
imageSize3D(GLint width
, GLint height
, GLint depth
,
6672 GLenum format
, GLenum type
)
6674 int components
= elements_per_group(format
,type
);
6675 int bytes_per_row
= bytes_per_element(type
) * width
;
6677 assert(width
> 0 && height
> 0 && depth
> 0);
6678 assert(type
!= GL_BITMAP
);
6680 return bytes_per_row
* height
* depth
* components
;
6681 } /* imageSize3D() */
6683 static void fillImage3D(const PixelStorageModes
*psm
,
6684 GLint width
, GLint height
, GLint depth
, GLenum format
,
6685 GLenum type
, GLboolean indexFormat
,
6686 const void *userImage
, GLushort
*newImage
)
6695 int elementsPerLine
;
6698 const GLubyte
*start
, *rowStart
, *iter
;
6702 myswapBytes
= psm
->unpack_swap_bytes
;
6703 components
= elements_per_group(format
,type
);
6704 if (psm
->unpack_row_length
> 0) {
6705 groupsPerLine
= psm
->unpack_row_length
;
6708 groupsPerLine
= width
;
6710 elementSize
= bytes_per_element(type
);
6711 groupSize
= elementSize
* components
;
6712 if (elementSize
== 1) myswapBytes
= 0;
6715 if (psm
->unpack_image_height
> 0) {
6716 rowsPerImage
= psm
->unpack_image_height
;
6719 rowsPerImage
= height
;
6723 rowSize
= groupsPerLine
* groupSize
;
6724 padding
= rowSize
% psm
->unpack_alignment
;
6726 rowSize
+= psm
->unpack_alignment
- padding
;
6729 imageSize
= rowsPerImage
* rowSize
; /* 3dstuff */
6731 start
= (const GLubyte
*)userImage
+ psm
->unpack_skip_rows
* rowSize
+
6732 psm
->unpack_skip_pixels
* groupSize
+
6734 psm
->unpack_skip_images
* imageSize
;
6735 elementsPerLine
= width
* components
;
6738 for (dd
= 0; dd
< depth
; dd
++) {
6741 for (hh
= 0; hh
< height
; hh
++) {
6744 for (ww
= 0; ww
< elementsPerLine
; ww
++) {
6746 float extractComponents
[4];
6749 case GL_UNSIGNED_BYTE
:
6753 *iter2
++ = (*iter
) * 257;
6758 *iter2
++ = *((const GLbyte
*) iter
);
6761 *iter2
++ = (*((const GLbyte
*) iter
)) * 516;
6764 case GL_UNSIGNED_BYTE_3_3_2
:
6765 extract332(0,iter
,extractComponents
);
6766 for (k
= 0; k
< 3; k
++) {
6767 *iter2
++ = (GLushort
)(extractComponents
[k
]*65535);
6770 case GL_UNSIGNED_BYTE_2_3_3_REV
:
6771 extract233rev(0,iter
,extractComponents
);
6772 for (k
= 0; k
< 3; k
++) {
6773 *iter2
++ = (GLushort
)(extractComponents
[k
]*65535);
6776 case GL_UNSIGNED_SHORT_5_6_5
:
6777 extract565(myswapBytes
,iter
,extractComponents
);
6778 for (k
= 0; k
< 3; k
++) {
6779 *iter2
++ = (GLushort
)(extractComponents
[k
]*65535);
6782 case GL_UNSIGNED_SHORT_5_6_5_REV
:
6783 extract565rev(myswapBytes
,iter
,extractComponents
);
6784 for (k
= 0; k
< 3; k
++) {
6785 *iter2
++ = (GLushort
)(extractComponents
[k
]*65535);
6788 case GL_UNSIGNED_SHORT_4_4_4_4
:
6789 extract4444(myswapBytes
,iter
,extractComponents
);
6790 for (k
= 0; k
< 4; k
++) {
6791 *iter2
++ = (GLushort
)(extractComponents
[k
]*65535);
6794 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
6795 extract4444rev(myswapBytes
,iter
,extractComponents
);
6796 for (k
= 0; k
< 4; k
++) {
6797 *iter2
++ = (GLushort
)(extractComponents
[k
]*65535);
6800 case GL_UNSIGNED_SHORT_5_5_5_1
:
6801 extract5551(myswapBytes
,iter
,extractComponents
);
6802 for (k
= 0; k
< 4; k
++) {
6803 *iter2
++ = (GLushort
)(extractComponents
[k
]*65535);
6806 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
6807 extract1555rev(myswapBytes
,iter
,extractComponents
);
6808 for (k
= 0; k
< 4; k
++) {
6809 *iter2
++ = (GLushort
)(extractComponents
[k
]*65535);
6812 case GL_UNSIGNED_SHORT
:
6815 widget
.ub
[0] = iter
[1];
6816 widget
.ub
[1] = iter
[0];
6818 widget
.ub
[0] = iter
[0];
6819 widget
.ub
[1] = iter
[1];
6821 if (type
== GL_SHORT
) {
6823 *iter2
++ = widget
.s
[0];
6826 *iter2
++ = widget
.s
[0]*2;
6829 *iter2
++ = widget
.us
[0];
6832 case GL_UNSIGNED_INT_8_8_8_8
:
6833 extract8888(myswapBytes
,iter
,extractComponents
);
6834 for (k
= 0; k
< 4; k
++) {
6835 *iter2
++ = (GLushort
)(extractComponents
[k
]*65535);
6838 case GL_UNSIGNED_INT_8_8_8_8_REV
:
6839 extract8888rev(myswapBytes
,iter
,extractComponents
);
6840 for (k
= 0; k
< 4; k
++) {
6841 *iter2
++ = (GLushort
)(extractComponents
[k
]*65535);
6844 case GL_UNSIGNED_INT_10_10_10_2
:
6845 extract1010102(myswapBytes
,iter
,extractComponents
);
6846 for (k
= 0; k
< 4; k
++) {
6847 *iter2
++ = (GLushort
)(extractComponents
[k
]*65535);
6850 case GL_UNSIGNED_INT_2_10_10_10_REV
:
6851 extract2101010rev(myswapBytes
,iter
,extractComponents
);
6852 for (k
= 0; k
< 4; k
++) {
6853 *iter2
++ = (GLushort
)(extractComponents
[k
]*65535);
6857 case GL_UNSIGNED_INT
:
6860 widget
.ub
[0] = iter
[3];
6861 widget
.ub
[1] = iter
[2];
6862 widget
.ub
[2] = iter
[1];
6863 widget
.ub
[3] = iter
[0];
6865 widget
.ub
[0] = iter
[0];
6866 widget
.ub
[1] = iter
[1];
6867 widget
.ub
[2] = iter
[2];
6868 widget
.ub
[3] = iter
[3];
6870 if (type
== GL_FLOAT
) {
6872 *iter2
++ = widget
.f
;
6874 *iter2
++ = 65535 * widget
.f
;
6876 } else if (type
== GL_UNSIGNED_INT
) {
6878 *iter2
++ = widget
.ui
;
6880 *iter2
++ = widget
.ui
>> 16;
6884 *iter2
++ = widget
.i
;
6886 *iter2
++ = widget
.i
>> 15;
6898 iter
= rowStart
; /* for assertion purposes */
6904 /* iterators should be one byte past end */
6905 if (!isTypePackedPixel(type
)) {
6906 assert(iter2
== &newImage
[width
*height
*depth
*components
]);
6909 assert(iter2
== &newImage
[width
*height
*depth
*
6910 elements_per_group(format
,0)]);
6912 assert( iter
== &((const GLubyte
*)userImage
)[rowSize
*height
*depth
+
6913 psm
->unpack_skip_rows
* rowSize
+
6914 psm
->unpack_skip_pixels
* groupSize
+
6916 psm
->unpack_skip_images
* imageSize
] );
6917 } /* fillImage3D () */
6919 static void scaleInternal3D(GLint components
,
6920 GLint widthIn
, GLint heightIn
, GLint depthIn
,
6921 const GLushort
*dataIn
,
6922 GLint widthOut
, GLint heightOut
, GLint depthOut
,
6925 float x
, lowx
, highx
, convx
, halfconvx
;
6926 float y
, lowy
, highy
, convy
, halfconvy
;
6927 float z
, lowz
, highz
, convz
, halfconvz
;
6928 float xpercent
,ypercent
,zpercent
;
6930 /* Max components in a format is 4, so... */
6933 int i
,j
,d
,k
,zint
,yint
,xint
,xindex
,yindex
,zindex
;
6936 convz
= (float) depthIn
/depthOut
;
6937 convy
= (float) heightIn
/heightOut
;
6938 convx
= (float) widthIn
/widthOut
;
6939 halfconvx
= convx
/2;
6940 halfconvy
= convy
/2;
6941 halfconvz
= convz
/2;
6942 for (d
= 0; d
< depthOut
; d
++) {
6943 z
= convz
* (d
+0.5);
6944 if (depthIn
> depthOut
) {
6945 highz
= z
+ halfconvz
;
6946 lowz
= z
- halfconvz
;
6951 for (i
= 0; i
< heightOut
; i
++) {
6952 y
= convy
* (i
+0.5);
6953 if (heightIn
> heightOut
) {
6954 highy
= y
+ halfconvy
;
6955 lowy
= y
- halfconvy
;
6960 for (j
= 0; j
< widthOut
; j
++) {
6961 x
= convx
* (j
+0.5);
6962 if (widthIn
> widthOut
) {
6963 highx
= x
+ halfconvx
;
6964 lowx
= x
- halfconvx
;
6971 ** Ok, now apply box filter to box that goes from (lowx, lowy,
6972 ** lowz) to (highx, highy, highz) on input data into this pixel
6975 totals
[0] = totals
[1] = totals
[2] = totals
[3] = 0.0;
6981 zindex
= (zint
+ depthIn
) % depthIn
;
6982 if (highz
< zint
+1) {
6983 zpercent
= highz
- z
;
6985 zpercent
= zint
+1 - z
;
6991 yindex
= (yint
+ heightIn
) % heightIn
;
6992 if (highy
< yint
+1) {
6993 ypercent
= highy
- y
;
6995 ypercent
= yint
+1 - y
;
7002 xindex
= (xint
+ widthIn
) % widthIn
;
7003 if (highx
< xint
+1) {
7004 xpercent
= highx
- x
;
7006 xpercent
= xint
+1 - x
;
7009 percent
= xpercent
* ypercent
* zpercent
;
7012 temp
= (xindex
+ (yindex
*widthIn
) +
7013 (zindex
*widthIn
*heightIn
)) * components
;
7014 for (k
= 0; k
< components
; k
++) {
7015 assert(0 <= (temp
+k
) &&
7017 (widthIn
*heightIn
*depthIn
*components
));
7018 totals
[k
] += dataIn
[temp
+ k
] * percent
;
7033 temp
= (j
+ (i
* widthOut
) +
7034 (d
*widthOut
*heightOut
)) * components
;
7035 for (k
= 0; k
< components
; k
++) {
7036 /* totals[] should be rounded in the case of enlarging an
7037 * RGB ramp when the type is 332 or 4444
7039 assert(0 <= (temp
+k
) &&
7040 (temp
+k
) < (widthOut
*heightOut
*depthOut
*components
));
7041 dataOut
[temp
+ k
] = (totals
[k
]+0.5)/volume
;
7046 } /* scaleInternal3D() */
7048 static void emptyImage3D(const PixelStorageModes
*psm
,
7049 GLint width
, GLint height
, GLint depth
,
7050 GLenum format
, GLenum type
, GLboolean indexFormat
,
7051 const GLushort
*oldImage
, void *userImage
)
7060 GLubyte
*start
, *rowStart
, *iter
;
7061 int elementsPerLine
;
7062 const GLushort
*iter2
;
7067 myswapBytes
= psm
->pack_swap_bytes
;
7068 components
= elements_per_group(format
,type
);
7069 if (psm
->pack_row_length
> 0) {
7070 groupsPerLine
= psm
->pack_row_length
;
7073 groupsPerLine
= width
;
7076 elementSize
= bytes_per_element(type
);
7077 groupSize
= elementSize
* components
;
7078 if (elementSize
== 1) myswapBytes
= 0;
7081 if (psm
->pack_image_height
> 0) {
7082 rowsPerImage
= psm
->pack_image_height
;
7085 rowsPerImage
= height
;
7090 rowSize
= groupsPerLine
* groupSize
;
7091 padding
= rowSize
% psm
->pack_alignment
;
7093 rowSize
+= psm
->pack_alignment
- padding
;
7096 imageSize
= rowsPerImage
* rowSize
; /* 3dstuff */
7098 start
= (GLubyte
*)userImage
+ psm
->pack_skip_rows
* rowSize
+
7099 psm
->pack_skip_pixels
* groupSize
+
7101 psm
->pack_skip_images
* imageSize
;
7102 elementsPerLine
= width
* components
;
7105 for (dd
= 0; dd
< depth
; dd
++) {
7108 for (ii
= 0; ii
< height
; ii
++) {
7111 for (jj
= 0; jj
< elementsPerLine
; jj
++) {
7113 float shoveComponents
[4];
7116 case GL_UNSIGNED_BYTE
:
7120 *iter
= *iter2
++ >> 8;
7125 *((GLbyte
*) iter
) = *iter2
++;
7127 *((GLbyte
*) iter
) = *iter2
++ >> 9;
7130 case GL_UNSIGNED_BYTE_3_3_2
:
7131 for (k
= 0; k
< 3; k
++) {
7132 shoveComponents
[k
]= *iter2
++ / 65535.0;
7134 shove332(shoveComponents
,0,(void *)iter
);
7136 case GL_UNSIGNED_BYTE_2_3_3_REV
:
7137 for (k
= 0; k
< 3; k
++) {
7138 shoveComponents
[k
]= *iter2
++ / 65535.0;
7140 shove233rev(shoveComponents
,0,(void *)iter
);
7142 case GL_UNSIGNED_SHORT_5_6_5
:
7143 for (k
= 0; k
< 3; k
++) {
7144 shoveComponents
[k
]= *iter2
++ / 65535.0;
7146 shove565(shoveComponents
,0,(void *)&widget
.us
[0]);
7148 iter
[0] = widget
.ub
[1];
7149 iter
[1] = widget
.ub
[0];
7152 *(GLushort
*)iter
= widget
.us
[0];
7155 case GL_UNSIGNED_SHORT_5_6_5_REV
:
7156 for (k
= 0; k
< 3; k
++) {
7157 shoveComponents
[k
]= *iter2
++ / 65535.0;
7159 shove565rev(shoveComponents
,0,(void *)&widget
.us
[0]);
7161 iter
[0] = widget
.ub
[1];
7162 iter
[1] = widget
.ub
[0];
7165 *(GLushort
*)iter
= widget
.us
[0];
7168 case GL_UNSIGNED_SHORT_4_4_4_4
:
7169 for (k
= 0; k
< 4; k
++) {
7170 shoveComponents
[k
]= *iter2
++ / 65535.0;
7172 shove4444(shoveComponents
,0,(void *)&widget
.us
[0]);
7174 iter
[0] = widget
.ub
[1];
7175 iter
[1] = widget
.ub
[0];
7177 *(GLushort
*)iter
= widget
.us
[0];
7180 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
7181 for (k
= 0; k
< 4; k
++) {
7182 shoveComponents
[k
]= *iter2
++ / 65535.0;
7184 shove4444rev(shoveComponents
,0,(void *)&widget
.us
[0]);
7186 iter
[0] = widget
.ub
[1];
7187 iter
[1] = widget
.ub
[0];
7189 *(GLushort
*)iter
= widget
.us
[0];
7192 case GL_UNSIGNED_SHORT_5_5_5_1
:
7193 for (k
= 0; k
< 4; k
++) {
7194 shoveComponents
[k
]= *iter2
++ / 65535.0;
7196 shove5551(shoveComponents
,0,(void *)&widget
.us
[0]);
7198 iter
[0] = widget
.ub
[1];
7199 iter
[1] = widget
.ub
[0];
7201 *(GLushort
*)iter
= widget
.us
[0];
7204 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
7205 for (k
= 0; k
< 4; k
++) {
7206 shoveComponents
[k
]= *iter2
++ / 65535.0;
7208 shove1555rev(shoveComponents
,0,(void *)&widget
.us
[0]);
7210 iter
[0] = widget
.ub
[1];
7211 iter
[1] = widget
.ub
[0];
7213 *(GLushort
*)iter
= widget
.us
[0];
7216 case GL_UNSIGNED_SHORT
:
7218 if (type
== GL_SHORT
) {
7220 widget
.s
[0] = *iter2
++;
7222 widget
.s
[0] = *iter2
++ >> 1;
7225 widget
.us
[0] = *iter2
++;
7228 iter
[0] = widget
.ub
[1];
7229 iter
[1] = widget
.ub
[0];
7231 iter
[0] = widget
.ub
[0];
7232 iter
[1] = widget
.ub
[1];
7235 case GL_UNSIGNED_INT_8_8_8_8
:
7236 for (k
= 0; k
< 4; k
++) {
7237 shoveComponents
[k
]= *iter2
++ / 65535.0;
7239 shove8888(shoveComponents
,0,(void *)&widget
.ui
);
7241 iter
[3] = widget
.ub
[0];
7242 iter
[2] = widget
.ub
[1];
7243 iter
[1] = widget
.ub
[2];
7244 iter
[0] = widget
.ub
[3];
7246 *(GLuint
*)iter
= widget
.ui
;
7249 case GL_UNSIGNED_INT_8_8_8_8_REV
:
7250 for (k
= 0; k
< 4; k
++) {
7251 shoveComponents
[k
]= *iter2
++ / 65535.0;
7253 shove8888rev(shoveComponents
,0,(void *)&widget
.ui
);
7255 iter
[3] = widget
.ub
[0];
7256 iter
[2] = widget
.ub
[1];
7257 iter
[1] = widget
.ub
[2];
7258 iter
[0] = widget
.ub
[3];
7260 *(GLuint
*)iter
= widget
.ui
;
7263 case GL_UNSIGNED_INT_10_10_10_2
:
7264 for (k
= 0; k
< 4; k
++) {
7265 shoveComponents
[k
]= *iter2
++ / 65535.0;
7267 shove1010102(shoveComponents
,0,(void *)&widget
.ui
);
7269 iter
[3] = widget
.ub
[0];
7270 iter
[2] = widget
.ub
[1];
7271 iter
[1] = widget
.ub
[2];
7272 iter
[0] = widget
.ub
[3];
7274 *(GLuint
*)iter
= widget
.ui
;
7277 case GL_UNSIGNED_INT_2_10_10_10_REV
:
7278 for (k
= 0; k
< 4; k
++) {
7279 shoveComponents
[k
]= *iter2
++ / 65535.0;
7281 shove2101010rev(shoveComponents
,0,(void *)&widget
.ui
);
7283 iter
[3] = widget
.ub
[0];
7284 iter
[2] = widget
.ub
[1];
7285 iter
[1] = widget
.ub
[2];
7286 iter
[0] = widget
.ub
[3];
7288 *(GLuint
*)iter
= widget
.ui
;
7292 case GL_UNSIGNED_INT
:
7294 if (type
== GL_FLOAT
) {
7296 widget
.f
= *iter2
++;
7298 widget
.f
= *iter2
++ / (float) 65535.0;
7300 } else if (type
== GL_UNSIGNED_INT
) {
7302 widget
.ui
= *iter2
++;
7304 widget
.ui
= (unsigned int) *iter2
++ * 65537;
7308 widget
.i
= *iter2
++;
7310 widget
.i
= ((unsigned int) *iter2
++ * 65537)/2;
7314 iter
[3] = widget
.ub
[0];
7315 iter
[2] = widget
.ub
[1];
7316 iter
[1] = widget
.ub
[2];
7317 iter
[0] = widget
.ub
[3];
7319 iter
[0] = widget
.ub
[0];
7320 iter
[1] = widget
.ub
[1];
7321 iter
[2] = widget
.ub
[2];
7322 iter
[3] = widget
.ub
[3];
7338 /* iterators should be one byte past end */
7339 if (!isTypePackedPixel(type
)) {
7340 assert(iter2
== &oldImage
[width
*height
*depth
*components
]);
7343 assert(iter2
== &oldImage
[width
*height
*depth
*
7344 elements_per_group(format
,0)]);
7346 assert( iter
== &((GLubyte
*)userImage
)[rowSize
*height
*depth
+
7347 psm
->unpack_skip_rows
* rowSize
+
7348 psm
->unpack_skip_pixels
* groupSize
+
7350 psm
->unpack_skip_images
* imageSize
] );
7351 } /* emptyImage3D() */
7354 int gluScaleImage3D(GLenum format
,
7355 GLint widthIn
, GLint heightIn
, GLint depthIn
,
7356 GLenum typeIn
, const void *dataIn
,
7357 GLint widthOut
, GLint heightOut
, GLint depthOut
,
7358 GLenum typeOut
, void *dataOut
)
7361 GLushort
*beforeImage
, *afterImage
;
7362 PixelStorageModes psm
;
7364 if (widthIn
== 0 || heightIn
== 0 || depthIn
== 0 ||
7365 widthOut
== 0 || heightOut
== 0 || depthOut
== 0) {
7369 if (widthIn
< 0 || heightIn
< 0 || depthIn
< 0 ||
7370 widthOut
< 0 || heightOut
< 0 || depthOut
< 0) {
7371 return GLU_INVALID_VALUE
;
7374 if (!legalFormat(format
) || !legalType(typeIn
) || !legalType(typeOut
) ||
7375 typeIn
== GL_BITMAP
|| typeOut
== GL_BITMAP
) {
7376 return GLU_INVALID_ENUM
;
7378 if (!isLegalFormatForPackedPixelType(format
, typeIn
)) {
7379 return GLU_INVALID_OPERATION
;
7381 if (!isLegalFormatForPackedPixelType(format
, typeOut
)) {
7382 return GLU_INVALID_OPERATION
;
7385 beforeImage
= malloc(imageSize3D(widthIn
, heightIn
, depthIn
, format
,
7386 GL_UNSIGNED_SHORT
));
7387 afterImage
= malloc(imageSize3D(widthOut
, heightOut
, depthOut
, format
,
7388 GL_UNSIGNED_SHORT
));
7389 if (beforeImage
== NULL
|| afterImage
== NULL
) {
7390 return GLU_OUT_OF_MEMORY
;
7392 retrieveStoreModes3D(&psm
);
7394 fillImage3D(&psm
,widthIn
,heightIn
,depthIn
,format
,typeIn
, is_index(format
),
7395 dataIn
, beforeImage
);
7396 components
= elements_per_group(format
,0);
7397 scaleInternal3D(components
,widthIn
,heightIn
,depthIn
,beforeImage
,
7398 widthOut
,heightOut
,depthOut
,afterImage
);
7399 emptyImage3D(&psm
,widthOut
,heightOut
,depthOut
,format
,typeOut
,
7400 is_index(format
),afterImage
, dataOut
);
7401 free((void *) beforeImage
);
7402 free((void *) afterImage
);
7405 } /* gluScaleImage3D() */
7408 static void closestFit3D(GLenum target
, GLint width
, GLint height
, GLint depth
,
7409 GLint internalFormat
, GLenum format
, GLenum type
,
7410 GLint
*newWidth
, GLint
*newHeight
, GLint
*newDepth
)
7412 GLint widthPowerOf2
= nearestPower(width
);
7413 GLint heightPowerOf2
= nearestPower(height
);
7414 GLint depthPowerOf2
= nearestPower(depth
);
7418 /* compute level 1 width & height & depth, clamping each at 1 */
7419 GLint widthAtLevelOne
= (widthPowerOf2
> 1) ?
7420 widthPowerOf2
>> 1 :
7422 GLint heightAtLevelOne
= (heightPowerOf2
> 1) ?
7423 heightPowerOf2
>> 1 :
7425 GLint depthAtLevelOne
= (depthPowerOf2
> 1) ?
7426 depthPowerOf2
>> 1 :
7428 GLenum proxyTarget
= GL_PROXY_TEXTURE_3D
;
7429 assert(widthAtLevelOne
> 0);
7430 assert(heightAtLevelOne
> 0);
7431 assert(depthAtLevelOne
> 0);
7433 /* does width x height x depth at level 1 & all their mipmaps fit? */
7434 assert(target
== GL_TEXTURE_3D
|| target
== GL_PROXY_TEXTURE_3D
);
7435 gluTexImage3D(proxyTarget
, 1, /* must be non-zero */
7437 widthAtLevelOne
,heightAtLevelOne
,depthAtLevelOne
,
7438 0,format
,type
,NULL
);
7439 glGetTexLevelParameteriv(proxyTarget
, 1,GL_TEXTURE_WIDTH
,&proxyWidth
);
7440 /* does it fit??? */
7441 if (proxyWidth
== 0) { /* nope, so try again with these sizes */
7442 if (widthPowerOf2
== 1 && heightPowerOf2
== 1 &&
7443 depthPowerOf2
== 1) {
7444 *newWidth
= *newHeight
= *newDepth
= 1; /* must fit 1x1x1 texture */
7447 widthPowerOf2
= widthAtLevelOne
;
7448 heightPowerOf2
= heightAtLevelOne
;
7449 depthPowerOf2
= depthAtLevelOne
;
7451 /* else it does fit */
7452 } while (proxyWidth
== 0);
7453 /* loop must terminate! */
7455 /* return the width & height at level 0 that fits */
7456 *newWidth
= widthPowerOf2
;
7457 *newHeight
= heightPowerOf2
;
7458 *newDepth
= depthPowerOf2
;
7459 /*printf("Proxy Textures\n");*/
7460 } /* closestFit3D() */
7462 static void halveImagePackedPixelSlice(int components
,
7463 void (*extractPackedPixel
)
7464 (int, const void *,GLfloat
[]),
7465 void (*shovePackedPixel
)
7466 (const GLfloat
[],int, void *),
7467 GLint width
, GLint height
, GLint depth
,
7468 const void *dataIn
, void *dataOut
,
7469 GLint pixelSizeInBytes
,
7470 GLint rowSizeInBytes
,
7471 GLint imageSizeInBytes
,
7475 int halfWidth
= width
/ 2;
7476 int halfHeight
= height
/ 2;
7477 int halfDepth
= depth
/ 2;
7478 const char *src
= (const char *)dataIn
;
7481 assert((width
== 1 || height
== 1) && depth
>= 2);
7483 if (width
== height
) { /* a 1-pixel column viewed from top */
7484 assert(width
== 1 && height
== 1);
7487 for (ii
= 0; ii
< halfDepth
; ii
++) {
7489 float extractTotals
[BOX2
][4];
7492 (*extractPackedPixel
)(isSwap
,src
,&extractTotals
[0][0]);
7493 (*extractPackedPixel
)(isSwap
,(src
+imageSizeInBytes
),
7494 &extractTotals
[1][0]);
7495 for (cc
= 0; cc
< components
; cc
++) {
7498 /* average 2 pixels since only a column */
7500 /* totals[RED]= extractTotals[0][RED]+extractTotals[1][RED];
7501 * totals[RED]/= 2.0;
7503 for (kk
= 0; kk
< BOX2
; kk
++) {
7504 totals
[cc
]+= extractTotals
[kk
][cc
];
7506 totals
[cc
]/= (float)BOX2
;
7509 (*shovePackedPixel
)(totals
,outIndex
,dataOut
);
7511 /* skip over to next group of 2 */
7512 src
+= imageSizeInBytes
+ imageSizeInBytes
;
7515 else if (height
== 1) { /* horizontal slice viewed from top */
7518 for (ii
= 0; ii
< halfDepth
; ii
++) {
7519 for (jj
= 0; jj
< halfWidth
; jj
++) {
7521 float extractTotals
[BOX4
][4];
7524 (*extractPackedPixel
)(isSwap
,src
,
7525 &extractTotals
[0][0]);
7526 (*extractPackedPixel
)(isSwap
,(src
+pixelSizeInBytes
),
7527 &extractTotals
[1][0]);
7528 (*extractPackedPixel
)(isSwap
,(src
+imageSizeInBytes
),
7529 &extractTotals
[2][0]);
7530 (*extractPackedPixel
)(isSwap
,
7531 (src
+imageSizeInBytes
+pixelSizeInBytes
),
7532 &extractTotals
[3][0]);
7533 for (cc
= 0; cc
< components
; cc
++) {
7536 /* grab 4 pixels to average */
7538 /* totals[RED]= extractTotals[0][RED]+extractTotals[1][RED]+
7539 * extractTotals[2][RED]+extractTotals[3][RED];
7540 * totals[RED]/= 4.0;
7542 for (kk
= 0; kk
< BOX4
; kk
++) {
7543 totals
[cc
]+= extractTotals
[kk
][cc
];
7545 totals
[cc
]/= (float)BOX4
;
7547 (*shovePackedPixel
)(totals
,outIndex
,dataOut
);
7550 /* skip over to next horizontal square of 4 */
7551 src
+= imageSizeInBytes
+ imageSizeInBytes
;
7557 else if (width
== 1) { /* vertical slice viewed from top */
7558 assert(height
!= 1);
7560 for (ii
= 0; ii
< halfDepth
; ii
++) {
7561 for (jj
= 0; jj
< halfHeight
; jj
++) {
7563 float extractTotals
[BOX4
][4];
7566 (*extractPackedPixel
)(isSwap
,src
,
7567 &extractTotals
[0][0]);
7568 (*extractPackedPixel
)(isSwap
,(src
+rowSizeInBytes
),
7569 &extractTotals
[1][0]);
7570 (*extractPackedPixel
)(isSwap
,(src
+imageSizeInBytes
),
7571 &extractTotals
[2][0]);
7572 (*extractPackedPixel
)(isSwap
,
7573 (src
+imageSizeInBytes
+rowSizeInBytes
),
7574 &extractTotals
[3][0]);
7575 for (cc
= 0; cc
< components
; cc
++) {
7578 /* grab 4 pixels to average */
7580 /* totals[RED]= extractTotals[0][RED]+extractTotals[1][RED]+
7581 * extractTotals[2][RED]+extractTotals[3][RED];
7582 * totals[RED]/= 4.0;
7584 for (kk
= 0; kk
< BOX4
; kk
++) {
7585 totals
[cc
]+= extractTotals
[kk
][cc
];
7587 totals
[cc
]/= (float)BOX4
;
7589 (*shovePackedPixel
)(totals
,outIndex
,dataOut
);
7593 /* skip over to next vertical square of 4 */
7594 src
+= imageSizeInBytes
+ imageSizeInBytes
;
7600 } /* halveImagePackedPixelSlice() */
7602 static void halveImagePackedPixel3D(int components
,
7603 void (*extractPackedPixel
)
7604 (int, const void *,GLfloat
[]),
7605 void (*shovePackedPixel
)
7606 (const GLfloat
[],int, void *),
7607 GLint width
, GLint height
, GLint depth
,
7608 const void *dataIn
, void *dataOut
,
7609 GLint pixelSizeInBytes
,
7610 GLint rowSizeInBytes
,
7611 GLint imageSizeInBytes
,
7615 assert(1 <= width
&& 1 <= height
);
7617 halveImagePackedPixel(components
,extractPackedPixel
,shovePackedPixel
,
7618 width
,height
,dataIn
,dataOut
,pixelSizeInBytes
,
7619 rowSizeInBytes
,isSwap
);
7622 /* a horizontal or vertical slice viewed from top */
7623 else if (width
== 1 || height
== 1) {
7626 halveImagePackedPixelSlice(components
,
7627 extractPackedPixel
,shovePackedPixel
,
7628 width
, height
, depth
, dataIn
, dataOut
,
7629 pixelSizeInBytes
, rowSizeInBytes
,
7630 imageSizeInBytes
, isSwap
);
7636 int halfWidth
= width
/ 2;
7637 int halfHeight
= height
/ 2;
7638 int halfDepth
= depth
/ 2;
7639 const char *src
= (const char *) dataIn
;
7640 int padBytes
= rowSizeInBytes
- (width
*pixelSizeInBytes
);
7643 for (dd
= 0; dd
< halfDepth
; dd
++) {
7644 for (ii
= 0; ii
< halfHeight
; ii
++) {
7645 for (jj
= 0; jj
< halfWidth
; jj
++) {
7647 float totals
[4]; /* 4 is maximum components */
7648 float extractTotals
[BOX8
][4]; /* 4 is maximum components */
7651 (*extractPackedPixel
)(isSwap
,src
,
7652 &extractTotals
[0][0]);
7653 (*extractPackedPixel
)(isSwap
,(src
+pixelSizeInBytes
),
7654 &extractTotals
[1][0]);
7655 (*extractPackedPixel
)(isSwap
,(src
+rowSizeInBytes
),
7656 &extractTotals
[2][0]);
7657 (*extractPackedPixel
)(isSwap
,
7658 (src
+rowSizeInBytes
+pixelSizeInBytes
),
7659 &extractTotals
[3][0]);
7661 (*extractPackedPixel
)(isSwap
,(src
+imageSizeInBytes
),
7662 &extractTotals
[4][0]);
7663 (*extractPackedPixel
)(isSwap
,(src
+pixelSizeInBytes
+imageSizeInBytes
),
7664 &extractTotals
[5][0]);
7665 (*extractPackedPixel
)(isSwap
,(src
+rowSizeInBytes
+imageSizeInBytes
),
7666 &extractTotals
[6][0]);
7667 (*extractPackedPixel
)(isSwap
,
7668 (src
+rowSizeInBytes
+pixelSizeInBytes
+imageSizeInBytes
),
7669 &extractTotals
[7][0]);
7670 for (cc
= 0; cc
< components
; cc
++) {
7673 /* grab 8 pixels to average */
7675 /* totals[RED]= extractTotals[0][RED]+extractTotals[1][RED]+
7676 * extractTotals[2][RED]+extractTotals[3][RED]+
7677 * extractTotals[4][RED]+extractTotals[5][RED]+
7678 * extractTotals[6][RED]+extractTotals[7][RED];
7679 * totals[RED]/= 8.0;
7681 for (kk
= 0; kk
< BOX8
; kk
++) {
7682 totals
[cc
]+= extractTotals
[kk
][cc
];
7684 totals
[cc
]/= (float)BOX8
;
7686 (*shovePackedPixel
)(totals
,outIndex
,dataOut
);
7689 /* skip over to next square of 4 */
7690 src
+= pixelSizeInBytes
+ pixelSizeInBytes
;
7692 /* skip past pad bytes, if any, to get to next row */
7695 /* src is at beginning of a row here, but it's the second row of
7696 * the square block of 4 pixels that we just worked on so we
7697 * need to go one more row.
7705 src
+= rowSizeInBytes
;
7708 src
+= imageSizeInBytes
;
7711 /* both pointers must reach one byte after the end */
7712 assert(src
== &((const char *)dataIn
)[rowSizeInBytes
*height
*depth
]);
7713 assert(outIndex
== halfWidth
* halfHeight
* halfDepth
);
7716 } /* halveImagePackedPixel3D() */
7718 static int gluBuild3DMipmapLevelsCore(GLenum target
, GLint internalFormat
,
7722 GLsizei widthPowerOf2
,
7723 GLsizei heightPowerOf2
,
7724 GLsizei depthPowerOf2
,
7725 GLenum format
, GLenum type
,
7727 GLint baseLevel
,GLint maxLevel
,
7730 GLint newWidth
, newHeight
, newDepth
;
7731 GLint level
, levels
;
7732 const void *usersImage
;
7733 void *srcImage
, *dstImage
;
7734 __GLU_INIT_SWAP_IMAGE
;
7738 GLint myswapBytes
, groupsPerLine
, elementSize
, groupSize
;
7739 GLint rowsPerImage
, imageSize
;
7740 GLint rowSize
, padding
;
7741 PixelStorageModes psm
;
7743 assert(checkMipmapArgs(internalFormat
,format
,type
) == 0);
7744 assert(width
>= 1 && height
>= 1 && depth
>= 1);
7745 assert(type
!= GL_BITMAP
);
7747 srcImage
= dstImage
= NULL
;
7749 newWidth
= widthPowerOf2
;
7750 newHeight
= heightPowerOf2
;
7751 newDepth
= depthPowerOf2
;
7752 levels
= computeLog(newWidth
);
7753 level
= computeLog(newHeight
);
7754 if (level
> levels
) levels
=level
;
7755 level
= computeLog(newDepth
);
7756 if (level
> levels
) levels
=level
;
7760 retrieveStoreModes3D(&psm
);
7761 myswapBytes
= psm
.unpack_swap_bytes
;
7762 cmpts
= elements_per_group(format
,type
);
7763 if (psm
.unpack_row_length
> 0) {
7764 groupsPerLine
= psm
.unpack_row_length
;
7766 groupsPerLine
= width
;
7769 elementSize
= bytes_per_element(type
);
7770 groupSize
= elementSize
* cmpts
;
7771 if (elementSize
== 1) myswapBytes
= 0;
7774 if (psm
.unpack_image_height
> 0) {
7775 rowsPerImage
= psm
.unpack_image_height
;
7778 rowsPerImage
= height
;
7782 rowSize
= groupsPerLine
* groupSize
;
7783 padding
= (rowSize
% psm
.unpack_alignment
);
7785 rowSize
+= psm
.unpack_alignment
- padding
;
7788 imageSize
= rowsPerImage
* rowSize
; /* 3dstuff */
7790 usersImage
= (const GLubyte
*)data
+ psm
.unpack_skip_rows
* rowSize
+
7791 psm
.unpack_skip_pixels
* groupSize
+
7793 psm
.unpack_skip_images
* imageSize
;
7795 glPixelStorei(GL_UNPACK_SKIP_ROWS
, 0);
7796 glPixelStorei(GL_UNPACK_SKIP_PIXELS
, 0);
7797 glPixelStorei(GL_UNPACK_ROW_LENGTH
, 0);
7798 glPixelStorei(GL_UNPACK_SKIP_IMAGES
, 0);
7799 glPixelStorei(GL_UNPACK_IMAGE_HEIGHT
, 0);
7803 if (width
== newWidth
&& height
== newHeight
&& depth
== newDepth
) {
7804 /* Use usersImage for level userLevel */
7805 if (baseLevel
<= level
&& level
<= maxLevel
) {
7806 gluTexImage3D(target
, level
, internalFormat
, width
,
7807 height
, depth
, 0, format
, type
,
7810 if(levels
== 0) { /* we're done. clean up and return */
7811 glPixelStorei(GL_UNPACK_ALIGNMENT
, psm
.unpack_alignment
);
7812 glPixelStorei(GL_UNPACK_SKIP_ROWS
, psm
.unpack_skip_rows
);
7813 glPixelStorei(GL_UNPACK_SKIP_PIXELS
, psm
.unpack_skip_pixels
);
7814 glPixelStorei(GL_UNPACK_ROW_LENGTH
, psm
.unpack_row_length
);
7815 glPixelStorei(GL_UNPACK_SWAP_BYTES
, psm
.unpack_swap_bytes
);
7816 glPixelStorei(GL_UNPACK_SKIP_IMAGES
, psm
.unpack_skip_images
);
7817 glPixelStorei(GL_UNPACK_IMAGE_HEIGHT
, psm
.unpack_image_height
);
7821 int nextWidth
= newWidth
/2;
7822 int nextHeight
= newHeight
/2;
7823 int nextDepth
= newDepth
/2;
7826 if (nextWidth
< 1) nextWidth
= 1;
7827 if (nextHeight
< 1) nextHeight
= 1;
7828 if (nextDepth
< 1) nextDepth
= 1;
7829 memReq
= imageSize3D(nextWidth
, nextHeight
, nextDepth
, format
, type
);
7832 case GL_UNSIGNED_BYTE
:
7833 dstImage
= (GLubyte
*)malloc(memReq
);
7836 dstImage
= (GLbyte
*)malloc(memReq
);
7838 case GL_UNSIGNED_SHORT
:
7839 dstImage
= (GLushort
*)malloc(memReq
);
7842 dstImage
= (GLshort
*)malloc(memReq
);
7844 case GL_UNSIGNED_INT
:
7845 dstImage
= (GLuint
*)malloc(memReq
);
7848 dstImage
= (GLint
*)malloc(memReq
);
7851 dstImage
= (GLfloat
*)malloc(memReq
);
7853 case GL_UNSIGNED_BYTE_3_3_2
:
7854 case GL_UNSIGNED_BYTE_2_3_3_REV
:
7855 dstImage
= (GLubyte
*)malloc(memReq
);
7857 case GL_UNSIGNED_SHORT_5_6_5
:
7858 case GL_UNSIGNED_SHORT_5_6_5_REV
:
7859 case GL_UNSIGNED_SHORT_4_4_4_4
:
7860 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
7861 case GL_UNSIGNED_SHORT_5_5_5_1
:
7862 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
7863 dstImage
= (GLushort
*)malloc(memReq
);
7865 case GL_UNSIGNED_INT_8_8_8_8
:
7866 case GL_UNSIGNED_INT_8_8_8_8_REV
:
7867 case GL_UNSIGNED_INT_10_10_10_2
:
7868 case GL_UNSIGNED_INT_2_10_10_10_REV
:
7869 dstImage
= (GLuint
*)malloc(memReq
);
7872 return GLU_INVALID_ENUM
; /* assertion */
7874 if (dstImage
== NULL
) {
7875 glPixelStorei(GL_UNPACK_ALIGNMENT
, psm
.unpack_alignment
);
7876 glPixelStorei(GL_UNPACK_SKIP_ROWS
, psm
.unpack_skip_rows
);
7877 glPixelStorei(GL_UNPACK_SKIP_PIXELS
, psm
.unpack_skip_pixels
);
7878 glPixelStorei(GL_UNPACK_ROW_LENGTH
, psm
.unpack_row_length
);
7879 glPixelStorei(GL_UNPACK_SWAP_BYTES
, psm
.unpack_swap_bytes
);
7880 glPixelStorei(GL_UNPACK_SKIP_IMAGES
, psm
.unpack_skip_images
);
7881 glPixelStorei(GL_UNPACK_IMAGE_HEIGHT
, psm
.unpack_image_height
);
7882 return GLU_OUT_OF_MEMORY
;
7886 case GL_UNSIGNED_BYTE
:
7888 halveImage3D(cmpts
,extractUbyte
,shoveUbyte
,
7890 usersImage
,dstImage
,elementSize
,groupSize
,rowSize
,
7891 imageSize
,myswapBytes
);
7894 halveImage_ubyte(cmpts
,width
,height
,usersImage
,dstImage
,
7895 elementSize
,rowSize
,groupSize
);
7900 halveImage3D(cmpts
,extractSbyte
,shoveSbyte
,
7902 usersImage
,dstImage
,elementSize
,groupSize
,rowSize
,
7903 imageSize
,myswapBytes
);
7906 halveImage_byte(cmpts
,width
,height
,usersImage
,dstImage
,
7907 elementSize
,rowSize
,groupSize
);
7910 case GL_UNSIGNED_SHORT
:
7912 halveImage3D(cmpts
,extractUshort
,shoveUshort
,
7914 usersImage
,dstImage
,elementSize
,groupSize
,rowSize
,
7915 imageSize
,myswapBytes
);
7918 halveImage_ushort(cmpts
,width
,height
,usersImage
,dstImage
,
7919 elementSize
,rowSize
,groupSize
,myswapBytes
);
7924 halveImage3D(cmpts
,extractSshort
,shoveSshort
,
7926 usersImage
,dstImage
,elementSize
,groupSize
,rowSize
,
7927 imageSize
,myswapBytes
);
7930 halveImage_short(cmpts
,width
,height
,usersImage
,dstImage
,
7931 elementSize
,rowSize
,groupSize
,myswapBytes
);
7934 case GL_UNSIGNED_INT
:
7936 halveImage3D(cmpts
,extractUint
,shoveUint
,
7938 usersImage
,dstImage
,elementSize
,groupSize
,rowSize
,
7939 imageSize
,myswapBytes
);
7942 halveImage_uint(cmpts
,width
,height
,usersImage
,dstImage
,
7943 elementSize
,rowSize
,groupSize
,myswapBytes
);
7948 halveImage3D(cmpts
,extractSint
,shoveSint
,
7950 usersImage
,dstImage
,elementSize
,groupSize
,rowSize
,
7951 imageSize
,myswapBytes
);
7954 halveImage_int(cmpts
,width
,height
,usersImage
,dstImage
,
7955 elementSize
,rowSize
,groupSize
,myswapBytes
);
7960 halveImage3D(cmpts
,extractFloat
,shoveFloat
,
7962 usersImage
,dstImage
,elementSize
,groupSize
,rowSize
,
7963 imageSize
,myswapBytes
);
7966 halveImage_float(cmpts
,width
,height
,usersImage
,dstImage
,
7967 elementSize
,rowSize
,groupSize
,myswapBytes
);
7970 case GL_UNSIGNED_BYTE_3_3_2
:
7971 assert(format
== GL_RGB
);
7972 halveImagePackedPixel3D(3,extract332
,shove332
,
7973 width
,height
,depth
,usersImage
,dstImage
,
7974 elementSize
,rowSize
,imageSize
,myswapBytes
);
7976 case GL_UNSIGNED_BYTE_2_3_3_REV
:
7977 assert(format
== GL_RGB
);
7978 halveImagePackedPixel3D(3,extract233rev
,shove233rev
,
7979 width
,height
,depth
,usersImage
,dstImage
,
7980 elementSize
,rowSize
,imageSize
,myswapBytes
);
7982 case GL_UNSIGNED_SHORT_5_6_5
:
7983 halveImagePackedPixel3D(3,extract565
,shove565
,
7984 width
,height
,depth
,usersImage
,dstImage
,
7985 elementSize
,rowSize
,imageSize
,myswapBytes
);
7987 case GL_UNSIGNED_SHORT_5_6_5_REV
:
7988 halveImagePackedPixel3D(3,extract565rev
,shove565rev
,
7989 width
,height
,depth
,usersImage
,dstImage
,
7990 elementSize
,rowSize
,imageSize
,myswapBytes
);
7992 case GL_UNSIGNED_SHORT_4_4_4_4
:
7993 halveImagePackedPixel3D(4,extract4444
,shove4444
,
7994 width
,height
,depth
,usersImage
,dstImage
,
7995 elementSize
,rowSize
,imageSize
,myswapBytes
);
7997 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
7998 halveImagePackedPixel3D(4,extract4444rev
,shove4444rev
,
7999 width
,height
,depth
,usersImage
,dstImage
,
8000 elementSize
,rowSize
,imageSize
,myswapBytes
);
8002 case GL_UNSIGNED_SHORT_5_5_5_1
:
8003 halveImagePackedPixel3D(4,extract5551
,shove5551
,
8004 width
,height
,depth
,usersImage
,dstImage
,
8005 elementSize
,rowSize
,imageSize
,myswapBytes
);
8007 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
8008 halveImagePackedPixel3D(4,extract1555rev
,shove1555rev
,
8009 width
,height
,depth
,usersImage
,dstImage
,
8010 elementSize
,rowSize
,imageSize
,myswapBytes
);
8012 case GL_UNSIGNED_INT_8_8_8_8
:
8013 halveImagePackedPixel3D(4,extract8888
,shove8888
,
8014 width
,height
,depth
,usersImage
,dstImage
,
8015 elementSize
,rowSize
,imageSize
,myswapBytes
);
8017 case GL_UNSIGNED_INT_8_8_8_8_REV
:
8018 halveImagePackedPixel3D(4,extract8888rev
,shove8888rev
,
8019 width
,height
,depth
,usersImage
,dstImage
,
8020 elementSize
,rowSize
,imageSize
,myswapBytes
);
8022 case GL_UNSIGNED_INT_10_10_10_2
:
8023 halveImagePackedPixel3D(4,extract1010102
,shove1010102
,
8024 width
,height
,depth
,usersImage
,dstImage
,
8025 elementSize
,rowSize
,imageSize
,myswapBytes
);
8027 case GL_UNSIGNED_INT_2_10_10_10_REV
:
8028 halveImagePackedPixel3D(4,extract2101010rev
,shove2101010rev
,
8029 width
,height
,depth
,usersImage
,dstImage
,
8030 elementSize
,rowSize
,imageSize
,myswapBytes
);
8037 newHeight
= height
/2;
8040 if (newWidth
< 1) newWidth
= 1;
8041 if (newHeight
< 1) newHeight
= 1;
8042 if (newDepth
< 1) newDepth
= 1;
8045 rowSize
= newWidth
* groupSize
;
8046 imageSize
= rowSize
* newHeight
; /* 3dstuff */
8047 memReq
= imageSize3D(newWidth
, newHeight
, newDepth
, format
, type
);
8048 /* Swap srcImage and dstImage */
8049 __GLU_SWAP_IMAGE(srcImage
,dstImage
);
8051 case GL_UNSIGNED_BYTE
:
8052 dstImage
= (GLubyte
*)malloc(memReq
);
8055 dstImage
= (GLbyte
*)malloc(memReq
);
8057 case GL_UNSIGNED_SHORT
:
8058 dstImage
= (GLushort
*)malloc(memReq
);
8061 dstImage
= (GLshort
*)malloc(memReq
);
8063 case GL_UNSIGNED_INT
:
8064 dstImage
= (GLuint
*)malloc(memReq
);
8067 dstImage
= (GLint
*)malloc(memReq
);
8070 dstImage
= (GLfloat
*)malloc(memReq
);
8072 case GL_UNSIGNED_BYTE_3_3_2
:
8073 case GL_UNSIGNED_BYTE_2_3_3_REV
:
8074 dstImage
= (GLubyte
*)malloc(memReq
);
8076 case GL_UNSIGNED_SHORT_5_6_5
:
8077 case GL_UNSIGNED_SHORT_5_6_5_REV
:
8078 case GL_UNSIGNED_SHORT_4_4_4_4
:
8079 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
8080 case GL_UNSIGNED_SHORT_5_5_5_1
:
8081 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
8082 dstImage
= (GLushort
*)malloc(memReq
);
8084 case GL_UNSIGNED_INT_8_8_8_8
:
8085 case GL_UNSIGNED_INT_8_8_8_8_REV
:
8086 case GL_UNSIGNED_INT_10_10_10_2
:
8087 case GL_UNSIGNED_INT_2_10_10_10_REV
:
8088 dstImage
= (GLuint
*)malloc(memReq
);
8091 return GLU_INVALID_ENUM
; /* assertion */
8093 if (dstImage
== NULL
) {
8094 glPixelStorei(GL_UNPACK_ALIGNMENT
, psm
.unpack_alignment
);
8095 glPixelStorei(GL_UNPACK_SKIP_ROWS
, psm
.unpack_skip_rows
);
8096 glPixelStorei(GL_UNPACK_SKIP_PIXELS
, psm
.unpack_skip_pixels
);
8097 glPixelStorei(GL_UNPACK_ROW_LENGTH
, psm
.unpack_row_length
);
8098 glPixelStorei(GL_UNPACK_SWAP_BYTES
, psm
.unpack_swap_bytes
);
8099 glPixelStorei(GL_UNPACK_SKIP_IMAGES
, psm
.unpack_skip_images
);
8100 glPixelStorei(GL_UNPACK_IMAGE_HEIGHT
, psm
.unpack_image_height
);
8101 return GLU_OUT_OF_MEMORY
;
8103 /* level userLevel+1 is in srcImage; level userLevel already saved */
8104 level
= userLevel
+1;
8105 } else {/* user's image is *not* nice power-of-2 sized square */
8106 memReq
= imageSize3D(newWidth
, newHeight
, newDepth
, format
, type
);
8108 case GL_UNSIGNED_BYTE
:
8109 dstImage
= (GLubyte
*)malloc(memReq
);
8112 dstImage
= (GLbyte
*)malloc(memReq
);
8114 case GL_UNSIGNED_SHORT
:
8115 dstImage
= (GLushort
*)malloc(memReq
);
8118 dstImage
= (GLshort
*)malloc(memReq
);
8120 case GL_UNSIGNED_INT
:
8121 dstImage
= (GLuint
*)malloc(memReq
);
8124 dstImage
= (GLint
*)malloc(memReq
);
8127 dstImage
= (GLfloat
*)malloc(memReq
);
8129 case GL_UNSIGNED_BYTE_3_3_2
:
8130 case GL_UNSIGNED_BYTE_2_3_3_REV
:
8131 dstImage
= (GLubyte
*)malloc(memReq
);
8133 case GL_UNSIGNED_SHORT_5_6_5
:
8134 case GL_UNSIGNED_SHORT_5_6_5_REV
:
8135 case GL_UNSIGNED_SHORT_4_4_4_4
:
8136 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
8137 case GL_UNSIGNED_SHORT_5_5_5_1
:
8138 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
8139 dstImage
= (GLushort
*)malloc(memReq
);
8141 case GL_UNSIGNED_INT_8_8_8_8
:
8142 case GL_UNSIGNED_INT_8_8_8_8_REV
:
8143 case GL_UNSIGNED_INT_10_10_10_2
:
8144 case GL_UNSIGNED_INT_2_10_10_10_REV
:
8145 dstImage
= (GLuint
*)malloc(memReq
);
8148 return GLU_INVALID_ENUM
; /* assertion */
8151 if (dstImage
== NULL
) {
8152 glPixelStorei(GL_UNPACK_ALIGNMENT
, psm
.unpack_alignment
);
8153 glPixelStorei(GL_UNPACK_SKIP_ROWS
, psm
.unpack_skip_rows
);
8154 glPixelStorei(GL_UNPACK_SKIP_PIXELS
, psm
.unpack_skip_pixels
);
8155 glPixelStorei(GL_UNPACK_ROW_LENGTH
, psm
.unpack_row_length
);
8156 glPixelStorei(GL_UNPACK_SWAP_BYTES
, psm
.unpack_swap_bytes
);
8157 glPixelStorei(GL_UNPACK_SKIP_IMAGES
, psm
.unpack_skip_images
);
8158 glPixelStorei(GL_UNPACK_IMAGE_HEIGHT
, psm
.unpack_image_height
);
8159 return GLU_OUT_OF_MEMORY
;
8161 /*printf("Build3DMipmaps(): ScaleImage3D %d %d %d->%d %d %d\n",
8162 width,height,depth,newWidth,newHeight,newDepth);*/
8164 gluScaleImage3D(format
, width
, height
, depth
, type
, usersImage
,
8165 newWidth
, newHeight
, newDepth
, type
, dstImage
);
8168 rowSize
= newWidth
* groupSize
;
8169 imageSize
= rowSize
* newHeight
; /* 3dstuff */
8170 /* Swap dstImage and srcImage */
8171 __GLU_SWAP_IMAGE(srcImage
,dstImage
);
8173 if(levels
!= 0) { /* use as little memory as possible */
8175 int nextWidth
= newWidth
/2;
8176 int nextHeight
= newHeight
/2;
8177 int nextDepth
= newDepth
/2;
8178 if (nextWidth
< 1) nextWidth
= 1;
8179 if (nextHeight
< 1) nextHeight
= 1;
8180 if (nextDepth
< 1) nextDepth
= 1;
8182 memReq
= imageSize3D(nextWidth
, nextHeight
, nextDepth
, format
, type
);
8185 case GL_UNSIGNED_BYTE
:
8186 dstImage
= (GLubyte
*)malloc(memReq
);
8189 dstImage
= (GLbyte
*)malloc(memReq
);
8191 case GL_UNSIGNED_SHORT
:
8192 dstImage
= (GLushort
*)malloc(memReq
);
8195 dstImage
= (GLshort
*)malloc(memReq
);
8197 case GL_UNSIGNED_INT
:
8198 dstImage
= (GLuint
*)malloc(memReq
);
8201 dstImage
= (GLint
*)malloc(memReq
);
8204 dstImage
= (GLfloat
*)malloc(memReq
);
8206 case GL_UNSIGNED_BYTE_3_3_2
:
8207 case GL_UNSIGNED_BYTE_2_3_3_REV
:
8208 dstImage
= (GLubyte
*)malloc(memReq
);
8210 case GL_UNSIGNED_SHORT_5_6_5
:
8211 case GL_UNSIGNED_SHORT_5_6_5_REV
:
8212 case GL_UNSIGNED_SHORT_4_4_4_4
:
8213 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
8214 case GL_UNSIGNED_SHORT_5_5_5_1
:
8215 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
8216 dstImage
= (GLushort
*)malloc(memReq
);
8218 case GL_UNSIGNED_INT_8_8_8_8
:
8219 case GL_UNSIGNED_INT_8_8_8_8_REV
:
8220 case GL_UNSIGNED_INT_10_10_10_2
:
8221 case GL_UNSIGNED_INT_2_10_10_10_REV
:
8222 dstImage
= (GLuint
*)malloc(memReq
);
8225 return GLU_INVALID_ENUM
; /* assertion */
8227 if (dstImage
== NULL
) {
8228 glPixelStorei(GL_UNPACK_ALIGNMENT
, psm
.unpack_alignment
);
8229 glPixelStorei(GL_UNPACK_SKIP_ROWS
, psm
.unpack_skip_rows
);
8230 glPixelStorei(GL_UNPACK_SKIP_PIXELS
, psm
.unpack_skip_pixels
);
8231 glPixelStorei(GL_UNPACK_ROW_LENGTH
, psm
.unpack_row_length
);
8232 glPixelStorei(GL_UNPACK_SWAP_BYTES
, psm
.unpack_swap_bytes
);
8233 glPixelStorei(GL_UNPACK_SKIP_IMAGES
, psm
.unpack_skip_images
);
8234 glPixelStorei(GL_UNPACK_IMAGE_HEIGHT
, psm
.unpack_image_height
);
8235 return GLU_OUT_OF_MEMORY
;
8238 /* level userLevel is in srcImage; nothing saved yet */
8242 glPixelStorei(GL_UNPACK_SWAP_BYTES
, GL_FALSE
);
8243 if (baseLevel
<= level
&& level
<= maxLevel
) {
8244 gluTexImage3D(target
, level
, internalFormat
, newWidth
, newHeight
, newDepth
,
8245 0,format
, type
, (void *)srcImage
);
8247 level
++; /* update current level for the loop */
8248 for (; level
<= levels
; level
++) {
8250 case GL_UNSIGNED_BYTE
:
8252 halveImage3D(cmpts
,extractUbyte
,shoveUbyte
,
8253 newWidth
,newHeight
,newDepth
,
8254 srcImage
,dstImage
,elementSize
,groupSize
,rowSize
,
8255 imageSize
,myswapBytes
);
8258 halveImage_ubyte(cmpts
,newWidth
,newHeight
,srcImage
,dstImage
,
8259 elementSize
,rowSize
,groupSize
);
8264 halveImage3D(cmpts
,extractSbyte
,shoveSbyte
,
8265 newWidth
,newHeight
,newDepth
,
8266 srcImage
,dstImage
,elementSize
,groupSize
,rowSize
,
8267 imageSize
,myswapBytes
);
8270 halveImage_byte(cmpts
,newWidth
,newHeight
,srcImage
,dstImage
,
8271 elementSize
,rowSize
,groupSize
);
8274 case GL_UNSIGNED_SHORT
:
8276 halveImage3D(cmpts
,extractUshort
,shoveUshort
,
8277 newWidth
,newHeight
,newDepth
,
8278 srcImage
,dstImage
,elementSize
,groupSize
,rowSize
,
8279 imageSize
,myswapBytes
);
8282 halveImage_ushort(cmpts
,newWidth
,newHeight
,srcImage
,dstImage
,
8283 elementSize
,rowSize
,groupSize
,myswapBytes
);
8288 halveImage3D(cmpts
,extractSshort
,shoveSshort
,
8289 newWidth
,newHeight
,newDepth
,
8290 srcImage
,dstImage
,elementSize
,groupSize
,rowSize
,
8291 imageSize
,myswapBytes
);
8294 halveImage_short(cmpts
,newWidth
,newHeight
,srcImage
,dstImage
,
8295 elementSize
,rowSize
,groupSize
,myswapBytes
);
8298 case GL_UNSIGNED_INT
:
8300 halveImage3D(cmpts
,extractUint
,shoveUint
,
8301 newWidth
,newHeight
,newDepth
,
8302 srcImage
,dstImage
,elementSize
,groupSize
,rowSize
,
8303 imageSize
,myswapBytes
);
8306 halveImage_uint(cmpts
,newWidth
,newHeight
,srcImage
,dstImage
,
8307 elementSize
,rowSize
,groupSize
,myswapBytes
);
8312 halveImage3D(cmpts
,extractSint
,shoveSint
,
8313 newWidth
,newHeight
,newDepth
,
8314 srcImage
,dstImage
,elementSize
,groupSize
,rowSize
,
8315 imageSize
,myswapBytes
);
8318 halveImage_int(cmpts
,newWidth
,newHeight
,srcImage
,dstImage
,
8319 elementSize
,rowSize
,groupSize
,myswapBytes
);
8324 halveImage3D(cmpts
,extractFloat
,shoveFloat
,
8325 newWidth
,newHeight
,newDepth
,
8326 srcImage
,dstImage
,elementSize
,groupSize
,rowSize
,
8327 imageSize
,myswapBytes
);
8330 halveImage_float(cmpts
,newWidth
,newHeight
,srcImage
,dstImage
,
8331 elementSize
,rowSize
,groupSize
,myswapBytes
);
8334 case GL_UNSIGNED_BYTE_3_3_2
:
8335 halveImagePackedPixel3D(3,extract332
,shove332
,
8336 newWidth
,newHeight
,newDepth
,
8337 srcImage
,dstImage
,elementSize
,rowSize
,
8338 imageSize
,myswapBytes
);
8340 case GL_UNSIGNED_BYTE_2_3_3_REV
:
8341 halveImagePackedPixel3D(3,extract233rev
,shove233rev
,
8342 newWidth
,newHeight
,newDepth
,
8343 srcImage
,dstImage
,elementSize
,rowSize
,
8344 imageSize
,myswapBytes
);
8346 case GL_UNSIGNED_SHORT_5_6_5
:
8347 halveImagePackedPixel3D(3,extract565
,shove565
,
8348 newWidth
,newHeight
,newDepth
,
8349 srcImage
,dstImage
,elementSize
,rowSize
,
8350 imageSize
,myswapBytes
);
8352 case GL_UNSIGNED_SHORT_5_6_5_REV
:
8353 halveImagePackedPixel3D(3,extract565rev
,shove565rev
,
8354 newWidth
,newHeight
,newDepth
,
8355 srcImage
,dstImage
,elementSize
,rowSize
,
8356 imageSize
,myswapBytes
);
8358 case GL_UNSIGNED_SHORT_4_4_4_4
:
8359 halveImagePackedPixel3D(4,extract4444
,shove4444
,
8360 newWidth
,newHeight
,newDepth
,
8361 srcImage
,dstImage
,elementSize
,rowSize
,
8362 imageSize
,myswapBytes
);
8364 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
8365 halveImagePackedPixel3D(4,extract4444rev
,shove4444rev
,
8366 newWidth
,newHeight
,newDepth
,
8367 srcImage
,dstImage
,elementSize
,rowSize
,
8368 imageSize
,myswapBytes
);
8370 case GL_UNSIGNED_SHORT_5_5_5_1
:
8371 halveImagePackedPixel3D(4,extract5551
,shove5551
,
8372 newWidth
,newHeight
,newDepth
,
8373 srcImage
,dstImage
,elementSize
,rowSize
,
8374 imageSize
,myswapBytes
);
8376 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
8377 halveImagePackedPixel3D(4,extract1555rev
,shove1555rev
,
8378 newWidth
,newHeight
,newDepth
,
8379 srcImage
,dstImage
,elementSize
,rowSize
,
8380 imageSize
,myswapBytes
);
8382 case GL_UNSIGNED_INT_8_8_8_8
:
8383 halveImagePackedPixel3D(4,extract8888
,shove8888
,
8384 newWidth
,newHeight
,newDepth
,
8385 srcImage
,dstImage
,elementSize
,rowSize
,
8386 imageSize
,myswapBytes
);
8388 case GL_UNSIGNED_INT_8_8_8_8_REV
:
8389 halveImagePackedPixel3D(4,extract8888rev
,shove8888rev
,
8390 newWidth
,newHeight
,newDepth
,
8391 srcImage
,dstImage
,elementSize
,rowSize
,
8392 imageSize
,myswapBytes
);
8394 case GL_UNSIGNED_INT_10_10_10_2
:
8395 halveImagePackedPixel3D(4,extract1010102
,shove1010102
,
8396 newWidth
,newHeight
,newDepth
,
8397 srcImage
,dstImage
,elementSize
,rowSize
,
8398 imageSize
,myswapBytes
);
8400 case GL_UNSIGNED_INT_2_10_10_10_REV
:
8401 halveImagePackedPixel3D(4,extract2101010rev
,shove2101010rev
,
8402 newWidth
,newHeight
,newDepth
,
8403 srcImage
,dstImage
,elementSize
,rowSize
,
8404 imageSize
,myswapBytes
);
8411 __GLU_SWAP_IMAGE(srcImage
,dstImage
);
8413 if (newWidth
> 1) { newWidth
/= 2; rowSize
/= 2;}
8414 if (newHeight
> 1) { newHeight
/= 2; imageSize
= rowSize
* newHeight
; }
8415 if (newDepth
> 1) newDepth
/= 2;
8417 /* call tex image with srcImage untouched since it's not padded */
8418 if (baseLevel
<= level
&& level
<= maxLevel
) {
8419 gluTexImage3D(target
, level
, internalFormat
, newWidth
, newHeight
,
8420 newDepth
,0, format
, type
, (void *) srcImage
);
8424 glPixelStorei(GL_UNPACK_ALIGNMENT
, psm
.unpack_alignment
);
8425 glPixelStorei(GL_UNPACK_SKIP_ROWS
, psm
.unpack_skip_rows
);
8426 glPixelStorei(GL_UNPACK_SKIP_PIXELS
, psm
.unpack_skip_pixels
);
8427 glPixelStorei(GL_UNPACK_ROW_LENGTH
, psm
.unpack_row_length
);
8428 glPixelStorei(GL_UNPACK_SWAP_BYTES
, psm
.unpack_swap_bytes
);
8429 glPixelStorei(GL_UNPACK_SKIP_IMAGES
, psm
.unpack_skip_images
);
8430 glPixelStorei(GL_UNPACK_IMAGE_HEIGHT
, psm
.unpack_image_height
);
8432 free(srcImage
); /*if you get to here, a srcImage has always been malloc'ed*/
8433 if (dstImage
) { /* if it's non-rectangular and only 1 level */
8437 } /* gluBuild3DMipmapLevelsCore() */
8440 gluBuild3DMipmapLevels(GLenum target
, GLint internalFormat
,
8441 GLsizei width
, GLsizei height
, GLsizei depth
,
8442 GLenum format
, GLenum type
,
8443 GLint userLevel
, GLint baseLevel
, GLint maxLevel
,
8448 int rc
= checkMipmapArgs(internalFormat
,format
,type
);
8449 if (rc
!= 0) return rc
;
8451 if (width
< 1 || height
< 1 || depth
< 1) {
8452 return GLU_INVALID_VALUE
;
8455 if(type
== GL_BITMAP
) {
8456 return GLU_INVALID_ENUM
;
8459 levels
= computeLog(width
);
8460 level
= computeLog(height
);
8461 if (level
> levels
) levels
=level
;
8462 level
= computeLog(depth
);
8463 if (level
> levels
) levels
=level
;
8466 if (!isLegalLevels(userLevel
,baseLevel
,maxLevel
,levels
))
8467 return GLU_INVALID_VALUE
;
8469 return gluBuild3DMipmapLevelsCore(target
, internalFormat
,
8470 width
, height
, depth
,
8471 width
, height
, depth
,
8473 userLevel
, baseLevel
, maxLevel
,
8475 } /* gluBuild3DMipmapLevels() */
8478 gluBuild3DMipmaps(GLenum target
, GLint internalFormat
,
8479 GLsizei width
, GLsizei height
, GLsizei depth
,
8480 GLenum format
, GLenum type
, const void *data
)
8482 GLint widthPowerOf2
, heightPowerOf2
, depthPowerOf2
;
8485 int rc
= checkMipmapArgs(internalFormat
,format
,type
);
8486 if (rc
!= 0) return rc
;
8488 if (width
< 1 || height
< 1 || depth
< 1) {
8489 return GLU_INVALID_VALUE
;
8492 if(type
== GL_BITMAP
) {
8493 return GLU_INVALID_ENUM
;
8496 closestFit3D(target
,width
,height
,depth
,internalFormat
,format
,type
,
8497 &widthPowerOf2
,&heightPowerOf2
,&depthPowerOf2
);
8499 levels
= computeLog(widthPowerOf2
);
8500 level
= computeLog(heightPowerOf2
);
8501 if (level
> levels
) levels
=level
;
8502 level
= computeLog(depthPowerOf2
);
8503 if (level
> levels
) levels
=level
;
8505 return gluBuild3DMipmapLevelsCore(target
, internalFormat
,
8506 width
, height
, depth
,
8507 widthPowerOf2
, heightPowerOf2
,
8509 format
, type
, 0, 0, levels
,
8511 } /* gluBuild3DMipmaps() */
8513 static GLdouble
extractUbyte(int isSwap
, const void *ubyte
)
8515 isSwap
= isSwap
; /* turn off warnings */
8517 assert(*((const GLubyte
*)ubyte
) <= 255);
8519 return (GLdouble
)(*((const GLubyte
*)ubyte
));
8520 } /* extractUbyte() */
8522 static void shoveUbyte(GLdouble value
, int index
, void *data
)
8524 assert(0.0 <= value
&& value
< 256.0);
8526 ((GLubyte
*)data
)[index
]= (GLubyte
)value
;
8527 } /* shoveUbyte() */
8529 static GLdouble
extractSbyte(int isSwap
, const void *sbyte
)
8531 isSwap
= isSwap
; /* turn off warnings */
8533 assert(*((const GLbyte
*)sbyte
) <= 127);
8535 return (GLdouble
)(*((const GLbyte
*)sbyte
));
8536 } /* extractSbyte() */
8538 static void shoveSbyte(GLdouble value
, int index
, void *data
)
8540 ((GLbyte
*)data
)[index
]= (GLbyte
)value
;
8541 } /* shoveSbyte() */
8543 static GLdouble
extractUshort(int isSwap
, const void *uitem
)
8548 ushort
= __GLU_SWAP_2_BYTES(uitem
);
8551 ushort
= *(const GLushort
*)uitem
;
8554 assert(ushort
<= 65535);
8556 return (GLdouble
)ushort
;
8557 } /* extractUshort() */
8559 static void shoveUshort(GLdouble value
, int index
, void *data
)
8561 assert(0.0 <= value
&& value
< 65536.0);
8563 ((GLushort
*)data
)[index
]= (GLushort
)value
;
8564 } /* shoveUshort() */
8566 static GLdouble
extractSshort(int isSwap
, const void *sitem
)
8571 sshort
= __GLU_SWAP_2_BYTES(sitem
);
8574 sshort
= *(const GLshort
*)sitem
;
8577 assert(sshort
<= 32767);
8579 return (GLdouble
)sshort
;
8580 } /* extractSshort() */
8582 static void shoveSshort(GLdouble value
, int index
, void *data
)
8584 assert(0.0 <= value
&& value
< 32768.0);
8586 ((GLshort
*)data
)[index
]= (GLshort
)value
;
8587 } /* shoveSshort() */
8589 static GLdouble
extractUint(int isSwap
, const void *uitem
)
8594 uint
= __GLU_SWAP_4_BYTES(uitem
);
8597 uint
= *(const GLuint
*)uitem
;
8600 assert(uint
<= 0xffffffff);
8602 return (GLdouble
)uint
;
8603 } /* extractUint() */
8605 static void shoveUint(GLdouble value
, int index
, void *data
)
8607 assert(0.0 <= value
&& value
<= (GLdouble
) UINT_MAX
);
8609 ((GLuint
*)data
)[index
]= (GLuint
)value
;
8612 static GLdouble
extractSint(int isSwap
, const void *sitem
)
8617 sint
= __GLU_SWAP_4_BYTES(sitem
);
8620 sint
= *(const GLint
*)sitem
;
8623 assert(sint
<= 0x7fffffff);
8625 return (GLdouble
)sint
;
8626 } /* extractSint() */
8628 static void shoveSint(GLdouble value
, int index
, void *data
)
8630 assert(0.0 <= value
&& value
<= (GLdouble
) INT_MAX
);
8632 ((GLint
*)data
)[index
]= (GLint
)value
;
8635 static GLdouble
extractFloat(int isSwap
, const void *item
)
8640 ffloat
= __GLU_SWAP_4_BYTES(item
);
8643 ffloat
= *(const GLfloat
*)item
;
8646 assert(ffloat
<= 1.0);
8648 return (GLdouble
)ffloat
;
8649 } /* extractFloat() */
8651 static void shoveFloat(GLdouble value
, int index
, void *data
)
8653 assert(0.0 <= value
&& value
<= 1.0);
8655 ((GLfloat
*)data
)[index
]= value
;
8656 } /* shoveFloat() */
8658 static void halveImageSlice(int components
,
8659 GLdouble (*extract
)(int, const void *),
8660 void (*shove
)(GLdouble
, int, void *),
8661 GLint width
, GLint height
, GLint depth
,
8662 const void *dataIn
, void *dataOut
,
8663 GLint elementSizeInBytes
,
8664 GLint groupSizeInBytes
,
8665 GLint rowSizeInBytes
,
8666 GLint imageSizeInBytes
,
8670 int halfWidth
= width
/ 2;
8671 int halfHeight
= height
/ 2;
8672 int halfDepth
= depth
/ 2;
8673 const char *src
= (const char *)dataIn
;
8674 int rowPadBytes
= rowSizeInBytes
- (width
* groupSizeInBytes
);
8675 int imagePadBytes
= imageSizeInBytes
- (width
*height
*groupSizeInBytes
);
8678 assert((width
== 1 || height
== 1) && depth
>= 2);
8680 if (width
== height
) { /* a 1-pixel column viewed from top */
8681 /* printf("1-column\n");*/
8682 assert(width
== 1 && height
== 1);
8685 for (ii
= 0; ii
< halfDepth
; ii
++) {
8688 for (cc
= 0; cc
< components
; cc
++) {
8690 double extractTotals
[BOX2
][4];
8693 extractTotals
[0][cc
]= (*extract
)(isSwap
,src
);
8694 extractTotals
[1][cc
]= (*extract
)(isSwap
,(src
+imageSizeInBytes
));
8696 /* average 2 pixels since only a column */
8698 /* totals[RED]= extractTotals[0][RED]+extractTotals[1][RED];
8699 * totals[RED]/= 2.0;
8701 for (kk
= 0; kk
< BOX2
; kk
++) {
8702 totals
[cc
]+= extractTotals
[kk
][cc
];
8704 totals
[cc
]/= (double)BOX2
;
8706 (*shove
)(totals
[cc
],outIndex
,dataOut
);
8708 src
+= elementSizeInBytes
;
8711 /* skip over to next group of 2 */
8712 src
+= rowSizeInBytes
;
8715 assert(src
== &((const char *)dataIn
)[rowSizeInBytes
*height
*depth
]);
8716 assert(outIndex
== halfDepth
* components
);
8718 else if (height
== 1) { /* horizontal slice viewed from top */
8719 /* printf("horizontal slice\n"); */
8722 for (ii
= 0; ii
< halfDepth
; ii
++) {
8723 for (jj
= 0; jj
< halfWidth
; jj
++) {
8726 for (cc
= 0; cc
< components
; cc
++) {
8729 double extractTotals
[BOX4
][4];
8731 extractTotals
[0][cc
]=(*extract
)(isSwap
,src
);
8732 extractTotals
[1][cc
]=(*extract
)(isSwap
,
8733 (src
+groupSizeInBytes
));
8734 extractTotals
[2][cc
]=(*extract
)(isSwap
,
8735 (src
+imageSizeInBytes
));
8736 extractTotals
[3][cc
]=(*extract
)(isSwap
,
8737 (src
+imageSizeInBytes
+groupSizeInBytes
));
8739 /* grab 4 pixels to average */
8741 /* totals[RED]= extractTotals[0][RED]+extractTotals[1][RED]+
8742 * extractTotals[2][RED]+extractTotals[3][RED];
8743 * totals[RED]/= 4.0;
8745 for (kk
= 0; kk
< BOX4
; kk
++) {
8746 totals
[cc
]+= extractTotals
[kk
][cc
];
8748 totals
[cc
]/= (double)BOX4
;
8750 (*shove
)(totals
[cc
],outIndex
,dataOut
);
8753 src
+= elementSizeInBytes
;
8756 /* skip over to next horizontal square of 4 */
8757 src
+= groupSizeInBytes
;
8761 src
+= rowSizeInBytes
;
8764 assert(src
== &((const char *)dataIn
)[rowSizeInBytes
*height
*depth
]);
8765 assert(outIndex
== halfWidth
* halfDepth
* components
);
8767 else if (width
== 1) { /* vertical slice viewed from top */
8768 /* printf("vertical slice\n"); */
8769 assert(height
!= 1);
8771 for (ii
= 0; ii
< halfDepth
; ii
++) {
8772 for (jj
= 0; jj
< halfHeight
; jj
++) {
8775 for (cc
= 0; cc
< components
; cc
++) {
8778 double extractTotals
[BOX4
][4];
8780 extractTotals
[0][cc
]=(*extract
)(isSwap
,src
);
8781 extractTotals
[1][cc
]=(*extract
)(isSwap
,
8782 (src
+rowSizeInBytes
));
8783 extractTotals
[2][cc
]=(*extract
)(isSwap
,
8784 (src
+imageSizeInBytes
));
8785 extractTotals
[3][cc
]=(*extract
)(isSwap
,
8786 (src
+imageSizeInBytes
+rowSizeInBytes
));
8788 /* grab 4 pixels to average */
8790 /* totals[RED]= extractTotals[0][RED]+extractTotals[1][RED]+
8791 * extractTotals[2][RED]+extractTotals[3][RED];
8792 * totals[RED]/= 4.0;
8794 for (kk
= 0; kk
< BOX4
; kk
++) {
8795 totals
[cc
]+= extractTotals
[kk
][cc
];
8797 totals
[cc
]/= (double)BOX4
;
8799 (*shove
)(totals
[cc
],outIndex
,dataOut
);
8802 src
+= elementSizeInBytes
;
8806 /* skip over to next vertical square of 4 */
8807 src
+= rowSizeInBytes
;
8809 src
+= imagePadBytes
;
8811 src
+= imageSizeInBytes
;
8814 assert(src
== &((const char *)dataIn
)[rowSizeInBytes
*height
*depth
]);
8815 assert(outIndex
== halfHeight
* halfDepth
* components
);
8818 } /* halveImageSlice() */
8820 static void halveImage3D(int components
,
8821 GLdouble (*extract
)(int, const void *),
8822 void (*shove
)(GLdouble
, int, void *),
8823 GLint width
, GLint height
, GLint depth
,
8824 const void *dataIn
, void *dataOut
,
8825 GLint elementSizeInBytes
,
8826 GLint groupSizeInBytes
,
8827 GLint rowSizeInBytes
,
8828 GLint imageSizeInBytes
,
8833 /* a horizontal/vertical/one-column slice viewed from top */
8834 if (width
== 1 || height
== 1) {
8837 halveImageSlice(components
,extract
,shove
, width
, height
, depth
,
8838 dataIn
, dataOut
, elementSizeInBytes
, groupSizeInBytes
,
8839 rowSizeInBytes
, imageSizeInBytes
, isSwap
);
8845 int halfWidth
= width
/ 2;
8846 int halfHeight
= height
/ 2;
8847 int halfDepth
= depth
/ 2;
8848 const char *src
= (const char *) dataIn
;
8849 int rowPadBytes
= rowSizeInBytes
- (width
*groupSizeInBytes
);
8850 int imagePadBytes
= imageSizeInBytes
- (width
*height
*groupSizeInBytes
);
8853 for (dd
= 0; dd
< halfDepth
; dd
++) {
8854 for (ii
= 0; ii
< halfHeight
; ii
++) {
8855 for (jj
= 0; jj
< halfWidth
; jj
++) {
8858 for (cc
= 0; cc
< components
; cc
++) {
8861 double totals
[4]; /* 4 is maximum components */
8862 double extractTotals
[BOX8
][4]; /* 4 is maximum components */
8864 extractTotals
[0][cc
]= (*extract
)(isSwap
,src
);
8865 extractTotals
[1][cc
]= (*extract
)(isSwap
,
8866 (src
+groupSizeInBytes
));
8867 extractTotals
[2][cc
]= (*extract
)(isSwap
,
8868 (src
+rowSizeInBytes
));
8869 extractTotals
[3][cc
]= (*extract
)(isSwap
,
8870 (src
+rowSizeInBytes
+groupSizeInBytes
));
8872 extractTotals
[4][cc
]= (*extract
)(isSwap
,
8873 (src
+imageSizeInBytes
));
8875 extractTotals
[5][cc
]= (*extract
)(isSwap
,
8876 (src
+groupSizeInBytes
+imageSizeInBytes
));
8877 extractTotals
[6][cc
]= (*extract
)(isSwap
,
8878 (src
+rowSizeInBytes
+imageSizeInBytes
));
8879 extractTotals
[7][cc
]= (*extract
)(isSwap
,
8880 (src
+rowSizeInBytes
+groupSizeInBytes
+imageSizeInBytes
));
8884 /* totals[RED]= extractTotals[0][RED]+extractTotals[1][RED]+
8885 * extractTotals[2][RED]+extractTotals[3][RED]+
8886 * extractTotals[4][RED]+extractTotals[5][RED]+
8887 * extractTotals[6][RED]+extractTotals[7][RED];
8888 * totals[RED]/= 8.0;
8890 for (kk
= 0; kk
< BOX8
; kk
++) {
8891 totals
[cc
]+= extractTotals
[kk
][cc
];
8893 totals
[cc
]/= (double)BOX8
;
8895 (*shove
)(totals
[cc
],outIndex
,dataOut
);
8899 src
+= elementSizeInBytes
; /* go to next component */
8902 /* skip over to next square of 4 */
8903 src
+= groupSizeInBytes
;
8905 /* skip past pad bytes, if any, to get to next row */
8908 /* src is at beginning of a row here, but it's the second row of
8909 * the square block of 4 pixels that we just worked on so we
8910 * need to go one more row.
8918 src
+= rowSizeInBytes
;
8921 /* skip past pad bytes, if any, to get to next image */
8922 src
+= imagePadBytes
;
8924 src
+= imageSizeInBytes
;
8927 /* both pointers must reach one byte after the end */
8928 assert(src
== &((const char *)dataIn
)[rowSizeInBytes
*height
*depth
]);
8929 assert(outIndex
== halfWidth
* halfHeight
* halfDepth
* components
);
8931 } /* halveImage3D() */