2 * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
3 * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice including the dates of first publication and
13 * either this permission notice or a reference to
14 * http://oss.sgi.com/projects/FreeB/
15 * shall be included in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
22 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 * Except as contained in this notice, the name of Silicon Graphics, Inc.
26 * shall not be used in advertising or otherwise to promote the sale, use or
27 * other dealings in this Software without prior written authorization from
28 * Silicon Graphics, Inc.
37 #include <limits.h> /* UINT_MAX */
51 /* Pixel storage modes */
54 GLint pack_row_length
;
56 GLint pack_skip_pixels
;
58 GLint pack_swap_bytes
;
59 GLint pack_skip_images
;
60 GLint pack_image_height
;
62 GLint unpack_alignment
;
63 GLint unpack_row_length
;
64 GLint unpack_skip_rows
;
65 GLint unpack_skip_pixels
;
66 GLint unpack_lsb_first
;
67 GLint unpack_swap_bytes
;
68 GLint unpack_skip_images
;
69 GLint unpack_image_height
;
72 static int gluBuild1DMipmapLevelsCore(GLenum
, GLint
,
75 GLenum
, GLenum
, GLint
, GLint
, GLint
,
77 static int gluBuild2DMipmapLevelsCore(GLenum
, GLint
,
80 GLenum
, GLenum
, GLint
, GLint
, GLint
,
82 static int gluBuild3DMipmapLevelsCore(GLenum
, GLint
,
83 GLsizei
, GLsizei
, GLsizei
,
84 GLsizei
, GLsizei
, GLsizei
,
85 GLenum
, GLenum
, GLint
, GLint
, GLint
,
89 * internal function declarations
91 static GLfloat
bytes_per_element(GLenum type
);
92 static GLint
elements_per_group(GLenum format
, GLenum type
);
93 static GLint
is_index(GLenum format
);
94 static GLint
image_size(GLint width
, GLint height
, GLenum format
, GLenum type
);
95 static void fill_image(const PixelStorageModes
*,
96 GLint width
, GLint height
, GLenum format
,
97 GLenum type
, GLboolean index_format
,
98 const void *userdata
, GLushort
*newimage
);
99 static void empty_image(const PixelStorageModes
*,
100 GLint width
, GLint height
, GLenum format
,
101 GLenum type
, GLboolean index_format
,
102 const GLushort
*oldimage
, void *userdata
);
103 static void scale_internal(GLint components
, GLint widthin
, GLint heightin
,
104 const GLushort
*datain
,
105 GLint widthout
, GLint heightout
,
108 static void scale_internal_ubyte(GLint components
, GLint widthin
,
109 GLint heightin
, const GLubyte
*datain
,
110 GLint widthout
, GLint heightout
,
111 GLubyte
*dataout
, GLint element_size
,
112 GLint ysize
, GLint group_size
);
113 static void scale_internal_byte(GLint components
, GLint widthin
,
114 GLint heightin
, const GLbyte
*datain
,
115 GLint widthout
, GLint heightout
,
116 GLbyte
*dataout
, GLint element_size
,
117 GLint ysize
, GLint group_size
);
118 static void scale_internal_ushort(GLint components
, GLint widthin
,
119 GLint heightin
, const GLushort
*datain
,
120 GLint widthout
, GLint heightout
,
121 GLushort
*dataout
, GLint element_size
,
122 GLint ysize
, GLint group_size
,
124 static void scale_internal_short(GLint components
, GLint widthin
,
125 GLint heightin
, const GLshort
*datain
,
126 GLint widthout
, GLint heightout
,
127 GLshort
*dataout
, GLint element_size
,
128 GLint ysize
, GLint group_size
,
130 static void scale_internal_uint(GLint components
, GLint widthin
,
131 GLint heightin
, const GLuint
*datain
,
132 GLint widthout
, GLint heightout
,
133 GLuint
*dataout
, GLint element_size
,
134 GLint ysize
, GLint group_size
,
136 static void scale_internal_int(GLint components
, GLint widthin
,
137 GLint heightin
, const GLint
*datain
,
138 GLint widthout
, GLint heightout
,
139 GLint
*dataout
, GLint element_size
,
140 GLint ysize
, GLint group_size
,
142 static void scale_internal_float(GLint components
, GLint widthin
,
143 GLint heightin
, const GLfloat
*datain
,
144 GLint widthout
, GLint heightout
,
145 GLfloat
*dataout
, GLint element_size
,
146 GLint ysize
, GLint group_size
,
149 static int checkMipmapArgs(GLenum
, GLenum
, GLenum
);
150 static GLboolean
legalFormat(GLenum
);
151 static GLboolean
legalType(GLenum
);
152 static GLboolean
isTypePackedPixel(GLenum
);
153 static GLboolean
isLegalFormatForPackedPixelType(GLenum
, GLenum
);
154 static GLboolean
isLegalLevels(GLint
, GLint
, GLint
, GLint
);
155 static void closestFit(GLenum
, GLint
, GLint
, GLint
, GLenum
, GLenum
,
158 /* all extract/shove routines must return double to handle unsigned ints */
159 static GLdouble
extractUbyte(int, const void *);
160 static void shoveUbyte(GLdouble
, int, void *);
161 static GLdouble
extractSbyte(int, const void *);
162 static void shoveSbyte(GLdouble
, int, void *);
163 static GLdouble
extractUshort(int, const void *);
164 static void shoveUshort(GLdouble
, int, void *);
165 static GLdouble
extractSshort(int, const void *);
166 static void shoveSshort(GLdouble
, int, void *);
167 static GLdouble
extractUint(int, const void *);
168 static void shoveUint(GLdouble
, int, void *);
169 static GLdouble
extractSint(int, const void *);
170 static void shoveSint(GLdouble
, int, void *);
171 static GLdouble
extractFloat(int, const void *);
172 static void shoveFloat(GLdouble
, int, void *);
173 static void halveImageSlice(int, GLdouble (*)(int, const void *),
174 void (*)(GLdouble
, int, void *),
176 const void *, void *,
177 GLint
, GLint
, GLint
, GLint
, GLint
);
178 static void halveImage3D(int, GLdouble (*)(int, const void *),
179 void (*)(GLdouble
, int, void *),
181 const void *, void *,
182 GLint
, GLint
, GLint
, GLint
, GLint
);
184 /* packedpixel type scale routines */
185 static void extract332(int,const void *, GLfloat
[]);
186 static void shove332(const GLfloat
[],int ,void *);
187 static void extract233rev(int,const void *, GLfloat
[]);
188 static void shove233rev(const GLfloat
[],int ,void *);
189 static void extract565(int,const void *, GLfloat
[]);
190 static void shove565(const GLfloat
[],int ,void *);
191 static void extract565rev(int,const void *, GLfloat
[]);
192 static void shove565rev(const GLfloat
[],int ,void *);
193 static void extract4444(int,const void *, GLfloat
[]);
194 static void shove4444(const GLfloat
[],int ,void *);
195 static void extract4444rev(int,const void *, GLfloat
[]);
196 static void shove4444rev(const GLfloat
[],int ,void *);
197 static void extract5551(int,const void *, GLfloat
[]);
198 static void shove5551(const GLfloat
[],int ,void *);
199 static void extract1555rev(int,const void *, GLfloat
[]);
200 static void shove1555rev(const GLfloat
[],int ,void *);
201 static void extract8888(int,const void *, GLfloat
[]);
202 static void shove8888(const GLfloat
[],int ,void *);
203 static void extract8888rev(int,const void *, GLfloat
[]);
204 static void shove8888rev(const GLfloat
[],int ,void *);
205 static void extract1010102(int,const void *, GLfloat
[]);
206 static void shove1010102(const GLfloat
[],int ,void *);
207 static void extract2101010rev(int,const void *, GLfloat
[]);
208 static void shove2101010rev(const GLfloat
[],int ,void *);
209 static void scaleInternalPackedPixel(int,
210 void (*)(int, const void *,GLfloat
[]),
211 void (*)(const GLfloat
[],int, void *),
212 GLint
,GLint
, const void *,
213 GLint
,GLint
,void *,GLint
,GLint
,GLint
);
214 static void halveImagePackedPixel(int,
215 void (*)(int, const void *,GLfloat
[]),
216 void (*)(const GLfloat
[],int, void *),
217 GLint
, GLint
, const void *,
218 void *, GLint
, GLint
, GLint
);
219 static void halve1DimagePackedPixel(int,
220 void (*)(int, const void *,GLfloat
[]),
221 void (*)(const GLfloat
[],int, void *),
222 GLint
, GLint
, const void *,
223 void *, GLint
, GLint
, GLint
);
225 static void halve1Dimage_ubyte(GLint
, GLuint
, GLuint
,const GLubyte
*,
226 GLubyte
*, GLint
, GLint
, GLint
);
227 static void halve1Dimage_byte(GLint
, GLuint
, GLuint
,const GLbyte
*, GLbyte
*,
228 GLint
, GLint
, GLint
);
229 static void halve1Dimage_ushort(GLint
, GLuint
, GLuint
, const GLushort
*,
230 GLushort
*, GLint
, GLint
, GLint
, GLint
);
231 static void halve1Dimage_short(GLint
, GLuint
, GLuint
,const GLshort
*, GLshort
*,
232 GLint
, GLint
, GLint
, GLint
);
233 static void halve1Dimage_uint(GLint
, GLuint
, GLuint
, const GLuint
*, GLuint
*,
234 GLint
, GLint
, GLint
, GLint
);
235 static void halve1Dimage_int(GLint
, GLuint
, GLuint
, const GLint
*, GLint
*,
236 GLint
, GLint
, GLint
, GLint
);
237 static void halve1Dimage_float(GLint
, GLuint
, GLuint
, const GLfloat
*, GLfloat
*,
238 GLint
, GLint
, GLint
, GLint
);
240 static GLint
imageSize3D(GLint
, GLint
, GLint
, GLenum
,GLenum
);
241 static void fillImage3D(const PixelStorageModes
*, GLint
, GLint
, GLint
,GLenum
,
242 GLenum
, GLboolean
, const void *, GLushort
*);
243 static void emptyImage3D(const PixelStorageModes
*,
244 GLint
, GLint
, GLint
, GLenum
,
246 const GLushort
*, void *);
247 static void scaleInternal3D(GLint
, GLint
, GLint
, GLint
, const GLushort
*,
248 GLint
, GLint
, GLint
, GLushort
*);
250 static void retrieveStoreModes(PixelStorageModes
*psm
)
252 glGetIntegerv(GL_UNPACK_ALIGNMENT
, &psm
->unpack_alignment
);
253 glGetIntegerv(GL_UNPACK_ROW_LENGTH
, &psm
->unpack_row_length
);
254 glGetIntegerv(GL_UNPACK_SKIP_ROWS
, &psm
->unpack_skip_rows
);
255 glGetIntegerv(GL_UNPACK_SKIP_PIXELS
, &psm
->unpack_skip_pixels
);
256 glGetIntegerv(GL_UNPACK_LSB_FIRST
, &psm
->unpack_lsb_first
);
257 glGetIntegerv(GL_UNPACK_SWAP_BYTES
, &psm
->unpack_swap_bytes
);
259 glGetIntegerv(GL_PACK_ALIGNMENT
, &psm
->pack_alignment
);
260 glGetIntegerv(GL_PACK_ROW_LENGTH
, &psm
->pack_row_length
);
261 glGetIntegerv(GL_PACK_SKIP_ROWS
, &psm
->pack_skip_rows
);
262 glGetIntegerv(GL_PACK_SKIP_PIXELS
, &psm
->pack_skip_pixels
);
263 glGetIntegerv(GL_PACK_LSB_FIRST
, &psm
->pack_lsb_first
);
264 glGetIntegerv(GL_PACK_SWAP_BYTES
, &psm
->pack_swap_bytes
);
267 static void retrieveStoreModes3D(PixelStorageModes
*psm
)
269 glGetIntegerv(GL_UNPACK_ALIGNMENT
, &psm
->unpack_alignment
);
270 glGetIntegerv(GL_UNPACK_ROW_LENGTH
, &psm
->unpack_row_length
);
271 glGetIntegerv(GL_UNPACK_SKIP_ROWS
, &psm
->unpack_skip_rows
);
272 glGetIntegerv(GL_UNPACK_SKIP_PIXELS
, &psm
->unpack_skip_pixels
);
273 glGetIntegerv(GL_UNPACK_LSB_FIRST
, &psm
->unpack_lsb_first
);
274 glGetIntegerv(GL_UNPACK_SWAP_BYTES
, &psm
->unpack_swap_bytes
);
275 glGetIntegerv(GL_UNPACK_SKIP_IMAGES
, &psm
->unpack_skip_images
);
276 glGetIntegerv(GL_UNPACK_IMAGE_HEIGHT
, &psm
->unpack_image_height
);
278 glGetIntegerv(GL_PACK_ALIGNMENT
, &psm
->pack_alignment
);
279 glGetIntegerv(GL_PACK_ROW_LENGTH
, &psm
->pack_row_length
);
280 glGetIntegerv(GL_PACK_SKIP_ROWS
, &psm
->pack_skip_rows
);
281 glGetIntegerv(GL_PACK_SKIP_PIXELS
, &psm
->pack_skip_pixels
);
282 glGetIntegerv(GL_PACK_LSB_FIRST
, &psm
->pack_lsb_first
);
283 glGetIntegerv(GL_PACK_SWAP_BYTES
, &psm
->pack_swap_bytes
);
284 glGetIntegerv(GL_PACK_SKIP_IMAGES
, &psm
->pack_skip_images
);
285 glGetIntegerv(GL_PACK_IMAGE_HEIGHT
, &psm
->pack_image_height
);
288 static int computeLog(GLuint value
)
295 if (value
== 0) return -1;
300 if (value
!= 1) return -1;
309 ** Compute the nearest power of 2 number. This algorithm is a little
310 ** strange, but it works quite well.
312 static int nearestPower(GLuint value
)
319 if (value
== 0) return -1;
324 } else if (value
== 3) {
332 #define __GLU_SWAP_2_BYTES(s)\
333 (GLushort)(((GLushort)((const GLubyte*)(s))[1])<<8 | ((const GLubyte*)(s))[0])
335 #define __GLU_SWAP_4_BYTES(s)\
336 (GLuint)(((GLuint)((const GLubyte*)(s))[3])<<24 | \
337 ((GLuint)((const GLubyte*)(s))[2])<<16 | \
338 ((GLuint)((const GLubyte*)(s))[1])<<8 | ((const GLubyte*)(s))[0])
340 static void halveImage(GLint components
, GLuint width
, GLuint height
,
341 const GLushort
*datain
, GLushort
*dataout
)
344 int newwidth
, newheight
;
349 newwidth
= width
/ 2;
350 newheight
= height
/ 2;
351 delta
= width
* components
;
356 for (i
= 0; i
< newheight
; i
++) {
357 for (j
= 0; j
< newwidth
; j
++) {
358 for (k
= 0; k
< components
; k
++) {
359 s
[0] = (t
[0] + t
[components
] + t
[delta
] +
360 t
[delta
+components
] + 2) / 4;
369 static void halveImage_ubyte(GLint components
, GLuint width
, GLuint height
,
370 const GLubyte
*datain
, GLubyte
*dataout
,
371 GLint element_size
, GLint ysize
, GLint group_size
)
374 int newwidth
, newheight
;
379 /* handle case where there is only 1 column/row */
380 if (width
== 1 || height
== 1) {
381 assert( !(width
== 1 && height
== 1) ); /* can't be 1x1 */
382 halve1Dimage_ubyte(components
,width
,height
,datain
,dataout
,
383 element_size
,ysize
,group_size
);
387 newwidth
= width
/ 2;
388 newheight
= height
/ 2;
389 padBytes
= ysize
- (width
*group_size
);
391 t
= (const char *)datain
;
394 for (i
= 0; i
< newheight
; i
++) {
395 for (j
= 0; j
< newwidth
; j
++) {
396 for (k
= 0; k
< components
; k
++) {
397 s
[0] = (*(const GLubyte
*)t
+
398 *(const GLubyte
*)(t
+group_size
) +
399 *(const GLubyte
*)(t
+ysize
) +
400 *(const GLubyte
*)(t
+ysize
+group_size
) + 2) / 4;
401 s
++; t
+= element_size
;
411 static void halve1Dimage_ubyte(GLint components
, GLuint width
, GLuint height
,
412 const GLubyte
*dataIn
, GLubyte
*dataOut
,
413 GLint element_size
, GLint ysize
,
416 GLint halfWidth
= width
/ 2;
417 GLint halfHeight
= height
/ 2;
418 const char *src
= (const char *) dataIn
;
419 GLubyte
*dest
= dataOut
;
422 assert(width
== 1 || height
== 1); /* must be 1D */
423 assert(width
!= height
); /* can't be square */
425 if (height
== 1) { /* 1 row */
426 assert(width
!= 1); /* widthxheight can't be 1x1 */
429 for (jj
= 0; jj
< halfWidth
; jj
++) {
431 for (kk
= 0; kk
< components
; kk
++) {
432 *dest
= (*(const GLubyte
*)src
+
433 *(const GLubyte
*)(src
+group_size
)) / 2;
438 src
+= group_size
; /* skip to next 2 */
441 int padBytes
= ysize
- (width
*group_size
);
442 src
+= padBytes
; /* for assertion only */
445 else if (width
== 1) { /* 1 column */
446 int padBytes
= ysize
- (width
* group_size
);
447 assert(height
!= 1); /* widthxheight can't be 1x1 */
449 /* one vertical column with possible pad bytes per row */
450 /* average two at a time */
452 for (jj
= 0; jj
< halfHeight
; jj
++) {
454 for (kk
= 0; kk
< components
; kk
++) {
455 *dest
= (*(const GLubyte
*)src
+ *(const GLubyte
*)(src
+ysize
)) / 2;
460 src
+= padBytes
; /* add pad bytes, if any, to get to end to row */
465 assert(src
== &((const char *)dataIn
)[ysize
*height
]);
466 assert((char *)dest
== &((char *)dataOut
)
467 [components
* element_size
* halfWidth
* halfHeight
]);
468 } /* halve1Dimage_ubyte() */
470 static void halveImage_byte(GLint components
, GLuint width
, GLuint height
,
471 const GLbyte
*datain
, GLbyte
*dataout
,
473 GLint ysize
, GLint group_size
)
476 int newwidth
, newheight
;
481 /* handle case where there is only 1 column/row */
482 if (width
== 1 || height
== 1) {
483 assert( !(width
== 1 && height
== 1) ); /* can't be 1x1 */
484 halve1Dimage_byte(components
,width
,height
,datain
,dataout
,
485 element_size
,ysize
,group_size
);
489 newwidth
= width
/ 2;
490 newheight
= height
/ 2;
491 padBytes
= ysize
- (width
*group_size
);
493 t
= (const char *)datain
;
496 for (i
= 0; i
< newheight
; i
++) {
497 for (j
= 0; j
< newwidth
; j
++) {
498 for (k
= 0; k
< components
; k
++) {
499 s
[0] = (*(const GLbyte
*)t
+
500 *(const GLbyte
*)(t
+group_size
) +
501 *(const GLbyte
*)(t
+ysize
) +
502 *(const GLbyte
*)(t
+ysize
+group_size
) + 2) / 4;
503 s
++; t
+= element_size
;
512 static void halve1Dimage_byte(GLint components
, GLuint width
, GLuint height
,
513 const GLbyte
*dataIn
, GLbyte
*dataOut
,
514 GLint element_size
,GLint ysize
, GLint group_size
)
516 GLint halfWidth
= width
/ 2;
517 GLint halfHeight
= height
/ 2;
518 const char *src
= (const char *) dataIn
;
519 GLbyte
*dest
= dataOut
;
522 assert(width
== 1 || height
== 1); /* must be 1D */
523 assert(width
!= height
); /* can't be square */
525 if (height
== 1) { /* 1 row */
526 assert(width
!= 1); /* widthxheight can't be 1x1 */
529 for (jj
= 0; jj
< halfWidth
; jj
++) {
531 for (kk
= 0; kk
< components
; kk
++) {
532 *dest
= (*(const GLbyte
*)src
+ *(const GLbyte
*)(src
+group_size
)) / 2;
537 src
+= group_size
; /* skip to next 2 */
540 int padBytes
= ysize
- (width
*group_size
);
541 src
+= padBytes
; /* for assertion only */
544 else if (width
== 1) { /* 1 column */
545 int padBytes
= ysize
- (width
* group_size
);
546 assert(height
!= 1); /* widthxheight can't be 1x1 */
548 /* one vertical column with possible pad bytes per row */
549 /* average two at a time */
551 for (jj
= 0; jj
< halfHeight
; jj
++) {
553 for (kk
= 0; kk
< components
; kk
++) {
554 *dest
= (*(const GLbyte
*)src
+ *(const GLbyte
*)(src
+ysize
)) / 2;
559 src
+= padBytes
; /* add pad bytes, if any, to get to end to row */
563 assert(src
== &((const char *)dataIn
)[ysize
*height
]);
566 assert((char *)dest
== &((char *)dataOut
)
567 [components
* element_size
* halfWidth
* halfHeight
]);
568 } /* halve1Dimage_byte() */
570 static void halveImage_ushort(GLint components
, GLuint width
, GLuint height
,
571 const GLushort
*datain
, GLushort
*dataout
,
572 GLint element_size
, GLint ysize
, GLint group_size
,
576 int newwidth
, newheight
;
581 /* handle case where there is only 1 column/row */
582 if (width
== 1 || height
== 1) {
583 assert( !(width
== 1 && height
== 1) ); /* can't be 1x1 */
584 halve1Dimage_ushort(components
,width
,height
,datain
,dataout
,
585 element_size
,ysize
,group_size
, myswap_bytes
);
589 newwidth
= width
/ 2;
590 newheight
= height
/ 2;
591 padBytes
= ysize
- (width
*group_size
);
593 t
= (const char *)datain
;
597 for (i
= 0; i
< newheight
; i
++) {
598 for (j
= 0; j
< newwidth
; j
++) {
599 for (k
= 0; k
< components
; k
++) {
600 s
[0] = (*(const GLushort
*)t
+
601 *(const GLushort
*)(t
+group_size
) +
602 *(const GLushort
*)(t
+ysize
) +
603 *(const GLushort
*)(t
+ysize
+group_size
) + 2) / 4;
604 s
++; t
+= element_size
;
612 for (i
= 0; i
< newheight
; i
++) {
613 for (j
= 0; j
< newwidth
; j
++) {
614 for (k
= 0; k
< components
; k
++) {
615 s
[0] = (__GLU_SWAP_2_BYTES(t
) +
616 __GLU_SWAP_2_BYTES(t
+group_size
) +
617 __GLU_SWAP_2_BYTES(t
+ysize
) +
618 __GLU_SWAP_2_BYTES(t
+ysize
+group_size
)+ 2)/4;
619 s
++; t
+= element_size
;
628 static void halve1Dimage_ushort(GLint components
, GLuint width
, GLuint height
,
629 const GLushort
*dataIn
, GLushort
*dataOut
,
630 GLint element_size
, GLint ysize
,
631 GLint group_size
, GLint myswap_bytes
)
633 GLint halfWidth
= width
/ 2;
634 GLint halfHeight
= height
/ 2;
635 const char *src
= (const char *) dataIn
;
636 GLushort
*dest
= dataOut
;
639 assert(width
== 1 || height
== 1); /* must be 1D */
640 assert(width
!= height
); /* can't be square */
642 if (height
== 1) { /* 1 row */
643 assert(width
!= 1); /* widthxheight can't be 1x1 */
646 for (jj
= 0; jj
< halfWidth
; jj
++) {
648 for (kk
= 0; kk
< components
; kk
++) {
650 GLushort ushort
[BOX2
];
652 ushort
[0]= __GLU_SWAP_2_BYTES(src
);
653 ushort
[1]= __GLU_SWAP_2_BYTES(src
+group_size
);
656 ushort
[0]= *(const GLushort
*)src
;
657 ushort
[1]= *(const GLushort
*)(src
+group_size
);
660 *dest
= (ushort
[0] + ushort
[1]) / 2;
664 src
+= group_size
; /* skip to next 2 */
667 int padBytes
= ysize
- (width
*group_size
);
668 src
+= padBytes
; /* for assertion only */
671 else if (width
== 1) { /* 1 column */
672 int padBytes
= ysize
- (width
* group_size
);
673 assert(height
!= 1); /* widthxheight can't be 1x1 */
675 /* one vertical column with possible pad bytes per row */
676 /* average two at a time */
678 for (jj
= 0; jj
< halfHeight
; jj
++) {
680 for (kk
= 0; kk
< components
; kk
++) {
682 GLushort ushort
[BOX2
];
684 ushort
[0]= __GLU_SWAP_2_BYTES(src
);
685 ushort
[1]= __GLU_SWAP_2_BYTES(src
+ysize
);
688 ushort
[0]= *(const GLushort
*)src
;
689 ushort
[1]= *(const GLushort
*)(src
+ysize
);
691 *dest
= (ushort
[0] + ushort
[1]) / 2;
696 src
+= padBytes
; /* add pad bytes, if any, to get to end to row */
700 assert(src
== &((const char *)dataIn
)[ysize
*height
]);
703 assert((char *)dest
== &((char *)dataOut
)
704 [components
* element_size
* halfWidth
* halfHeight
]);
706 } /* halve1Dimage_ushort() */
709 static void halveImage_short(GLint components
, GLuint width
, GLuint height
,
710 const GLshort
*datain
, GLshort
*dataout
,
711 GLint element_size
, GLint ysize
, GLint group_size
,
715 int newwidth
, newheight
;
720 /* handle case where there is only 1 column/row */
721 if (width
== 1 || height
== 1) {
722 assert( !(width
== 1 && height
== 1) ); /* can't be 1x1 */
723 halve1Dimage_short(components
,width
,height
,datain
,dataout
,
724 element_size
,ysize
,group_size
, myswap_bytes
);
728 newwidth
= width
/ 2;
729 newheight
= height
/ 2;
730 padBytes
= ysize
- (width
*group_size
);
732 t
= (const char *)datain
;
736 for (i
= 0; i
< newheight
; i
++) {
737 for (j
= 0; j
< newwidth
; j
++) {
738 for (k
= 0; k
< components
; k
++) {
739 s
[0] = (*(const GLshort
*)t
+
740 *(const GLshort
*)(t
+group_size
) +
741 *(const GLshort
*)(t
+ysize
) +
742 *(const GLshort
*)(t
+ysize
+group_size
) + 2) / 4;
743 s
++; t
+= element_size
;
751 for (i
= 0; i
< newheight
; i
++) {
752 for (j
= 0; j
< newwidth
; j
++) {
753 for (k
= 0; k
< components
; k
++) {
756 b
= __GLU_SWAP_2_BYTES(t
);
757 buf
= *(const GLshort
*)&b
;
758 b
= __GLU_SWAP_2_BYTES(t
+group_size
);
759 buf
+= *(const GLshort
*)&b
;
760 b
= __GLU_SWAP_2_BYTES(t
+ysize
);
761 buf
+= *(const GLshort
*)&b
;
762 b
= __GLU_SWAP_2_BYTES(t
+ysize
+group_size
);
763 buf
+= *(const GLshort
*)&b
;
764 s
[0] = (GLshort
)((buf
+2)/4);
765 s
++; t
+= element_size
;
774 static void halve1Dimage_short(GLint components
, GLuint width
, GLuint height
,
775 const GLshort
*dataIn
, GLshort
*dataOut
,
776 GLint element_size
, GLint ysize
,
777 GLint group_size
, GLint myswap_bytes
)
779 GLint halfWidth
= width
/ 2;
780 GLint halfHeight
= height
/ 2;
781 const char *src
= (const char *) dataIn
;
782 GLshort
*dest
= dataOut
;
785 assert(width
== 1 || height
== 1); /* must be 1D */
786 assert(width
!= height
); /* can't be square */
788 if (height
== 1) { /* 1 row */
789 assert(width
!= 1); /* widthxheight can't be 1x1 */
792 for (jj
= 0; jj
< halfWidth
; jj
++) {
794 for (kk
= 0; kk
< components
; kk
++) {
796 GLshort sshort
[BOX2
];
798 sshort
[0]= __GLU_SWAP_2_BYTES(src
);
799 sshort
[1]= __GLU_SWAP_2_BYTES(src
+group_size
);
802 sshort
[0]= *(const GLshort
*)src
;
803 sshort
[1]= *(const GLshort
*)(src
+group_size
);
806 *dest
= (sshort
[0] + sshort
[1]) / 2;
810 src
+= group_size
; /* skip to next 2 */
813 int padBytes
= ysize
- (width
*group_size
);
814 src
+= padBytes
; /* for assertion only */
817 else if (width
== 1) { /* 1 column */
818 int padBytes
= ysize
- (width
* group_size
);
819 assert(height
!= 1); /* widthxheight can't be 1x1 */
821 /* one vertical column with possible pad bytes per row */
822 /* average two at a time */
824 for (jj
= 0; jj
< halfHeight
; jj
++) {
826 for (kk
= 0; kk
< components
; kk
++) {
828 GLshort sshort
[BOX2
];
830 sshort
[0]= __GLU_SWAP_2_BYTES(src
);
831 sshort
[1]= __GLU_SWAP_2_BYTES(src
+ysize
);
834 sshort
[0]= *(const GLshort
*)src
;
835 sshort
[1]= *(const GLshort
*)(src
+ysize
);
837 *dest
= (sshort
[0] + sshort
[1]) / 2;
842 src
+= padBytes
; /* add pad bytes, if any, to get to end to row */
846 assert(src
== &((const char *)dataIn
)[ysize
*height
]);
849 assert((char *)dest
== &((char *)dataOut
)
850 [components
* element_size
* halfWidth
* halfHeight
]);
852 } /* halve1Dimage_short() */
855 static void halveImage_uint(GLint components
, GLuint width
, GLuint height
,
856 const GLuint
*datain
, GLuint
*dataout
,
857 GLint element_size
, GLint ysize
, GLint group_size
,
861 int newwidth
, newheight
;
866 /* handle case where there is only 1 column/row */
867 if (width
== 1 || height
== 1) {
868 assert( !(width
== 1 && height
== 1) ); /* can't be 1x1 */
869 halve1Dimage_uint(components
,width
,height
,datain
,dataout
,
870 element_size
,ysize
,group_size
, myswap_bytes
);
874 newwidth
= width
/ 2;
875 newheight
= height
/ 2;
876 padBytes
= ysize
- (width
*group_size
);
878 t
= (const char *)datain
;
882 for (i
= 0; i
< newheight
; i
++) {
883 for (j
= 0; j
< newwidth
; j
++) {
884 for (k
= 0; k
< components
; k
++) {
885 /* need to cast to double to hold large unsigned ints */
886 s
[0] = ((double)*(const GLuint
*)t
+
887 (double)*(const GLuint
*)(t
+group_size
) +
888 (double)*(const GLuint
*)(t
+ysize
) +
889 (double)*(const GLuint
*)(t
+ysize
+group_size
))/4 + 0.5;
890 s
++; t
+= element_size
;
899 for (i
= 0; i
< newheight
; i
++) {
900 for (j
= 0; j
< newwidth
; j
++) {
901 for (k
= 0; k
< components
; k
++) {
902 /* need to cast to double to hold large unsigned ints */
904 buf
= (GLdouble
)__GLU_SWAP_4_BYTES(t
) +
905 (GLdouble
)__GLU_SWAP_4_BYTES(t
+group_size
) +
906 (GLdouble
)__GLU_SWAP_4_BYTES(t
+ysize
) +
907 (GLdouble
)__GLU_SWAP_4_BYTES(t
+ysize
+group_size
);
908 s
[0] = (GLuint
)(buf
/4 + 0.5);
910 s
++; t
+= element_size
;
920 static void halve1Dimage_uint(GLint components
, GLuint width
, GLuint height
,
921 const GLuint
*dataIn
, GLuint
*dataOut
,
922 GLint element_size
, GLint ysize
,
923 GLint group_size
, GLint myswap_bytes
)
925 GLint halfWidth
= width
/ 2;
926 GLint halfHeight
= height
/ 2;
927 const char *src
= (const char *) dataIn
;
928 GLuint
*dest
= dataOut
;
931 assert(width
== 1 || height
== 1); /* must be 1D */
932 assert(width
!= height
); /* can't be square */
934 if (height
== 1) { /* 1 row */
935 assert(width
!= 1); /* widthxheight can't be 1x1 */
938 for (jj
= 0; jj
< halfWidth
; jj
++) {
940 for (kk
= 0; kk
< components
; kk
++) {
944 uint
[0]= __GLU_SWAP_4_BYTES(src
);
945 uint
[1]= __GLU_SWAP_4_BYTES(src
+group_size
);
948 uint
[0]= *(const GLuint
*)src
;
949 uint
[1]= *(const GLuint
*)(src
+group_size
);
951 *dest
= ((double)uint
[0]+(double)uint
[1])/2.0;
956 src
+= group_size
; /* skip to next 2 */
959 int padBytes
= ysize
- (width
*group_size
);
960 src
+= padBytes
; /* for assertion only */
963 else if (width
== 1) { /* 1 column */
964 int padBytes
= ysize
- (width
* group_size
);
965 assert(height
!= 1); /* widthxheight can't be 1x1 */
967 /* one vertical column with possible pad bytes per row */
968 /* average two at a time */
970 for (jj
= 0; jj
< halfHeight
; jj
++) {
972 for (kk
= 0; kk
< components
; kk
++) {
976 uint
[0]= __GLU_SWAP_4_BYTES(src
);
977 uint
[1]= __GLU_SWAP_4_BYTES(src
+ysize
);
980 uint
[0]= *(const GLuint
*)src
;
981 uint
[1]= *(const GLuint
*)(src
+ysize
);
983 *dest
= ((double)uint
[0]+(double)uint
[1])/2.0;
988 src
+= padBytes
; /* add pad bytes, if any, to get to end to row */
992 assert(src
== &((const char *)dataIn
)[ysize
*height
]);
995 assert((char *)dest
== &((char *)dataOut
)
996 [components
* element_size
* halfWidth
* halfHeight
]);
998 } /* halve1Dimage_uint() */
1000 static void halveImage_int(GLint components
, GLuint width
, GLuint height
,
1001 const GLint
*datain
, GLint
*dataout
, GLint element_size
,
1002 GLint ysize
, GLint group_size
, GLint myswap_bytes
)
1005 int newwidth
, newheight
;
1010 /* handle case where there is only 1 column/row */
1011 if (width
== 1 || height
== 1) {
1012 assert( !(width
== 1 && height
== 1) ); /* can't be 1x1 */
1013 halve1Dimage_int(components
,width
,height
,datain
,dataout
,
1014 element_size
,ysize
,group_size
, myswap_bytes
);
1018 newwidth
= width
/ 2;
1019 newheight
= height
/ 2;
1020 padBytes
= ysize
- (width
*group_size
);
1022 t
= (const char *)datain
;
1024 /* Piece o' cake! */
1026 for (i
= 0; i
< newheight
; i
++) {
1027 for (j
= 0; j
< newwidth
; j
++) {
1028 for (k
= 0; k
< components
; k
++) {
1029 s
[0] = ((float)*(const GLint
*)t
+
1030 (float)*(const GLint
*)(t
+group_size
) +
1031 (float)*(const GLint
*)(t
+ysize
) +
1032 (float)*(const GLint
*)(t
+ysize
+group_size
))/4 + 0.5;
1033 s
++; t
+= element_size
;
1041 for (i
= 0; i
< newheight
; i
++) {
1042 for (j
= 0; j
< newwidth
; j
++) {
1043 for (k
= 0; k
< components
; k
++) {
1046 b
= __GLU_SWAP_4_BYTES(t
);
1048 b
= __GLU_SWAP_4_BYTES(t
+group_size
);
1050 b
= __GLU_SWAP_4_BYTES(t
+ysize
);
1052 b
= __GLU_SWAP_4_BYTES(t
+ysize
+group_size
);
1054 s
[0] = (GLint
)(buf
/4 + 0.5);
1056 s
++; t
+= element_size
;
1066 static void halve1Dimage_int(GLint components
, GLuint width
, GLuint height
,
1067 const GLint
*dataIn
, GLint
*dataOut
,
1068 GLint element_size
, GLint ysize
,
1069 GLint group_size
, GLint myswap_bytes
)
1071 GLint halfWidth
= width
/ 2;
1072 GLint halfHeight
= height
/ 2;
1073 const char *src
= (const char *) dataIn
;
1074 GLint
*dest
= dataOut
;
1077 assert(width
== 1 || height
== 1); /* must be 1D */
1078 assert(width
!= height
); /* can't be square */
1080 if (height
== 1) { /* 1 row */
1081 assert(width
!= 1); /* widthxheight can't be 1x1 */
1084 for (jj
= 0; jj
< halfWidth
; jj
++) {
1086 for (kk
= 0; kk
< components
; kk
++) {
1090 uint
[0]= __GLU_SWAP_4_BYTES(src
);
1091 uint
[1]= __GLU_SWAP_4_BYTES(src
+group_size
);
1094 uint
[0]= *(const GLuint
*)src
;
1095 uint
[1]= *(const GLuint
*)(src
+group_size
);
1097 *dest
= ((float)uint
[0]+(float)uint
[1])/2.0;
1102 src
+= group_size
; /* skip to next 2 */
1105 int padBytes
= ysize
- (width
*group_size
);
1106 src
+= padBytes
; /* for assertion only */
1109 else if (width
== 1) { /* 1 column */
1110 int padBytes
= ysize
- (width
* group_size
);
1111 assert(height
!= 1); /* widthxheight can't be 1x1 */
1113 /* one vertical column with possible pad bytes per row */
1114 /* average two at a time */
1116 for (jj
= 0; jj
< halfHeight
; jj
++) {
1118 for (kk
= 0; kk
< components
; kk
++) {
1122 uint
[0]= __GLU_SWAP_4_BYTES(src
);
1123 uint
[1]= __GLU_SWAP_4_BYTES(src
+ysize
);
1126 uint
[0]= *(const GLuint
*)src
;
1127 uint
[1]= *(const GLuint
*)(src
+ysize
);
1129 *dest
= ((float)uint
[0]+(float)uint
[1])/2.0;
1134 src
+= padBytes
; /* add pad bytes, if any, to get to end to row */
1138 assert(src
== &((const char *)dataIn
)[ysize
*height
]);
1141 assert((char *)dest
== &((char *)dataOut
)
1142 [components
* element_size
* halfWidth
* halfHeight
]);
1144 } /* halve1Dimage_int() */
1147 static void halveImage_float(GLint components
, GLuint width
, GLuint height
,
1148 const GLfloat
*datain
, GLfloat
*dataout
,
1149 GLint element_size
, GLint ysize
, GLint group_size
,
1153 int newwidth
, newheight
;
1158 /* handle case where there is only 1 column/row */
1159 if (width
== 1 || height
== 1) {
1160 assert( !(width
== 1 && height
== 1) ); /* can't be 1x1 */
1161 halve1Dimage_float(components
,width
,height
,datain
,dataout
,
1162 element_size
,ysize
,group_size
, myswap_bytes
);
1166 newwidth
= width
/ 2;
1167 newheight
= height
/ 2;
1168 padBytes
= ysize
- (width
*group_size
);
1170 t
= (const char *)datain
;
1172 /* Piece o' cake! */
1174 for (i
= 0; i
< newheight
; i
++) {
1175 for (j
= 0; j
< newwidth
; j
++) {
1176 for (k
= 0; k
< components
; k
++) {
1177 s
[0] = (*(const GLfloat
*)t
+
1178 *(const GLfloat
*)(t
+group_size
) +
1179 *(const GLfloat
*)(t
+ysize
) +
1180 *(const GLfloat
*)(t
+ysize
+group_size
)) / 4;
1181 s
++; t
+= element_size
;
1189 for (i
= 0; i
< newheight
; i
++) {
1190 for (j
= 0; j
< newwidth
; j
++) {
1191 for (k
= 0; k
< components
; k
++) {
1192 union { GLuint b
; GLfloat f
; } swapbuf
;
1193 swapbuf
.b
= __GLU_SWAP_4_BYTES(t
);
1195 swapbuf
.b
= __GLU_SWAP_4_BYTES(t
+group_size
);
1197 swapbuf
.b
= __GLU_SWAP_4_BYTES(t
+ysize
);
1199 swapbuf
.b
= __GLU_SWAP_4_BYTES(t
+ysize
+group_size
);
1202 s
++; t
+= element_size
;
1212 static void halve1Dimage_float(GLint components
, GLuint width
, GLuint height
,
1213 const GLfloat
*dataIn
, GLfloat
*dataOut
,
1214 GLint element_size
, GLint ysize
,
1215 GLint group_size
, GLint myswap_bytes
)
1217 GLint halfWidth
= width
/ 2;
1218 GLint halfHeight
= height
/ 2;
1219 const char *src
= (const char *) dataIn
;
1220 GLfloat
*dest
= dataOut
;
1223 assert(width
== 1 || height
== 1); /* must be 1D */
1224 assert(width
!= height
); /* can't be square */
1226 if (height
== 1) { /* 1 row */
1227 assert(width
!= 1); /* widthxheight can't be 1x1 */
1230 for (jj
= 0; jj
< halfWidth
; jj
++) {
1232 for (kk
= 0; kk
< components
; kk
++) {
1234 GLfloat sfloat
[BOX2
];
1236 sfloat
[0]= __GLU_SWAP_4_BYTES(src
);
1237 sfloat
[1]= __GLU_SWAP_4_BYTES(src
+group_size
);
1240 sfloat
[0]= *(const GLfloat
*)src
;
1241 sfloat
[1]= *(const GLfloat
*)(src
+group_size
);
1244 *dest
= (sfloat
[0] + sfloat
[1]) / 2.0;
1248 src
+= group_size
; /* skip to next 2 */
1251 int padBytes
= ysize
- (width
*group_size
);
1252 src
+= padBytes
; /* for assertion only */
1255 else if (width
== 1) { /* 1 column */
1256 int padBytes
= ysize
- (width
* group_size
);
1257 assert(height
!= 1); /* widthxheight can't be 1x1 */
1259 /* one vertical column with possible pad bytes per row */
1260 /* average two at a time */
1262 for (jj
= 0; jj
< halfHeight
; jj
++) {
1264 for (kk
= 0; kk
< components
; kk
++) {
1266 GLfloat sfloat
[BOX2
];
1268 sfloat
[0]= __GLU_SWAP_4_BYTES(src
);
1269 sfloat
[1]= __GLU_SWAP_4_BYTES(src
+ysize
);
1272 sfloat
[0]= *(const GLfloat
*)src
;
1273 sfloat
[1]= *(const GLfloat
*)(src
+ysize
);
1275 *dest
= (sfloat
[0] + sfloat
[1]) / 2.0;
1280 src
+= padBytes
; /* add pad bytes, if any, to get to end to row */
1281 src
+= ysize
; /* skip to odd row */
1285 assert(src
== &((const char *)dataIn
)[ysize
*height
]);
1286 assert((char *)dest
== &((char *)dataOut
)
1287 [components
* element_size
* halfWidth
* halfHeight
]);
1288 } /* halve1Dimage_float() */
1290 static void scale_internal(GLint components
, GLint widthin
, GLint heightin
,
1291 const GLushort
*datain
,
1292 GLint widthout
, GLint heightout
,
1295 float x
, lowx
, highx
, convx
, halfconvx
;
1296 float y
, lowy
, highy
, convy
, halfconvy
;
1297 float xpercent
,ypercent
;
1299 /* Max components in a format is 4, so... */
1302 int i
,j
,k
,yint
,xint
,xindex
,yindex
;
1305 if (widthin
== widthout
*2 && heightin
== heightout
*2) {
1306 halveImage(components
, widthin
, heightin
, datain
, dataout
);
1309 convy
= (float) heightin
/heightout
;
1310 convx
= (float) widthin
/widthout
;
1311 halfconvx
= convx
/2;
1312 halfconvy
= convy
/2;
1313 for (i
= 0; i
< heightout
; i
++) {
1314 y
= convy
* (i
+0.5);
1315 if (heightin
> heightout
) {
1316 highy
= y
+ halfconvy
;
1317 lowy
= y
- halfconvy
;
1322 for (j
= 0; j
< widthout
; j
++) {
1323 x
= convx
* (j
+0.5);
1324 if (widthin
> widthout
) {
1325 highx
= x
+ halfconvx
;
1326 lowx
= x
- halfconvx
;
1333 ** Ok, now apply box filter to box that goes from (lowx, lowy)
1334 ** to (highx, highy) on input data into this pixel on output
1337 totals
[0] = totals
[1] = totals
[2] = totals
[3] = 0.0;
1343 yindex
= (yint
+ heightin
) % heightin
;
1344 if (highy
< yint
+1) {
1345 ypercent
= highy
- y
;
1347 ypercent
= yint
+1 - y
;
1354 xindex
= (xint
+ widthin
) % widthin
;
1355 if (highx
< xint
+1) {
1356 xpercent
= highx
- x
;
1358 xpercent
= xint
+1 - x
;
1361 percent
= xpercent
* ypercent
;
1363 temp
= (xindex
+ (yindex
* widthin
)) * components
;
1364 for (k
= 0; k
< components
; k
++) {
1365 totals
[k
] += datain
[temp
+ k
] * percent
;
1375 temp
= (j
+ (i
* widthout
)) * components
;
1376 for (k
= 0; k
< components
; k
++) {
1377 /* totals[] should be rounded in the case of enlarging an RGB
1378 * ramp when the type is 332 or 4444
1380 dataout
[temp
+ k
] = (totals
[k
]+0.5)/area
;
1386 static void scale_internal_ubyte(GLint components
, GLint widthin
,
1387 GLint heightin
, const GLubyte
*datain
,
1388 GLint widthout
, GLint heightout
,
1389 GLubyte
*dataout
, GLint element_size
,
1390 GLint ysize
, GLint group_size
)
1395 /* Max components in a format is 4, so... */
1400 const char *temp
, *temp0
;
1401 const char *temp_index
;
1404 int lowx_int
, highx_int
, lowy_int
, highy_int
;
1405 float x_percent
, y_percent
;
1406 float lowx_float
, highx_float
, lowy_float
, highy_float
;
1407 float convy_float
, convx_float
;
1408 int convy_int
, convx_int
;
1410 const char *left
, *right
;
1412 if (widthin
== widthout
*2 && heightin
== heightout
*2) {
1413 halveImage_ubyte(components
, widthin
, heightin
,
1414 (const GLubyte
*)datain
, (GLubyte
*)dataout
,
1415 element_size
, ysize
, group_size
);
1418 convy
= (float) heightin
/heightout
;
1419 convx
= (float) widthin
/widthout
;
1420 convy_int
= floor(convy
);
1421 convy_float
= convy
- convy_int
;
1422 convx_int
= floor(convx
);
1423 convx_float
= convx
- convx_int
;
1425 area
= convx
* convy
;
1429 highy_int
= convy_int
;
1430 highy_float
= convy_float
;
1432 for (i
= 0; i
< heightout
; i
++) {
1433 /* Clamp here to be sure we don't read beyond input buffer. */
1434 if (highy_int
>= heightin
)
1435 highy_int
= heightin
- 1;
1438 highx_int
= convx_int
;
1439 highx_float
= convx_float
;
1441 for (j
= 0; j
< widthout
; j
++) {
1444 ** Ok, now apply box filter to box that goes from (lowx, lowy)
1445 ** to (highx, highy) on input data into this pixel on output
1448 totals
[0] = totals
[1] = totals
[2] = totals
[3] = 0.0;
1450 /* calculate the value for pixels in the 1st row */
1451 xindex
= lowx_int
*group_size
;
1452 if((highy_int
>lowy_int
) && (highx_int
>lowx_int
)) {
1454 y_percent
= 1-lowy_float
;
1455 temp
= (const char *)datain
+ xindex
+ lowy_int
* ysize
;
1456 percent
= y_percent
* (1-lowx_float
);
1457 for (k
= 0, temp_index
= temp
; k
< components
;
1458 k
++, temp_index
+= element_size
) {
1459 totals
[k
] += (GLubyte
)(*(temp_index
)) * percent
;
1462 for(l
= lowx_int
+1; l
< highx_int
; l
++) {
1464 for (k
= 0, temp_index
= temp
; k
< components
;
1465 k
++, temp_index
+= element_size
) {
1466 totals
[k
] += (GLubyte
)(*(temp_index
)) * y_percent
;
1471 percent
= y_percent
* highx_float
;
1472 for (k
= 0, temp_index
= temp
; k
< components
;
1473 k
++, temp_index
+= element_size
) {
1474 totals
[k
] += (GLubyte
)(*(temp_index
)) * percent
;
1477 /* calculate the value for pixels in the last row */
1478 y_percent
= highy_float
;
1479 percent
= y_percent
* (1-lowx_float
);
1480 temp
= (const char *)datain
+ xindex
+ highy_int
* ysize
;
1481 for (k
= 0, temp_index
= temp
; k
< components
;
1482 k
++, temp_index
+= element_size
) {
1483 totals
[k
] += (GLubyte
)(*(temp_index
)) * percent
;
1485 for(l
= lowx_int
+1; l
< highx_int
; l
++) {
1487 for (k
= 0, temp_index
= temp
; k
< components
;
1488 k
++, temp_index
+= element_size
) {
1489 totals
[k
] += (GLubyte
)(*(temp_index
)) * y_percent
;
1493 percent
= y_percent
* highx_float
;
1494 for (k
= 0, temp_index
= temp
; k
< components
;
1495 k
++, temp_index
+= element_size
) {
1496 totals
[k
] += (GLubyte
)(*(temp_index
)) * percent
;
1500 /* calculate the value for pixels in the 1st and last column */
1501 for(m
= lowy_int
+1; m
< highy_int
; m
++) {
1504 for (k
= 0; k
< components
;
1505 k
++, left
+= element_size
, right
+= element_size
) {
1506 totals
[k
] += (GLubyte
)(*(left
))*(1-lowx_float
)
1507 +(GLubyte
)(*(right
))*highx_float
;
1510 } else if (highy_int
> lowy_int
) {
1511 x_percent
= highx_float
- lowx_float
;
1512 percent
= (1-lowy_float
)*x_percent
;
1513 temp
= (const char *)datain
+ xindex
+ lowy_int
*ysize
;
1514 for (k
= 0, temp_index
= temp
; k
< components
;
1515 k
++, temp_index
+= element_size
) {
1516 totals
[k
] += (GLubyte
)(*(temp_index
)) * percent
;
1518 for(m
= lowy_int
+1; m
< highy_int
; m
++) {
1520 for (k
= 0, temp_index
= temp
; k
< components
;
1521 k
++, temp_index
+= element_size
) {
1522 totals
[k
] += (GLubyte
)(*(temp_index
)) * x_percent
;
1525 percent
= x_percent
* highy_float
;
1527 for (k
= 0, temp_index
= temp
; k
< components
;
1528 k
++, temp_index
+= element_size
) {
1529 totals
[k
] += (GLubyte
)(*(temp_index
)) * percent
;
1531 } else if (highx_int
> lowx_int
) {
1532 y_percent
= highy_float
- lowy_float
;
1533 percent
= (1-lowx_float
)*y_percent
;
1534 temp
= (const char *)datain
+ xindex
+ lowy_int
*ysize
;
1535 for (k
= 0, temp_index
= temp
; k
< components
;
1536 k
++, temp_index
+= element_size
) {
1537 totals
[k
] += (GLubyte
)(*(temp_index
)) * percent
;
1539 for (l
= lowx_int
+1; l
< highx_int
; l
++) {
1541 for (k
= 0, temp_index
= temp
; k
< components
;
1542 k
++, temp_index
+= element_size
) {
1543 totals
[k
] += (GLubyte
)(*(temp_index
)) * y_percent
;
1547 percent
= y_percent
* highx_float
;
1548 for (k
= 0, temp_index
= temp
; k
< components
;
1549 k
++, temp_index
+= element_size
) {
1550 totals
[k
] += (GLubyte
)(*(temp_index
)) * percent
;
1553 percent
= (highy_float
-lowy_float
)*(highx_float
-lowx_float
);
1554 temp
= (const char *)datain
+ xindex
+ lowy_int
* ysize
;
1555 for (k
= 0, temp_index
= temp
; k
< components
;
1556 k
++, temp_index
+= element_size
) {
1557 totals
[k
] += (GLubyte
)(*(temp_index
)) * percent
;
1563 /* this is for the pixels in the body */
1564 temp0
= (const char *)datain
+ xindex
+ group_size
+
1566 for (m
= lowy_int
+1; m
< highy_int
; m
++) {
1568 for(l
= lowx_int
+1; l
< highx_int
; l
++) {
1569 for (k
= 0, temp_index
= temp
; k
< components
;
1570 k
++, temp_index
+= element_size
) {
1571 totals
[k
] += (GLubyte
)(*(temp_index
));
1578 outindex
= (j
+ (i
* widthout
)) * components
;
1579 for (k
= 0; k
< components
; k
++) {
1580 dataout
[outindex
+ k
] = totals
[k
]/area
;
1581 /*printf("totals[%d] = %f\n", k, totals[k]);*/
1583 lowx_int
= highx_int
;
1584 lowx_float
= highx_float
;
1585 highx_int
+= convx_int
;
1586 highx_float
+= convx_float
;
1587 if(highx_float
> 1) {
1592 lowy_int
= highy_int
;
1593 lowy_float
= highy_float
;
1594 highy_int
+= convy_int
;
1595 highy_float
+= convy_float
;
1596 if(highy_float
> 1) {
1603 static void scale_internal_byte(GLint components
, GLint widthin
,
1604 GLint heightin
, const GLbyte
*datain
,
1605 GLint widthout
, GLint heightout
,
1606 GLbyte
*dataout
, GLint element_size
,
1607 GLint ysize
, GLint group_size
)
1612 /* Max components in a format is 4, so... */
1617 const char *temp
, *temp0
;
1618 const char *temp_index
;
1621 int lowx_int
, highx_int
, lowy_int
, highy_int
;
1622 float x_percent
, y_percent
;
1623 float lowx_float
, highx_float
, lowy_float
, highy_float
;
1624 float convy_float
, convx_float
;
1625 int convy_int
, convx_int
;
1627 const char *left
, *right
;
1629 if (widthin
== widthout
*2 && heightin
== heightout
*2) {
1630 halveImage_byte(components
, widthin
, heightin
,
1631 (const GLbyte
*)datain
, (GLbyte
*)dataout
,
1632 element_size
, ysize
, group_size
);
1635 convy
= (float) heightin
/heightout
;
1636 convx
= (float) widthin
/widthout
;
1637 convy_int
= floor(convy
);
1638 convy_float
= convy
- convy_int
;
1639 convx_int
= floor(convx
);
1640 convx_float
= convx
- convx_int
;
1642 area
= convx
* convy
;
1646 highy_int
= convy_int
;
1647 highy_float
= convy_float
;
1649 for (i
= 0; i
< heightout
; i
++) {
1650 /* Clamp here to be sure we don't read beyond input buffer. */
1651 if (highy_int
>= heightin
)
1652 highy_int
= heightin
- 1;
1655 highx_int
= convx_int
;
1656 highx_float
= convx_float
;
1658 for (j
= 0; j
< widthout
; j
++) {
1661 ** Ok, now apply box filter to box that goes from (lowx, lowy)
1662 ** to (highx, highy) on input data into this pixel on output
1665 totals
[0] = totals
[1] = totals
[2] = totals
[3] = 0.0;
1667 /* calculate the value for pixels in the 1st row */
1668 xindex
= lowx_int
*group_size
;
1669 if((highy_int
>lowy_int
) && (highx_int
>lowx_int
)) {
1671 y_percent
= 1-lowy_float
;
1672 temp
= (const char *)datain
+ xindex
+ lowy_int
* ysize
;
1673 percent
= y_percent
* (1-lowx_float
);
1674 for (k
= 0, temp_index
= temp
; k
< components
;
1675 k
++, temp_index
+= element_size
) {
1676 totals
[k
] += (GLbyte
)(*(temp_index
)) * percent
;
1679 for(l
= lowx_int
+1; l
< highx_int
; l
++) {
1681 for (k
= 0, temp_index
= temp
; k
< components
;
1682 k
++, temp_index
+= element_size
) {
1683 totals
[k
] += (GLbyte
)(*(temp_index
)) * y_percent
;
1688 percent
= y_percent
* highx_float
;
1689 for (k
= 0, temp_index
= temp
; k
< components
;
1690 k
++, temp_index
+= element_size
) {
1691 totals
[k
] += (GLbyte
)(*(temp_index
)) * percent
;
1694 /* calculate the value for pixels in the last row */
1695 y_percent
= highy_float
;
1696 percent
= y_percent
* (1-lowx_float
);
1697 temp
= (const char *)datain
+ xindex
+ highy_int
* ysize
;
1698 for (k
= 0, temp_index
= temp
; k
< components
;
1699 k
++, temp_index
+= element_size
) {
1700 totals
[k
] += (GLbyte
)(*(temp_index
)) * percent
;
1702 for(l
= lowx_int
+1; l
< highx_int
; l
++) {
1704 for (k
= 0, temp_index
= temp
; k
< components
;
1705 k
++, temp_index
+= element_size
) {
1706 totals
[k
] += (GLbyte
)(*(temp_index
)) * y_percent
;
1710 percent
= y_percent
* highx_float
;
1711 for (k
= 0, temp_index
= temp
; k
< components
;
1712 k
++, temp_index
+= element_size
) {
1713 totals
[k
] += (GLbyte
)(*(temp_index
)) * percent
;
1717 /* calculate the value for pixels in the 1st and last column */
1718 for(m
= lowy_int
+1; m
< highy_int
; m
++) {
1721 for (k
= 0; k
< components
;
1722 k
++, left
+= element_size
, right
+= element_size
) {
1723 totals
[k
] += (GLbyte
)(*(left
))*(1-lowx_float
)
1724 +(GLbyte
)(*(right
))*highx_float
;
1727 } else if (highy_int
> lowy_int
) {
1728 x_percent
= highx_float
- lowx_float
;
1729 percent
= (1-lowy_float
)*x_percent
;
1730 temp
= (const char *)datain
+ xindex
+ lowy_int
*ysize
;
1731 for (k
= 0, temp_index
= temp
; k
< components
;
1732 k
++, temp_index
+= element_size
) {
1733 totals
[k
] += (GLbyte
)(*(temp_index
)) * percent
;
1735 for(m
= lowy_int
+1; m
< highy_int
; m
++) {
1737 for (k
= 0, temp_index
= temp
; k
< components
;
1738 k
++, temp_index
+= element_size
) {
1739 totals
[k
] += (GLbyte
)(*(temp_index
)) * x_percent
;
1742 percent
= x_percent
* highy_float
;
1744 for (k
= 0, temp_index
= temp
; k
< components
;
1745 k
++, temp_index
+= element_size
) {
1746 totals
[k
] += (GLbyte
)(*(temp_index
)) * percent
;
1748 } else if (highx_int
> lowx_int
) {
1749 y_percent
= highy_float
- lowy_float
;
1750 percent
= (1-lowx_float
)*y_percent
;
1751 temp
= (const char *)datain
+ xindex
+ lowy_int
*ysize
;
1752 for (k
= 0, temp_index
= temp
; k
< components
;
1753 k
++, temp_index
+= element_size
) {
1754 totals
[k
] += (GLbyte
)(*(temp_index
)) * percent
;
1756 for (l
= lowx_int
+1; l
< highx_int
; l
++) {
1758 for (k
= 0, temp_index
= temp
; k
< components
;
1759 k
++, temp_index
+= element_size
) {
1760 totals
[k
] += (GLbyte
)(*(temp_index
)) * y_percent
;
1764 percent
= y_percent
* highx_float
;
1765 for (k
= 0, temp_index
= temp
; k
< components
;
1766 k
++, temp_index
+= element_size
) {
1767 totals
[k
] += (GLbyte
)(*(temp_index
)) * percent
;
1770 percent
= (highy_float
-lowy_float
)*(highx_float
-lowx_float
);
1771 temp
= (const char *)datain
+ xindex
+ lowy_int
* ysize
;
1772 for (k
= 0, temp_index
= temp
; k
< components
;
1773 k
++, temp_index
+= element_size
) {
1774 totals
[k
] += (GLbyte
)(*(temp_index
)) * percent
;
1780 /* this is for the pixels in the body */
1781 temp0
= (const char *)datain
+ xindex
+ group_size
+
1783 for (m
= lowy_int
+1; m
< highy_int
; m
++) {
1785 for(l
= lowx_int
+1; l
< highx_int
; l
++) {
1786 for (k
= 0, temp_index
= temp
; k
< components
;
1787 k
++, temp_index
+= element_size
) {
1788 totals
[k
] += (GLbyte
)(*(temp_index
));
1795 outindex
= (j
+ (i
* widthout
)) * components
;
1796 for (k
= 0; k
< components
; k
++) {
1797 dataout
[outindex
+ k
] = totals
[k
]/area
;
1798 /*printf("totals[%d] = %f\n", k, totals[k]);*/
1800 lowx_int
= highx_int
;
1801 lowx_float
= highx_float
;
1802 highx_int
+= convx_int
;
1803 highx_float
+= convx_float
;
1804 if(highx_float
> 1) {
1809 lowy_int
= highy_int
;
1810 lowy_float
= highy_float
;
1811 highy_int
+= convy_int
;
1812 highy_float
+= convy_float
;
1813 if(highy_float
> 1) {
1820 static void scale_internal_ushort(GLint components
, GLint widthin
,
1821 GLint heightin
, const GLushort
*datain
,
1822 GLint widthout
, GLint heightout
,
1823 GLushort
*dataout
, GLint element_size
,
1824 GLint ysize
, GLint group_size
,
1830 /* Max components in a format is 4, so... */
1835 const char *temp
, *temp0
;
1836 const char *temp_index
;
1839 int lowx_int
, highx_int
, lowy_int
, highy_int
;
1840 float x_percent
, y_percent
;
1841 float lowx_float
, highx_float
, lowy_float
, highy_float
;
1842 float convy_float
, convx_float
;
1843 int convy_int
, convx_int
;
1845 const char *left
, *right
;
1847 if (widthin
== widthout
*2 && heightin
== heightout
*2) {
1848 halveImage_ushort(components
, widthin
, heightin
,
1849 (const GLushort
*)datain
, (GLushort
*)dataout
,
1850 element_size
, ysize
, group_size
, myswap_bytes
);
1853 convy
= (float) heightin
/heightout
;
1854 convx
= (float) widthin
/widthout
;
1855 convy_int
= floor(convy
);
1856 convy_float
= convy
- convy_int
;
1857 convx_int
= floor(convx
);
1858 convx_float
= convx
- convx_int
;
1860 area
= convx
* convy
;
1864 highy_int
= convy_int
;
1865 highy_float
= convy_float
;
1867 for (i
= 0; i
< heightout
; i
++) {
1868 /* Clamp here to be sure we don't read beyond input buffer. */
1869 if (highy_int
>= heightin
)
1870 highy_int
= heightin
- 1;
1873 highx_int
= convx_int
;
1874 highx_float
= convx_float
;
1876 for (j
= 0; j
< widthout
; j
++) {
1878 ** Ok, now apply box filter to box that goes from (lowx, lowy)
1879 ** to (highx, highy) on input data into this pixel on output
1882 totals
[0] = totals
[1] = totals
[2] = totals
[3] = 0.0;
1884 /* calculate the value for pixels in the 1st row */
1885 xindex
= lowx_int
*group_size
;
1886 if((highy_int
>lowy_int
) && (highx_int
>lowx_int
)) {
1888 y_percent
= 1-lowy_float
;
1889 temp
= (const char *)datain
+ xindex
+ lowy_int
* ysize
;
1890 percent
= y_percent
* (1-lowx_float
);
1891 for (k
= 0, temp_index
= temp
; k
< components
;
1892 k
++, temp_index
+= element_size
) {
1894 totals
[k
] += __GLU_SWAP_2_BYTES(temp_index
) * percent
;
1896 totals
[k
] += *(const GLushort
*)temp_index
* percent
;
1900 for(l
= lowx_int
+1; l
< highx_int
; l
++) {
1902 for (k
= 0, temp_index
= temp
; k
< components
;
1903 k
++, temp_index
+= element_size
) {
1906 __GLU_SWAP_2_BYTES(temp_index
) * y_percent
;
1908 totals
[k
] += *(const GLushort
*)temp_index
* y_percent
;
1914 percent
= y_percent
* highx_float
;
1915 for (k
= 0, temp_index
= temp
; k
< components
;
1916 k
++, temp_index
+= element_size
) {
1918 totals
[k
] += __GLU_SWAP_2_BYTES(temp_index
) * percent
;
1920 totals
[k
] += *(const GLushort
*)temp_index
* percent
;
1924 /* calculate the value for pixels in the last row */
1925 y_percent
= highy_float
;
1926 percent
= y_percent
* (1-lowx_float
);
1927 temp
= (const char *)datain
+ xindex
+ highy_int
* ysize
;
1928 for (k
= 0, temp_index
= temp
; k
< components
;
1929 k
++, temp_index
+= element_size
) {
1931 totals
[k
] += __GLU_SWAP_2_BYTES(temp_index
) * percent
;
1933 totals
[k
] += *(const GLushort
*)temp_index
* percent
;
1936 for(l
= lowx_int
+1; l
< highx_int
; l
++) {
1938 for (k
= 0, temp_index
= temp
; k
< components
;
1939 k
++, temp_index
+= element_size
) {
1942 __GLU_SWAP_2_BYTES(temp_index
) * y_percent
;
1944 totals
[k
] += *(const GLushort
*)temp_index
* y_percent
;
1949 percent
= y_percent
* highx_float
;
1950 for (k
= 0, temp_index
= temp
; k
< components
;
1951 k
++, temp_index
+= element_size
) {
1953 totals
[k
] += __GLU_SWAP_2_BYTES(temp_index
) * percent
;
1955 totals
[k
] += *(const GLushort
*)temp_index
* percent
;
1959 /* calculate the value for pixels in the 1st and last column */
1960 for(m
= lowy_int
+1; m
< highy_int
; m
++) {
1963 for (k
= 0; k
< components
;
1964 k
++, left
+= element_size
, right
+= element_size
) {
1967 __GLU_SWAP_2_BYTES(left
) * (1-lowx_float
) +
1968 __GLU_SWAP_2_BYTES(right
) * highx_float
;
1970 totals
[k
] += *(const GLushort
*)left
* (1-lowx_float
)
1971 + *(const GLushort
*)right
* highx_float
;
1975 } else if (highy_int
> lowy_int
) {
1976 x_percent
= highx_float
- lowx_float
;
1977 percent
= (1-lowy_float
)*x_percent
;
1978 temp
= (const char *)datain
+ xindex
+ lowy_int
*ysize
;
1979 for (k
= 0, temp_index
= temp
; k
< components
;
1980 k
++, temp_index
+= element_size
) {
1982 totals
[k
] += __GLU_SWAP_2_BYTES(temp_index
) * percent
;
1984 totals
[k
] += *(const GLushort
*)temp_index
* percent
;
1987 for(m
= lowy_int
+1; m
< highy_int
; m
++) {
1989 for (k
= 0, temp_index
= temp
; k
< components
;
1990 k
++, temp_index
+= element_size
) {
1993 __GLU_SWAP_2_BYTES(temp_index
) * x_percent
;
1995 totals
[k
] += *(const GLushort
*)temp_index
* x_percent
;
1999 percent
= x_percent
* highy_float
;
2001 for (k
= 0, temp_index
= temp
; k
< components
;
2002 k
++, temp_index
+= element_size
) {
2004 totals
[k
] += __GLU_SWAP_2_BYTES(temp_index
) * percent
;
2006 totals
[k
] += *(const GLushort
*)temp_index
* percent
;
2009 } else if (highx_int
> lowx_int
) {
2010 y_percent
= highy_float
- lowy_float
;
2011 percent
= (1-lowx_float
)*y_percent
;
2012 temp
= (const char *)datain
+ xindex
+ lowy_int
*ysize
;
2013 for (k
= 0, temp_index
= temp
; k
< components
;
2014 k
++, temp_index
+= element_size
) {
2016 totals
[k
] += __GLU_SWAP_2_BYTES(temp_index
) * percent
;
2018 totals
[k
] += *(const GLushort
*)temp_index
* percent
;
2021 for (l
= lowx_int
+1; l
< highx_int
; l
++) {
2023 for (k
= 0, temp_index
= temp
; k
< components
;
2024 k
++, temp_index
+= element_size
) {
2027 __GLU_SWAP_2_BYTES(temp_index
) * y_percent
;
2029 totals
[k
] += *(const GLushort
*)temp_index
* y_percent
;
2034 percent
= y_percent
* highx_float
;
2035 for (k
= 0, temp_index
= temp
; k
< components
;
2036 k
++, temp_index
+= element_size
) {
2038 totals
[k
] += __GLU_SWAP_2_BYTES(temp_index
) * percent
;
2040 totals
[k
] += *(const GLushort
*)temp_index
* percent
;
2044 percent
= (highy_float
-lowy_float
)*(highx_float
-lowx_float
);
2045 temp
= (const char *)datain
+ xindex
+ lowy_int
* ysize
;
2046 for (k
= 0, temp_index
= temp
; k
< components
;
2047 k
++, temp_index
+= element_size
) {
2049 totals
[k
] += __GLU_SWAP_2_BYTES(temp_index
) * percent
;
2051 totals
[k
] += *(const GLushort
*)temp_index
* percent
;
2056 /* this is for the pixels in the body */
2057 temp0
= (const char *)datain
+ xindex
+ group_size
+
2059 for (m
= lowy_int
+1; m
< highy_int
; m
++) {
2061 for(l
= lowx_int
+1; l
< highx_int
; l
++) {
2062 for (k
= 0, temp_index
= temp
; k
< components
;
2063 k
++, temp_index
+= element_size
) {
2065 totals
[k
] += __GLU_SWAP_2_BYTES(temp_index
);
2067 totals
[k
] += *(const GLushort
*)temp_index
;
2075 outindex
= (j
+ (i
* widthout
)) * components
;
2076 for (k
= 0; k
< components
; k
++) {
2077 dataout
[outindex
+ k
] = totals
[k
]/area
;
2078 /*printf("totals[%d] = %f\n", k, totals[k]);*/
2080 lowx_int
= highx_int
;
2081 lowx_float
= highx_float
;
2082 highx_int
+= convx_int
;
2083 highx_float
+= convx_float
;
2084 if(highx_float
> 1) {
2089 lowy_int
= highy_int
;
2090 lowy_float
= highy_float
;
2091 highy_int
+= convy_int
;
2092 highy_float
+= convy_float
;
2093 if(highy_float
> 1) {
2100 static void scale_internal_short(GLint components
, GLint widthin
,
2101 GLint heightin
, const GLshort
*datain
,
2102 GLint widthout
, GLint heightout
,
2103 GLshort
*dataout
, GLint element_size
,
2104 GLint ysize
, GLint group_size
,
2110 /* Max components in a format is 4, so... */
2115 const char *temp
, *temp0
;
2116 const char *temp_index
;
2119 int lowx_int
, highx_int
, lowy_int
, highy_int
;
2120 float x_percent
, y_percent
;
2121 float lowx_float
, highx_float
, lowy_float
, highy_float
;
2122 float convy_float
, convx_float
;
2123 int convy_int
, convx_int
;
2125 const char *left
, *right
;
2127 GLushort swapbuf
; /* unsigned buffer */
2129 if (widthin
== widthout
*2 && heightin
== heightout
*2) {
2130 halveImage_short(components
, widthin
, heightin
,
2131 (const GLshort
*)datain
, (GLshort
*)dataout
,
2132 element_size
, ysize
, group_size
, myswap_bytes
);
2135 convy
= (float) heightin
/heightout
;
2136 convx
= (float) widthin
/widthout
;
2137 convy_int
= floor(convy
);
2138 convy_float
= convy
- convy_int
;
2139 convx_int
= floor(convx
);
2140 convx_float
= convx
- convx_int
;
2142 area
= convx
* convy
;
2146 highy_int
= convy_int
;
2147 highy_float
= convy_float
;
2149 for (i
= 0; i
< heightout
; i
++) {
2150 /* Clamp here to be sure we don't read beyond input buffer. */
2151 if (highy_int
>= heightin
)
2152 highy_int
= heightin
- 1;
2155 highx_int
= convx_int
;
2156 highx_float
= convx_float
;
2158 for (j
= 0; j
< widthout
; j
++) {
2160 ** Ok, now apply box filter to box that goes from (lowx, lowy)
2161 ** to (highx, highy) on input data into this pixel on output
2164 totals
[0] = totals
[1] = totals
[2] = totals
[3] = 0.0;
2166 /* calculate the value for pixels in the 1st row */
2167 xindex
= lowx_int
*group_size
;
2168 if((highy_int
>lowy_int
) && (highx_int
>lowx_int
)) {
2170 y_percent
= 1-lowy_float
;
2171 temp
= (const char *)datain
+ xindex
+ lowy_int
* ysize
;
2172 percent
= y_percent
* (1-lowx_float
);
2173 for (k
= 0, temp_index
= temp
; k
< components
;
2174 k
++, temp_index
+= element_size
) {
2176 swapbuf
= __GLU_SWAP_2_BYTES(temp_index
);
2177 totals
[k
] += *(const GLshort
*)&swapbuf
* percent
;
2179 totals
[k
] += *(const GLshort
*)temp_index
* percent
;
2183 for(l
= lowx_int
+1; l
< highx_int
; l
++) {
2185 for (k
= 0, temp_index
= temp
; k
< components
;
2186 k
++, temp_index
+= element_size
) {
2188 swapbuf
= __GLU_SWAP_2_BYTES(temp_index
);
2189 totals
[k
] += *(const GLshort
*)&swapbuf
* y_percent
;
2191 totals
[k
] += *(const GLshort
*)temp_index
* y_percent
;
2197 percent
= y_percent
* highx_float
;
2198 for (k
= 0, temp_index
= temp
; k
< components
;
2199 k
++, temp_index
+= element_size
) {
2201 swapbuf
= __GLU_SWAP_2_BYTES(temp_index
);
2202 totals
[k
] += *(const GLshort
*)&swapbuf
* percent
;
2204 totals
[k
] += *(const GLshort
*)temp_index
* percent
;
2208 /* calculate the value for pixels in the last row */
2209 y_percent
= highy_float
;
2210 percent
= y_percent
* (1-lowx_float
);
2211 temp
= (const char *)datain
+ xindex
+ highy_int
* ysize
;
2212 for (k
= 0, temp_index
= temp
; k
< components
;
2213 k
++, temp_index
+= element_size
) {
2215 swapbuf
= __GLU_SWAP_2_BYTES(temp_index
);
2216 totals
[k
] += *(const GLshort
*)&swapbuf
* percent
;
2218 totals
[k
] += *(const GLshort
*)temp_index
* percent
;
2221 for(l
= lowx_int
+1; l
< highx_int
; l
++) {
2223 for (k
= 0, temp_index
= temp
; k
< components
;
2224 k
++, temp_index
+= element_size
) {
2226 swapbuf
= __GLU_SWAP_2_BYTES(temp_index
);
2227 totals
[k
] += *(const GLshort
*)&swapbuf
* y_percent
;
2229 totals
[k
] += *(const GLshort
*)temp_index
* y_percent
;
2234 percent
= y_percent
* highx_float
;
2235 for (k
= 0, temp_index
= temp
; k
< components
;
2236 k
++, temp_index
+= element_size
) {
2238 swapbuf
= __GLU_SWAP_2_BYTES(temp_index
);
2239 totals
[k
] += *(const GLshort
*)&swapbuf
* percent
;
2241 totals
[k
] += *(const GLshort
*)temp_index
* percent
;
2245 /* calculate the value for pixels in the 1st and last column */
2246 for(m
= lowy_int
+1; m
< highy_int
; m
++) {
2249 for (k
= 0; k
< components
;
2250 k
++, left
+= element_size
, right
+= element_size
) {
2252 swapbuf
= __GLU_SWAP_2_BYTES(left
);
2253 totals
[k
] += *(const GLshort
*)&swapbuf
* (1-lowx_float
);
2254 swapbuf
= __GLU_SWAP_2_BYTES(right
);
2255 totals
[k
] += *(const GLshort
*)&swapbuf
* highx_float
;
2257 totals
[k
] += *(const GLshort
*)left
* (1-lowx_float
)
2258 + *(const GLshort
*)right
* highx_float
;
2262 } else if (highy_int
> lowy_int
) {
2263 x_percent
= highx_float
- lowx_float
;
2264 percent
= (1-lowy_float
)*x_percent
;
2265 temp
= (const char *)datain
+ xindex
+ lowy_int
*ysize
;
2266 for (k
= 0, temp_index
= temp
; k
< components
;
2267 k
++, temp_index
+= element_size
) {
2269 swapbuf
= __GLU_SWAP_2_BYTES(temp_index
);
2270 totals
[k
] += *(const GLshort
*)&swapbuf
* percent
;
2272 totals
[k
] += *(const GLshort
*)temp_index
* percent
;
2275 for(m
= lowy_int
+1; m
< highy_int
; m
++) {
2277 for (k
= 0, temp_index
= temp
; k
< components
;
2278 k
++, temp_index
+= element_size
) {
2280 swapbuf
= __GLU_SWAP_2_BYTES(temp_index
);
2281 totals
[k
] += *(const GLshort
*)&swapbuf
* x_percent
;
2283 totals
[k
] += *(const GLshort
*)temp_index
* x_percent
;
2287 percent
= x_percent
* highy_float
;
2289 for (k
= 0, temp_index
= temp
; k
< components
;
2290 k
++, temp_index
+= element_size
) {
2292 swapbuf
= __GLU_SWAP_2_BYTES(temp_index
);
2293 totals
[k
] += *(const GLshort
*)&swapbuf
* percent
;
2295 totals
[k
] += *(const GLshort
*)temp_index
* percent
;
2298 } else if (highx_int
> lowx_int
) {
2299 y_percent
= highy_float
- lowy_float
;
2300 percent
= (1-lowx_float
)*y_percent
;
2302 temp
= (const char *)datain
+ xindex
+ lowy_int
*ysize
;
2303 for (k
= 0, temp_index
= temp
; k
< components
;
2304 k
++, temp_index
+= element_size
) {
2306 swapbuf
= __GLU_SWAP_2_BYTES(temp_index
);
2307 totals
[k
] += *(const GLshort
*)&swapbuf
* percent
;
2309 totals
[k
] += *(const GLshort
*)temp_index
* percent
;
2312 for (l
= lowx_int
+1; l
< highx_int
; l
++) {
2314 for (k
= 0, temp_index
= temp
; k
< components
;
2315 k
++, temp_index
+= element_size
) {
2317 swapbuf
= __GLU_SWAP_2_BYTES(temp_index
);
2318 totals
[k
] += *(const GLshort
*)&swapbuf
* y_percent
;
2320 totals
[k
] += *(const GLshort
*)temp_index
* y_percent
;
2325 percent
= y_percent
* highx_float
;
2326 for (k
= 0, temp_index
= temp
; k
< components
;
2327 k
++, temp_index
+= element_size
) {
2329 swapbuf
= __GLU_SWAP_2_BYTES(temp_index
);
2330 totals
[k
] += *(const GLshort
*)&swapbuf
* percent
;
2332 totals
[k
] += *(const GLshort
*)temp_index
* percent
;
2336 percent
= (highy_float
-lowy_float
)*(highx_float
-lowx_float
);
2337 temp
= (const char *)datain
+ xindex
+ lowy_int
* ysize
;
2338 for (k
= 0, temp_index
= temp
; k
< components
;
2339 k
++, temp_index
+= element_size
) {
2341 swapbuf
= __GLU_SWAP_2_BYTES(temp_index
);
2342 totals
[k
] += *(const GLshort
*)&swapbuf
* percent
;
2344 totals
[k
] += *(const GLshort
*)temp_index
* percent
;
2349 /* this is for the pixels in the body */
2350 temp0
= (const char *)datain
+ xindex
+ group_size
+
2352 for (m
= lowy_int
+1; m
< highy_int
; m
++) {
2354 for(l
= lowx_int
+1; l
< highx_int
; l
++) {
2355 for (k
= 0, temp_index
= temp
; k
< components
;
2356 k
++, temp_index
+= element_size
) {
2358 swapbuf
= __GLU_SWAP_2_BYTES(temp_index
);
2359 totals
[k
] += *(const GLshort
*)&swapbuf
;
2361 totals
[k
] += *(const GLshort
*)temp_index
;
2369 outindex
= (j
+ (i
* widthout
)) * components
;
2370 for (k
= 0; k
< components
; k
++) {
2371 dataout
[outindex
+ k
] = totals
[k
]/area
;
2372 /*printf("totals[%d] = %f\n", k, totals[k]);*/
2374 lowx_int
= highx_int
;
2375 lowx_float
= highx_float
;
2376 highx_int
+= convx_int
;
2377 highx_float
+= convx_float
;
2378 if(highx_float
> 1) {
2383 lowy_int
= highy_int
;
2384 lowy_float
= highy_float
;
2385 highy_int
+= convy_int
;
2386 highy_float
+= convy_float
;
2387 if(highy_float
> 1) {
2394 static void scale_internal_uint(GLint components
, GLint widthin
,
2395 GLint heightin
, const GLuint
*datain
,
2396 GLint widthout
, GLint heightout
,
2397 GLuint
*dataout
, GLint element_size
,
2398 GLint ysize
, GLint group_size
,
2404 /* Max components in a format is 4, so... */
2409 const char *temp
, *temp0
;
2410 const char *temp_index
;
2413 int lowx_int
, highx_int
, lowy_int
, highy_int
;
2414 float x_percent
, y_percent
;
2415 float lowx_float
, highx_float
, lowy_float
, highy_float
;
2416 float convy_float
, convx_float
;
2417 int convy_int
, convx_int
;
2419 const char *left
, *right
;
2421 if (widthin
== widthout
*2 && heightin
== heightout
*2) {
2422 halveImage_uint(components
, widthin
, heightin
,
2423 (const GLuint
*)datain
, (GLuint
*)dataout
,
2424 element_size
, ysize
, group_size
, myswap_bytes
);
2427 convy
= (float) heightin
/heightout
;
2428 convx
= (float) widthin
/widthout
;
2429 convy_int
= floor(convy
);
2430 convy_float
= convy
- convy_int
;
2431 convx_int
= floor(convx
);
2432 convx_float
= convx
- convx_int
;
2434 area
= convx
* convy
;
2438 highy_int
= convy_int
;
2439 highy_float
= convy_float
;
2441 for (i
= 0; i
< heightout
; i
++) {
2442 /* Clamp here to be sure we don't read beyond input buffer. */
2443 if (highy_int
>= heightin
)
2444 highy_int
= heightin
- 1;
2447 highx_int
= convx_int
;
2448 highx_float
= convx_float
;
2450 for (j
= 0; j
< widthout
; j
++) {
2452 ** Ok, now apply box filter to box that goes from (lowx, lowy)
2453 ** to (highx, highy) on input data into this pixel on output
2456 totals
[0] = totals
[1] = totals
[2] = totals
[3] = 0.0;
2458 /* calculate the value for pixels in the 1st row */
2459 xindex
= lowx_int
*group_size
;
2460 if((highy_int
>lowy_int
) && (highx_int
>lowx_int
)) {
2462 y_percent
= 1-lowy_float
;
2463 temp
= (const char *)datain
+ xindex
+ lowy_int
* ysize
;
2464 percent
= y_percent
* (1-lowx_float
);
2465 for (k
= 0, temp_index
= temp
; k
< components
;
2466 k
++, temp_index
+= element_size
) {
2468 totals
[k
] += __GLU_SWAP_4_BYTES(temp_index
) * percent
;
2470 totals
[k
] += *(const GLuint
*)temp_index
* percent
;
2474 for(l
= lowx_int
+1; l
< highx_int
; l
++) {
2476 for (k
= 0, temp_index
= temp
; k
< components
;
2477 k
++, temp_index
+= element_size
) {
2480 __GLU_SWAP_4_BYTES(temp_index
) * y_percent
;
2482 totals
[k
] += *(const GLuint
*)temp_index
* y_percent
;
2488 percent
= y_percent
* highx_float
;
2489 for (k
= 0, temp_index
= temp
; k
< components
;
2490 k
++, temp_index
+= element_size
) {
2492 totals
[k
] += __GLU_SWAP_4_BYTES(temp_index
) * percent
;
2494 totals
[k
] += *(const GLuint
*)temp_index
* percent
;
2498 /* calculate the value for pixels in the last row */
2499 y_percent
= highy_float
;
2500 percent
= y_percent
* (1-lowx_float
);
2501 temp
= (const char *)datain
+ xindex
+ highy_int
* ysize
;
2502 for (k
= 0, temp_index
= temp
; k
< components
;
2503 k
++, temp_index
+= element_size
) {
2505 totals
[k
] += __GLU_SWAP_4_BYTES(temp_index
) * percent
;
2507 totals
[k
] += *(const GLuint
*)temp_index
* percent
;
2510 for(l
= lowx_int
+1; l
< highx_int
; l
++) {
2512 for (k
= 0, temp_index
= temp
; k
< components
;
2513 k
++, temp_index
+= element_size
) {
2516 __GLU_SWAP_4_BYTES(temp_index
) * y_percent
;
2518 totals
[k
] += *(const GLuint
*)temp_index
* y_percent
;
2523 percent
= y_percent
* highx_float
;
2524 for (k
= 0, temp_index
= temp
; k
< components
;
2525 k
++, temp_index
+= element_size
) {
2527 totals
[k
] += __GLU_SWAP_4_BYTES(temp_index
) * percent
;
2529 totals
[k
] += *(const GLuint
*)temp_index
* percent
;
2533 /* calculate the value for pixels in the 1st and last column */
2534 for(m
= lowy_int
+1; m
< highy_int
; m
++) {
2537 for (k
= 0; k
< components
;
2538 k
++, left
+= element_size
, right
+= element_size
) {
2541 __GLU_SWAP_4_BYTES(left
) * (1-lowx_float
)
2542 + __GLU_SWAP_4_BYTES(right
) * highx_float
;
2544 totals
[k
] += *(const GLuint
*)left
* (1-lowx_float
)
2545 + *(const GLuint
*)right
* highx_float
;
2549 } else if (highy_int
> lowy_int
) {
2550 x_percent
= highx_float
- lowx_float
;
2551 percent
= (1-lowy_float
)*x_percent
;
2552 temp
= (const char *)datain
+ xindex
+ lowy_int
*ysize
;
2553 for (k
= 0, temp_index
= temp
; k
< components
;
2554 k
++, temp_index
+= element_size
) {
2556 totals
[k
] += __GLU_SWAP_4_BYTES(temp_index
) * percent
;
2558 totals
[k
] += *(const GLuint
*)temp_index
* percent
;
2561 for(m
= lowy_int
+1; m
< highy_int
; m
++) {
2563 for (k
= 0, temp_index
= temp
; k
< components
;
2564 k
++, temp_index
+= element_size
) {
2567 __GLU_SWAP_4_BYTES(temp_index
) * x_percent
;
2569 totals
[k
] += *(const GLuint
*)temp_index
* x_percent
;
2573 percent
= x_percent
* highy_float
;
2575 for (k
= 0, temp_index
= temp
; k
< components
;
2576 k
++, temp_index
+= element_size
) {
2578 totals
[k
] += __GLU_SWAP_4_BYTES(temp_index
) * percent
;
2580 totals
[k
] += *(const GLuint
*)temp_index
* percent
;
2583 } else if (highx_int
> lowx_int
) {
2584 y_percent
= highy_float
- lowy_float
;
2585 percent
= (1-lowx_float
)*y_percent
;
2587 temp
= (const char *)datain
+ xindex
+ lowy_int
*ysize
;
2588 for (k
= 0, temp_index
= temp
; k
< components
;
2589 k
++, temp_index
+= element_size
) {
2591 totals
[k
] += __GLU_SWAP_4_BYTES(temp_index
) * percent
;
2593 totals
[k
] += *(const GLuint
*)temp_index
* percent
;
2596 for (l
= lowx_int
+1; l
< highx_int
; l
++) {
2598 for (k
= 0, temp_index
= temp
; k
< components
;
2599 k
++, temp_index
+= element_size
) {
2602 __GLU_SWAP_4_BYTES(temp_index
) * y_percent
;
2604 totals
[k
] += *(const GLuint
*)temp_index
* y_percent
;
2609 percent
= y_percent
* highx_float
;
2610 for (k
= 0, temp_index
= temp
; k
< components
;
2611 k
++, temp_index
+= element_size
) {
2613 totals
[k
] += __GLU_SWAP_4_BYTES(temp_index
) * percent
;
2615 totals
[k
] += *(const GLuint
*)temp_index
* percent
;
2619 percent
= (highy_float
-lowy_float
)*(highx_float
-lowx_float
);
2620 temp
= (const char *)datain
+ xindex
+ lowy_int
* ysize
;
2621 for (k
= 0, temp_index
= temp
; k
< components
;
2622 k
++, temp_index
+= element_size
) {
2624 totals
[k
] += __GLU_SWAP_4_BYTES(temp_index
) * percent
;
2626 totals
[k
] += *(const GLuint
*)temp_index
* percent
;
2631 /* this is for the pixels in the body */
2632 temp0
= (const char *)datain
+ xindex
+ group_size
+
2634 for (m
= lowy_int
+1; m
< highy_int
; m
++) {
2636 for(l
= lowx_int
+1; l
< highx_int
; l
++) {
2637 for (k
= 0, temp_index
= temp
; k
< components
;
2638 k
++, temp_index
+= element_size
) {
2640 totals
[k
] += __GLU_SWAP_4_BYTES(temp_index
);
2642 totals
[k
] += *(const GLuint
*)temp_index
;
2650 outindex
= (j
+ (i
* widthout
)) * components
;
2651 for (k
= 0; k
< components
; k
++) {
2652 /* clamp at UINT_MAX */
2653 float value
= totals
[k
]/area
;
2654 if (value
>= (float) UINT_MAX
) { /* need '=' */
2655 dataout
[outindex
+ k
] = UINT_MAX
;
2657 else dataout
[outindex
+ k
] = value
;
2659 lowx_int
= highx_int
;
2660 lowx_float
= highx_float
;
2661 highx_int
+= convx_int
;
2662 highx_float
+= convx_float
;
2663 if(highx_float
> 1) {
2668 lowy_int
= highy_int
;
2669 lowy_float
= highy_float
;
2670 highy_int
+= convy_int
;
2671 highy_float
+= convy_float
;
2672 if(highy_float
> 1) {
2681 static void scale_internal_int(GLint components
, GLint widthin
,
2682 GLint heightin
, const GLint
*datain
,
2683 GLint widthout
, GLint heightout
,
2684 GLint
*dataout
, GLint element_size
,
2685 GLint ysize
, GLint group_size
,
2691 /* Max components in a format is 4, so... */
2696 const char *temp
, *temp0
;
2697 const char *temp_index
;
2700 int lowx_int
, highx_int
, lowy_int
, highy_int
;
2701 float x_percent
, y_percent
;
2702 float lowx_float
, highx_float
, lowy_float
, highy_float
;
2703 float convy_float
, convx_float
;
2704 int convy_int
, convx_int
;
2706 const char *left
, *right
;
2708 GLuint swapbuf
; /* unsigned buffer */
2710 if (widthin
== widthout
*2 && heightin
== heightout
*2) {
2711 halveImage_int(components
, widthin
, heightin
,
2712 (const GLint
*)datain
, (GLint
*)dataout
,
2713 element_size
, ysize
, group_size
, myswap_bytes
);
2716 convy
= (float) heightin
/heightout
;
2717 convx
= (float) widthin
/widthout
;
2718 convy_int
= floor(convy
);
2719 convy_float
= convy
- convy_int
;
2720 convx_int
= floor(convx
);
2721 convx_float
= convx
- convx_int
;
2723 area
= convx
* convy
;
2727 highy_int
= convy_int
;
2728 highy_float
= convy_float
;
2730 for (i
= 0; i
< heightout
; i
++) {
2731 /* Clamp here to be sure we don't read beyond input buffer. */
2732 if (highy_int
>= heightin
)
2733 highy_int
= heightin
- 1;
2736 highx_int
= convx_int
;
2737 highx_float
= convx_float
;
2739 for (j
= 0; j
< widthout
; j
++) {
2741 ** Ok, now apply box filter to box that goes from (lowx, lowy)
2742 ** to (highx, highy) on input data into this pixel on output
2745 totals
[0] = totals
[1] = totals
[2] = totals
[3] = 0.0;
2747 /* calculate the value for pixels in the 1st row */
2748 xindex
= lowx_int
*group_size
;
2749 if((highy_int
>lowy_int
) && (highx_int
>lowx_int
)) {
2751 y_percent
= 1-lowy_float
;
2752 temp
= (const char *)datain
+ xindex
+ lowy_int
* ysize
;
2753 percent
= y_percent
* (1-lowx_float
);
2754 for (k
= 0, temp_index
= temp
; k
< components
;
2755 k
++, temp_index
+= element_size
) {
2757 swapbuf
= __GLU_SWAP_4_BYTES(temp_index
);
2758 totals
[k
] += *(const GLint
*)&swapbuf
* percent
;
2760 totals
[k
] += *(const GLint
*)temp_index
* percent
;
2764 for(l
= lowx_int
+1; l
< highx_int
; l
++) {
2766 for (k
= 0, temp_index
= temp
; k
< components
;
2767 k
++, temp_index
+= element_size
) {
2769 swapbuf
= __GLU_SWAP_4_BYTES(temp_index
);
2770 totals
[k
] += *(const GLint
*)&swapbuf
* y_percent
;
2772 totals
[k
] += *(const GLint
*)temp_index
* y_percent
;
2778 percent
= y_percent
* highx_float
;
2779 for (k
= 0, temp_index
= temp
; k
< components
;
2780 k
++, temp_index
+= element_size
) {
2782 swapbuf
= __GLU_SWAP_4_BYTES(temp_index
);
2783 totals
[k
] += *(const GLint
*)&swapbuf
* percent
;
2785 totals
[k
] += *(const GLint
*)temp_index
* percent
;
2789 /* calculate the value for pixels in the last row */
2790 y_percent
= highy_float
;
2791 percent
= y_percent
* (1-lowx_float
);
2792 temp
= (const char *)datain
+ xindex
+ highy_int
* ysize
;
2793 for (k
= 0, temp_index
= temp
; k
< components
;
2794 k
++, temp_index
+= element_size
) {
2796 swapbuf
= __GLU_SWAP_4_BYTES(temp_index
);
2797 totals
[k
] += *(const GLint
*)&swapbuf
* percent
;
2799 totals
[k
] += *(const GLint
*)temp_index
* percent
;
2802 for(l
= lowx_int
+1; l
< highx_int
; l
++) {
2804 for (k
= 0, temp_index
= temp
; k
< components
;
2805 k
++, temp_index
+= element_size
) {
2807 swapbuf
= __GLU_SWAP_4_BYTES(temp_index
);
2808 totals
[k
] += *(const GLint
*)&swapbuf
* y_percent
;
2810 totals
[k
] += *(const GLint
*)temp_index
* y_percent
;
2815 percent
= y_percent
* highx_float
;
2816 for (k
= 0, temp_index
= temp
; k
< components
;
2817 k
++, temp_index
+= element_size
) {
2819 swapbuf
= __GLU_SWAP_4_BYTES(temp_index
);
2820 totals
[k
] += *(const GLint
*)&swapbuf
* percent
;
2822 totals
[k
] += *(const GLint
*)temp_index
* percent
;
2826 /* calculate the value for pixels in the 1st and last column */
2827 for(m
= lowy_int
+1; m
< highy_int
; m
++) {
2830 for (k
= 0; k
< components
;
2831 k
++, left
+= element_size
, right
+= element_size
) {
2833 swapbuf
= __GLU_SWAP_4_BYTES(left
);
2834 totals
[k
] += *(const GLint
*)&swapbuf
* (1-lowx_float
);
2835 swapbuf
= __GLU_SWAP_4_BYTES(right
);
2836 totals
[k
] += *(const GLint
*)&swapbuf
* highx_float
;
2838 totals
[k
] += *(const GLint
*)left
* (1-lowx_float
)
2839 + *(const GLint
*)right
* highx_float
;
2843 } else if (highy_int
> lowy_int
) {
2844 x_percent
= highx_float
- lowx_float
;
2845 percent
= (1-lowy_float
)*x_percent
;
2846 temp
= (const char *)datain
+ xindex
+ lowy_int
*ysize
;
2847 for (k
= 0, temp_index
= temp
; k
< components
;
2848 k
++, temp_index
+= element_size
) {
2850 swapbuf
= __GLU_SWAP_4_BYTES(temp_index
);
2851 totals
[k
] += *(const GLint
*)&swapbuf
* percent
;
2853 totals
[k
] += *(const GLint
*)temp_index
* percent
;
2856 for(m
= lowy_int
+1; m
< highy_int
; m
++) {
2858 for (k
= 0, temp_index
= temp
; k
< components
;
2859 k
++, temp_index
+= element_size
) {
2861 swapbuf
= __GLU_SWAP_4_BYTES(temp_index
);
2862 totals
[k
] += *(const GLint
*)&swapbuf
* x_percent
;
2864 totals
[k
] += *(const GLint
*)temp_index
* x_percent
;
2868 percent
= x_percent
* highy_float
;
2870 for (k
= 0, temp_index
= temp
; k
< components
;
2871 k
++, temp_index
+= element_size
) {
2873 swapbuf
= __GLU_SWAP_4_BYTES(temp_index
);
2874 totals
[k
] += *(const GLint
*)&swapbuf
* percent
;
2876 totals
[k
] += *(const GLint
*)temp_index
* percent
;
2879 } else if (highx_int
> lowx_int
) {
2880 y_percent
= highy_float
- lowy_float
;
2881 percent
= (1-lowx_float
)*y_percent
;
2883 temp
= (const char *)datain
+ xindex
+ lowy_int
*ysize
;
2884 for (k
= 0, temp_index
= temp
; k
< components
;
2885 k
++, temp_index
+= element_size
) {
2887 swapbuf
= __GLU_SWAP_4_BYTES(temp_index
);
2888 totals
[k
] += *(const GLint
*)&swapbuf
* percent
;
2890 totals
[k
] += *(const GLint
*)temp_index
* percent
;
2893 for (l
= lowx_int
+1; l
< highx_int
; l
++) {
2895 for (k
= 0, temp_index
= temp
; k
< components
;
2896 k
++, temp_index
+= element_size
) {
2898 swapbuf
= __GLU_SWAP_4_BYTES(temp_index
);
2899 totals
[k
] += *(const GLint
*)&swapbuf
* y_percent
;
2901 totals
[k
] += *(const GLint
*)temp_index
* y_percent
;
2906 percent
= y_percent
* highx_float
;
2907 for (k
= 0, temp_index
= temp
; k
< components
;
2908 k
++, temp_index
+= element_size
) {
2910 swapbuf
= __GLU_SWAP_4_BYTES(temp_index
);
2911 totals
[k
] += *(const GLint
*)&swapbuf
* percent
;
2913 totals
[k
] += *(const GLint
*)temp_index
* percent
;
2917 percent
= (highy_float
-lowy_float
)*(highx_float
-lowx_float
);
2918 temp
= (const char *)datain
+ xindex
+ lowy_int
* ysize
;
2919 for (k
= 0, temp_index
= temp
; k
< components
;
2920 k
++, temp_index
+= element_size
) {
2922 swapbuf
= __GLU_SWAP_4_BYTES(temp_index
);
2923 totals
[k
] += *(const GLint
*)&swapbuf
* percent
;
2925 totals
[k
] += *(const GLint
*)temp_index
* percent
;
2930 /* this is for the pixels in the body */
2931 temp0
= (const char *)datain
+ xindex
+ group_size
+
2933 for (m
= lowy_int
+1; m
< highy_int
; m
++) {
2935 for(l
= lowx_int
+1; l
< highx_int
; l
++) {
2936 for (k
= 0, temp_index
= temp
; k
< components
;
2937 k
++, temp_index
+= element_size
) {
2939 swapbuf
= __GLU_SWAP_4_BYTES(temp_index
);
2940 totals
[k
] += *(const GLint
*)&swapbuf
;
2942 totals
[k
] += *(const GLint
*)temp_index
;
2950 outindex
= (j
+ (i
* widthout
)) * components
;
2951 for (k
= 0; k
< components
; k
++) {
2952 dataout
[outindex
+ k
] = totals
[k
]/area
;
2953 /*printf("totals[%d] = %f\n", k, totals[k]);*/
2955 lowx_int
= highx_int
;
2956 lowx_float
= highx_float
;
2957 highx_int
+= convx_int
;
2958 highx_float
+= convx_float
;
2959 if(highx_float
> 1) {
2964 lowy_int
= highy_int
;
2965 lowy_float
= highy_float
;
2966 highy_int
+= convy_int
;
2967 highy_float
+= convy_float
;
2968 if(highy_float
> 1) {
2977 static void scale_internal_float(GLint components
, GLint widthin
,
2978 GLint heightin
, const GLfloat
*datain
,
2979 GLint widthout
, GLint heightout
,
2980 GLfloat
*dataout
, GLint element_size
,
2981 GLint ysize
, GLint group_size
,
2987 /* Max components in a format is 4, so... */
2992 const char *temp
, *temp0
;
2993 const char *temp_index
;
2996 int lowx_int
, highx_int
, lowy_int
, highy_int
;
2997 float x_percent
, y_percent
;
2998 float lowx_float
, highx_float
, lowy_float
, highy_float
;
2999 float convy_float
, convx_float
;
3000 int convy_int
, convx_int
;
3002 const char *left
, *right
;
3004 union { GLuint b
; GLfloat f
; } swapbuf
;
3006 if (widthin
== widthout
*2 && heightin
== heightout
*2) {
3007 halveImage_float(components
, widthin
, heightin
,
3008 (const GLfloat
*)datain
, (GLfloat
*)dataout
,
3009 element_size
, ysize
, group_size
, myswap_bytes
);
3012 convy
= (float) heightin
/heightout
;
3013 convx
= (float) widthin
/widthout
;
3014 convy_int
= floor(convy
);
3015 convy_float
= convy
- convy_int
;
3016 convx_int
= floor(convx
);
3017 convx_float
= convx
- convx_int
;
3019 area
= convx
* convy
;
3023 highy_int
= convy_int
;
3024 highy_float
= convy_float
;
3026 for (i
= 0; i
< heightout
; i
++) {
3027 /* Clamp here to be sure we don't read beyond input buffer. */
3028 if (highy_int
>= heightin
)
3029 highy_int
= heightin
- 1;
3032 highx_int
= convx_int
;
3033 highx_float
= convx_float
;
3035 for (j
= 0; j
< widthout
; j
++) {
3037 ** Ok, now apply box filter to box that goes from (lowx, lowy)
3038 ** to (highx, highy) on input data into this pixel on output
3041 totals
[0] = totals
[1] = totals
[2] = totals
[3] = 0.0;
3043 /* calculate the value for pixels in the 1st row */
3044 xindex
= lowx_int
*group_size
;
3045 if((highy_int
>lowy_int
) && (highx_int
>lowx_int
)) {
3047 y_percent
= 1-lowy_float
;
3048 temp
= (const char *)datain
+ xindex
+ lowy_int
* ysize
;
3049 percent
= y_percent
* (1-lowx_float
);
3050 for (k
= 0, temp_index
= temp
; k
< components
;
3051 k
++, temp_index
+= element_size
) {
3053 swapbuf
.b
= __GLU_SWAP_4_BYTES(temp_index
);
3054 totals
[k
] += swapbuf
.f
* percent
;
3056 totals
[k
] += *(const GLfloat
*)temp_index
* percent
;
3060 for(l
= lowx_int
+1; l
< highx_int
; l
++) {
3062 for (k
= 0, temp_index
= temp
; k
< components
;
3063 k
++, temp_index
+= element_size
) {
3065 swapbuf
.b
= __GLU_SWAP_4_BYTES(temp_index
);
3066 totals
[k
] += swapbuf
.f
* y_percent
;
3068 totals
[k
] += *(const GLfloat
*)temp_index
* y_percent
;
3074 percent
= y_percent
* highx_float
;
3075 for (k
= 0, temp_index
= temp
; k
< components
;
3076 k
++, temp_index
+= element_size
) {
3078 swapbuf
.b
= __GLU_SWAP_4_BYTES(temp_index
);
3079 totals
[k
] += swapbuf
.f
* percent
;
3081 totals
[k
] += *(const GLfloat
*)temp_index
* percent
;
3085 /* calculate the value for pixels in the last row */
3086 y_percent
= highy_float
;
3087 percent
= y_percent
* (1-lowx_float
);
3088 temp
= (const char *)datain
+ xindex
+ highy_int
* ysize
;
3089 for (k
= 0, temp_index
= temp
; k
< components
;
3090 k
++, temp_index
+= element_size
) {
3092 swapbuf
.b
= __GLU_SWAP_4_BYTES(temp_index
);
3093 totals
[k
] += swapbuf
.f
* percent
;
3095 totals
[k
] += *(const GLfloat
*)temp_index
* percent
;
3098 for(l
= lowx_int
+1; l
< highx_int
; l
++) {
3100 for (k
= 0, temp_index
= temp
; k
< components
;
3101 k
++, temp_index
+= element_size
) {
3103 swapbuf
.b
= __GLU_SWAP_4_BYTES(temp_index
);
3104 totals
[k
] += swapbuf
.f
* y_percent
;
3106 totals
[k
] += *(const GLfloat
*)temp_index
* y_percent
;
3111 percent
= y_percent
* highx_float
;
3112 for (k
= 0, temp_index
= temp
; k
< components
;
3113 k
++, temp_index
+= element_size
) {
3115 swapbuf
.b
= __GLU_SWAP_4_BYTES(temp_index
);
3116 totals
[k
] += swapbuf
.f
* percent
;
3118 totals
[k
] += *(const GLfloat
*)temp_index
* percent
;
3122 /* calculate the value for pixels in the 1st and last column */
3123 for(m
= lowy_int
+1; m
< highy_int
; m
++) {
3126 for (k
= 0; k
< components
;
3127 k
++, left
+= element_size
, right
+= element_size
) {
3129 swapbuf
.b
= __GLU_SWAP_4_BYTES(left
);
3130 totals
[k
] += swapbuf
.f
* (1-lowx_float
);
3131 swapbuf
.b
= __GLU_SWAP_4_BYTES(right
);
3132 totals
[k
] += swapbuf
.f
* highx_float
;
3134 totals
[k
] += *(const GLfloat
*)left
* (1-lowx_float
)
3135 + *(const GLfloat
*)right
* highx_float
;
3139 } else if (highy_int
> lowy_int
) {
3140 x_percent
= highx_float
- lowx_float
;
3141 percent
= (1-lowy_float
)*x_percent
;
3142 temp
= (const char *)datain
+ xindex
+ lowy_int
*ysize
;
3143 for (k
= 0, temp_index
= temp
; k
< components
;
3144 k
++, temp_index
+= element_size
) {
3146 swapbuf
.b
= __GLU_SWAP_4_BYTES(temp_index
);
3147 totals
[k
] += swapbuf
.f
* percent
;
3149 totals
[k
] += *(const GLfloat
*)temp_index
* percent
;
3152 for(m
= lowy_int
+1; m
< highy_int
; m
++) {
3154 for (k
= 0, temp_index
= temp
; k
< components
;
3155 k
++, temp_index
+= element_size
) {
3157 swapbuf
.b
= __GLU_SWAP_4_BYTES(temp_index
);
3158 totals
[k
] += swapbuf
.f
* x_percent
;
3160 totals
[k
] += *(const GLfloat
*)temp_index
* x_percent
;
3164 percent
= x_percent
* highy_float
;
3166 for (k
= 0, temp_index
= temp
; k
< components
;
3167 k
++, temp_index
+= element_size
) {
3169 swapbuf
.b
= __GLU_SWAP_4_BYTES(temp_index
);
3170 totals
[k
] += swapbuf
.f
* percent
;
3172 totals
[k
] += *(const GLfloat
*)temp_index
* percent
;
3175 } else if (highx_int
> lowx_int
) {
3176 y_percent
= highy_float
- lowy_float
;
3177 percent
= (1-lowx_float
)*y_percent
;
3179 temp
= (const char *)datain
+ xindex
+ lowy_int
*ysize
;
3180 for (k
= 0, temp_index
= temp
; k
< components
;
3181 k
++, temp_index
+= element_size
) {
3183 swapbuf
.b
= __GLU_SWAP_4_BYTES(temp_index
);
3184 totals
[k
] += swapbuf
.f
* percent
;
3186 totals
[k
] += *(const GLfloat
*)temp_index
* percent
;
3189 for (l
= lowx_int
+1; l
< highx_int
; l
++) {
3191 for (k
= 0, temp_index
= temp
; k
< components
;
3192 k
++, temp_index
+= element_size
) {
3194 swapbuf
.b
= __GLU_SWAP_4_BYTES(temp_index
);
3195 totals
[k
] += swapbuf
.f
* y_percent
;
3197 totals
[k
] += *(const GLfloat
*)temp_index
* y_percent
;
3202 percent
= y_percent
* highx_float
;
3203 for (k
= 0, temp_index
= temp
; k
< components
;
3204 k
++, temp_index
+= element_size
) {
3206 swapbuf
.b
= __GLU_SWAP_4_BYTES(temp_index
);
3207 totals
[k
] += swapbuf
.f
* percent
;
3209 totals
[k
] += *(const GLfloat
*)temp_index
* percent
;
3213 percent
= (highy_float
-lowy_float
)*(highx_float
-lowx_float
);
3214 temp
= (const char *)datain
+ xindex
+ lowy_int
* ysize
;
3215 for (k
= 0, temp_index
= temp
; k
< components
;
3216 k
++, temp_index
+= element_size
) {
3218 swapbuf
.b
= __GLU_SWAP_4_BYTES(temp_index
);
3219 totals
[k
] += swapbuf
.f
* percent
;
3221 totals
[k
] += *(const GLfloat
*)temp_index
* percent
;
3226 /* this is for the pixels in the body */
3227 temp0
= (const char *)datain
+ xindex
+ group_size
+
3229 for (m
= lowy_int
+1; m
< highy_int
; m
++) {
3231 for(l
= lowx_int
+1; l
< highx_int
; l
++) {
3232 for (k
= 0, temp_index
= temp
; k
< components
;
3233 k
++, temp_index
+= element_size
) {
3235 swapbuf
.b
= __GLU_SWAP_4_BYTES(temp_index
);
3236 totals
[k
] += swapbuf
.f
;
3238 totals
[k
] += *(const GLfloat
*)temp_index
;
3246 outindex
= (j
+ (i
* widthout
)) * components
;
3247 for (k
= 0; k
< components
; k
++) {
3248 dataout
[outindex
+ k
] = totals
[k
]/area
;
3249 /*printf("totals[%d] = %f\n", k, totals[k]);*/
3251 lowx_int
= highx_int
;
3252 lowx_float
= highx_float
;
3253 highx_int
+= convx_int
;
3254 highx_float
+= convx_float
;
3255 if(highx_float
> 1) {
3260 lowy_int
= highy_int
;
3261 lowy_float
= highy_float
;
3262 highy_int
+= convy_int
;
3263 highy_float
+= convy_float
;
3264 if(highy_float
> 1) {
3271 static int checkMipmapArgs(GLenum internalFormat
, GLenum format
, GLenum type
)
3273 if (!legalFormat(format
) || !legalType(type
)) {
3274 return GLU_INVALID_ENUM
;
3276 if (format
== GL_STENCIL_INDEX
) {
3277 return GLU_INVALID_ENUM
;
3280 if (!isLegalFormatForPackedPixelType(format
, type
)) {
3281 return GLU_INVALID_OPERATION
;
3285 } /* checkMipmapArgs() */
3287 static GLboolean
legalFormat(GLenum format
)
3290 case GL_COLOR_INDEX
:
3291 case GL_STENCIL_INDEX
:
3292 case GL_DEPTH_COMPONENT
:
3300 case GL_LUMINANCE_ALPHA
:
3310 static GLboolean
legalType(GLenum type
)
3315 case GL_UNSIGNED_BYTE
:
3317 case GL_UNSIGNED_SHORT
:
3319 case GL_UNSIGNED_INT
:
3321 case GL_UNSIGNED_BYTE_3_3_2
:
3322 case GL_UNSIGNED_BYTE_2_3_3_REV
:
3323 case GL_UNSIGNED_SHORT_5_6_5
:
3324 case GL_UNSIGNED_SHORT_5_6_5_REV
:
3325 case GL_UNSIGNED_SHORT_4_4_4_4
:
3326 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
3327 case GL_UNSIGNED_SHORT_5_5_5_1
:
3328 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
3329 case GL_UNSIGNED_INT_8_8_8_8
:
3330 case GL_UNSIGNED_INT_8_8_8_8_REV
:
3331 case GL_UNSIGNED_INT_10_10_10_2
:
3332 case GL_UNSIGNED_INT_2_10_10_10_REV
:
3340 static GLboolean
isTypePackedPixel(GLenum type
)
3342 assert(legalType(type
));
3344 if (type
== GL_UNSIGNED_BYTE_3_3_2
||
3345 type
== GL_UNSIGNED_BYTE_2_3_3_REV
||
3346 type
== GL_UNSIGNED_SHORT_5_6_5
||
3347 type
== GL_UNSIGNED_SHORT_5_6_5_REV
||
3348 type
== GL_UNSIGNED_SHORT_4_4_4_4
||
3349 type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
||
3350 type
== GL_UNSIGNED_SHORT_5_5_5_1
||
3351 type
== GL_UNSIGNED_SHORT_1_5_5_5_REV
||
3352 type
== GL_UNSIGNED_INT_8_8_8_8
||
3353 type
== GL_UNSIGNED_INT_8_8_8_8_REV
||
3354 type
== GL_UNSIGNED_INT_10_10_10_2
||
3355 type
== GL_UNSIGNED_INT_2_10_10_10_REV
) {
3359 } /* isTypePackedPixel() */
3361 /* Determines if the packed pixel type is compatible with the format */
3362 static GLboolean
isLegalFormatForPackedPixelType(GLenum format
, GLenum type
)
3364 /* if not a packed pixel type then return true */
3365 if (!isTypePackedPixel(type
)) {
3369 /* 3_3_2/2_3_3_REV & 5_6_5/5_6_5_REV are only compatible with RGB */
3370 if ((type
== GL_UNSIGNED_BYTE_3_3_2
|| type
== GL_UNSIGNED_BYTE_2_3_3_REV
||
3371 type
== GL_UNSIGNED_SHORT_5_6_5
|| type
== GL_UNSIGNED_SHORT_5_6_5_REV
)
3372 && format
!= GL_RGB
)
3375 /* 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 &
3376 * 10_10_10_2/2_10_10_10_REV are only compatible with RGBA, BGRA & ABGR_EXT.
3378 if ((type
== GL_UNSIGNED_SHORT_4_4_4_4
||
3379 type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
||
3380 type
== GL_UNSIGNED_SHORT_5_5_5_1
||
3381 type
== GL_UNSIGNED_SHORT_1_5_5_5_REV
||
3382 type
== GL_UNSIGNED_INT_8_8_8_8
||
3383 type
== GL_UNSIGNED_INT_8_8_8_8_REV
||
3384 type
== GL_UNSIGNED_INT_10_10_10_2
||
3385 type
== GL_UNSIGNED_INT_2_10_10_10_REV
) &&
3386 (format
!= GL_RGBA
&&
3387 format
!= GL_BGRA
)) {
3392 } /* isLegalFormatForPackedPixelType() */
3394 static GLboolean
isLegalLevels(GLint userLevel
,GLint baseLevel
,GLint maxLevel
,
3397 if (baseLevel
< 0 || baseLevel
< userLevel
|| maxLevel
< baseLevel
||
3398 totalLevels
< maxLevel
)
3400 else return GL_TRUE
;
3401 } /* isLegalLevels() */
3403 /* Given user requested texture size, determine if it fits. If it
3404 * doesn't then halve both sides and make the determination again
3405 * until it does fit (for IR only).
3406 * Note that proxy textures are not implemented in RE* even though
3407 * they advertise the texture extension.
3408 * Note that proxy textures are implemented but not according to spec in
3411 static void closestFit(GLenum target
, GLint width
, GLint height
,
3412 GLint internalFormat
, GLenum format
, GLenum type
,
3413 GLint
*newWidth
, GLint
*newHeight
)
3415 /* Use proxy textures if OpenGL version is >= 1.1 */
3416 if ( (strtod((const char *)glGetString(GL_VERSION
),NULL
) >= 1.1)
3418 GLint widthPowerOf2
= nearestPower(width
);
3419 GLint heightPowerOf2
= nearestPower(height
);
3423 /* compute level 1 width & height, clamping each at 1 */
3424 GLint widthAtLevelOne
= (widthPowerOf2
> 1) ?
3425 widthPowerOf2
>> 1 :
3427 GLint heightAtLevelOne
= (heightPowerOf2
> 1) ?
3428 heightPowerOf2
>> 1 :
3431 assert(widthAtLevelOne
> 0); assert(heightAtLevelOne
> 0);
3433 /* does width x height at level 1 & all their mipmaps fit? */
3434 if (target
== GL_TEXTURE_2D
|| target
== GL_PROXY_TEXTURE_2D
) {
3435 proxyTarget
= GL_PROXY_TEXTURE_2D
;
3436 glTexImage2D(proxyTarget
, 1, /* must be non-zero */
3438 widthAtLevelOne
,heightAtLevelOne
,0,format
,type
,NULL
);
3440 #if defined(GL_ARB_texture_cube_map)
3441 if ((target
== GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
) ||
3442 (target
== GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
) ||
3443 (target
== GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
) ||
3444 (target
== GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
) ||
3445 (target
== GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
) ||
3446 (target
== GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
)) {
3447 proxyTarget
= GL_PROXY_TEXTURE_CUBE_MAP_ARB
;
3448 glTexImage2D(proxyTarget
, 1, /* must be non-zero */
3450 widthAtLevelOne
,heightAtLevelOne
,0,format
,type
,NULL
);
3452 #endif /* GL_ARB_texture_cube_map */
3454 assert(target
== GL_TEXTURE_1D
|| target
== GL_PROXY_TEXTURE_1D
);
3455 proxyTarget
= GL_PROXY_TEXTURE_1D
;
3456 glTexImage1D(proxyTarget
, 1, /* must be non-zero */
3457 internalFormat
,widthAtLevelOne
,0,format
,type
,NULL
);
3459 glGetTexLevelParameteriv(proxyTarget
, 1,GL_TEXTURE_WIDTH
,&proxyWidth
);
3460 /* does it fit??? */
3461 if (proxyWidth
== 0) { /* nope, so try again with these sizes */
3462 if (widthPowerOf2
== 1 && heightPowerOf2
== 1) {
3463 /* An 1x1 texture couldn't fit for some reason, so
3464 * break out. This should never happen. But things
3465 * happen. The disadvantage with this if-statement is
3466 * that we will never be aware of when this happens
3467 * since it will silently branch out.
3469 goto noProxyTextures
;
3471 widthPowerOf2
= widthAtLevelOne
;
3472 heightPowerOf2
= heightAtLevelOne
;
3474 /* else it does fit */
3475 } while (proxyWidth
== 0);
3476 /* loop must terminate! */
3478 /* return the width & height at level 0 that fits */
3479 *newWidth
= widthPowerOf2
;
3480 *newHeight
= heightPowerOf2
;
3481 /*printf("Proxy Textures\n");*/
3482 } /* if gluCheckExtension() */
3483 else { /* no texture extension, so do this instead */
3488 glGetIntegerv(GL_MAX_TEXTURE_SIZE
, &maxsize
);
3489 /* clamp user's texture sizes to maximum sizes, if necessary */
3490 *newWidth
= nearestPower(width
);
3491 if (*newWidth
> maxsize
) *newWidth
= maxsize
;
3492 *newHeight
= nearestPower(height
);
3493 if (*newHeight
> maxsize
) *newHeight
= maxsize
;
3494 /*printf("NO proxy textures\n");*/
3496 } /* closestFit() */
3499 gluScaleImage(GLenum format
, GLsizei widthin
, GLsizei heightin
,
3500 GLenum typein
, const void *datain
,
3501 GLsizei widthout
, GLsizei heightout
, GLenum typeout
,
3505 GLushort
*beforeImage
;
3506 GLushort
*afterImage
;
3507 PixelStorageModes psm
;
3509 if (widthin
== 0 || heightin
== 0 || widthout
== 0 || heightout
== 0) {
3512 if (widthin
< 0 || heightin
< 0 || widthout
< 0 || heightout
< 0) {
3513 return GLU_INVALID_VALUE
;
3515 if (!legalFormat(format
) || !legalType(typein
) || !legalType(typeout
)) {
3516 return GLU_INVALID_ENUM
;
3518 if (!isLegalFormatForPackedPixelType(format
, typein
)) {
3519 return GLU_INVALID_OPERATION
;
3521 if (!isLegalFormatForPackedPixelType(format
, typeout
)) {
3522 return GLU_INVALID_OPERATION
;
3525 malloc(image_size(widthin
, heightin
, format
, GL_UNSIGNED_SHORT
));
3527 malloc(image_size(widthout
, heightout
, format
, GL_UNSIGNED_SHORT
));
3528 if (beforeImage
== NULL
|| afterImage
== NULL
) {
3531 return GLU_OUT_OF_MEMORY
;
3534 retrieveStoreModes(&psm
);
3535 fill_image(&psm
,widthin
, heightin
, format
, typein
, is_index(format
),
3536 datain
, beforeImage
);
3537 components
= elements_per_group(format
, 0);
3538 scale_internal(components
, widthin
, heightin
, beforeImage
,
3539 widthout
, heightout
, afterImage
);
3540 empty_image(&psm
,widthout
, heightout
, format
, typeout
,
3541 is_index(format
), afterImage
, dataout
);
3542 free((GLbyte
*) beforeImage
);
3543 free((GLbyte
*) afterImage
);
3548 int gluBuild1DMipmapLevelsCore(GLenum target
, GLint internalFormat
,
3550 GLsizei widthPowerOf2
,
3551 GLenum format
, GLenum type
,
3552 GLint userLevel
, GLint baseLevel
,GLint maxLevel
,
3556 GLint level
, levels
;
3558 GLint newImage_width
;
3559 GLushort
*otherImage
;
3560 GLushort
*imageTemp
;
3563 PixelStorageModes psm
;
3565 assert(checkMipmapArgs(internalFormat
,format
,type
) == 0);
3570 newwidth
= widthPowerOf2
;
3571 levels
= computeLog(newwidth
);
3575 retrieveStoreModes(&psm
);
3576 newImage
= (GLushort
*)
3577 malloc(image_size(width
, 1, format
, GL_UNSIGNED_SHORT
));
3578 newImage_width
= width
;
3579 if (newImage
== NULL
) {
3580 return GLU_OUT_OF_MEMORY
;
3582 fill_image(&psm
,width
, 1, format
, type
, is_index(format
),
3584 cmpts
= elements_per_group(format
,type
);
3585 glPixelStorei(GL_UNPACK_ALIGNMENT
, 2);
3586 glPixelStorei(GL_UNPACK_SKIP_ROWS
, 0);
3587 glPixelStorei(GL_UNPACK_SKIP_PIXELS
, 0);
3588 glPixelStorei(GL_UNPACK_ROW_LENGTH
, 0);
3590 ** If swap_bytes was set, swapping occurred in fill_image.
3592 glPixelStorei(GL_UNPACK_SWAP_BYTES
, GL_FALSE
);
3594 for (level
= userLevel
; level
<= levels
; level
++) {
3595 if (newImage_width
== newwidth
) {
3596 /* Use newImage for this level */
3597 if (baseLevel
<= level
&& level
<= maxLevel
) {
3598 glTexImage1D(target
, level
, internalFormat
, newImage_width
,
3599 0, format
, GL_UNSIGNED_SHORT
, (void *) newImage
);
3602 if (otherImage
== NULL
) {
3603 memreq
= image_size(newwidth
, 1, format
, GL_UNSIGNED_SHORT
);
3604 otherImage
= (GLushort
*) malloc(memreq
);
3605 if (otherImage
== NULL
) {
3606 glPixelStorei(GL_UNPACK_ALIGNMENT
, psm
.unpack_alignment
);
3607 glPixelStorei(GL_UNPACK_SKIP_ROWS
, psm
.unpack_skip_rows
);
3608 glPixelStorei(GL_UNPACK_SKIP_PIXELS
,psm
.unpack_skip_pixels
);
3609 glPixelStorei(GL_UNPACK_ROW_LENGTH
, psm
.unpack_row_length
);
3610 glPixelStorei(GL_UNPACK_SWAP_BYTES
, psm
.unpack_swap_bytes
);
3611 return GLU_OUT_OF_MEMORY
;
3614 scale_internal(cmpts
, newImage_width
, 1, newImage
,
3615 newwidth
, 1, otherImage
);
3616 /* Swap newImage and otherImage */
3617 imageTemp
= otherImage
;
3618 otherImage
= newImage
;
3619 newImage
= imageTemp
;
3621 newImage_width
= newwidth
;
3622 if (baseLevel
<= level
&& level
<= maxLevel
) {
3623 glTexImage1D(target
, level
, internalFormat
, newImage_width
,
3624 0, format
, GL_UNSIGNED_SHORT
, (void *) newImage
);
3627 if (newwidth
> 1) newwidth
/= 2;
3629 glPixelStorei(GL_UNPACK_ALIGNMENT
, psm
.unpack_alignment
);
3630 glPixelStorei(GL_UNPACK_SKIP_ROWS
, psm
.unpack_skip_rows
);
3631 glPixelStorei(GL_UNPACK_SKIP_PIXELS
, psm
.unpack_skip_pixels
);
3632 glPixelStorei(GL_UNPACK_ROW_LENGTH
, psm
.unpack_row_length
);
3633 glPixelStorei(GL_UNPACK_SWAP_BYTES
, psm
.unpack_swap_bytes
);
3635 free((GLbyte
*) newImage
);
3637 free((GLbyte
*) otherImage
);
3643 gluBuild1DMipmapLevels(GLenum target
, GLint internalFormat
,
3645 GLenum format
, GLenum type
,
3646 GLint userLevel
, GLint baseLevel
, GLint maxLevel
,
3651 int rc
= checkMipmapArgs(internalFormat
,format
,type
);
3652 if (rc
!= 0) return rc
;
3655 return GLU_INVALID_VALUE
;
3658 levels
= computeLog(width
);
3661 if (!isLegalLevels(userLevel
,baseLevel
,maxLevel
,levels
))
3662 return GLU_INVALID_VALUE
;
3664 return gluBuild1DMipmapLevelsCore(target
, internalFormat
,
3667 userLevel
, baseLevel
, maxLevel
,
3669 } /* gluBuild1DMipmapLevels() */
3672 gluBuild1DMipmaps(GLenum target
, GLint internalFormat
, GLsizei width
,
3673 GLenum format
, GLenum type
,
3676 GLint widthPowerOf2
;
3680 int rc
= checkMipmapArgs(internalFormat
,format
,type
);
3681 if (rc
!= 0) return rc
;
3684 return GLU_INVALID_VALUE
;
3687 closestFit(target
,width
,1,internalFormat
,format
,type
,&widthPowerOf2
,&dummy
);
3688 levels
= computeLog(widthPowerOf2
);
3690 return gluBuild1DMipmapLevelsCore(target
,internalFormat
,
3693 format
,type
,0,0,levels
,data
);
3696 static int bitmapBuild2DMipmaps(GLenum target
, GLint internalFormat
,
3697 GLint width
, GLint height
, GLenum format
,
3698 GLenum type
, const void *data
)
3700 GLint newwidth
, newheight
;
3701 GLint level
, levels
;
3703 GLint newImage_width
;
3704 GLint newImage_height
;
3705 GLushort
*otherImage
;
3706 GLushort
*imageTemp
;
3709 PixelStorageModes psm
;
3711 retrieveStoreModes(&psm
);
3714 glGetIntegerv(GL_MAX_TEXTURE_SIZE
, &maxsize
);
3715 newwidth
= nearestPower(width
);
3716 if (newwidth
> maxsize
) newwidth
= maxsize
;
3717 newheight
= nearestPower(height
);
3718 if (newheight
> maxsize
) newheight
= maxsize
;
3720 closestFit(target
,width
,height
,internalFormat
,format
,type
,
3721 &newwidth
,&newheight
);
3723 levels
= computeLog(newwidth
);
3724 level
= computeLog(newheight
);
3725 if (level
> levels
) levels
=level
;
3728 newImage
= (GLushort
*)
3729 malloc(image_size(width
, height
, format
, GL_UNSIGNED_SHORT
));
3730 newImage_width
= width
;
3731 newImage_height
= height
;
3732 if (newImage
== NULL
) {
3733 return GLU_OUT_OF_MEMORY
;
3736 fill_image(&psm
,width
, height
, format
, type
, is_index(format
),
3739 cmpts
= elements_per_group(format
,type
);
3740 glPixelStorei(GL_UNPACK_ALIGNMENT
, 2);
3741 glPixelStorei(GL_UNPACK_SKIP_ROWS
, 0);
3742 glPixelStorei(GL_UNPACK_SKIP_PIXELS
, 0);
3743 glPixelStorei(GL_UNPACK_ROW_LENGTH
, 0);
3745 ** If swap_bytes was set, swapping occurred in fill_image.
3747 glPixelStorei(GL_UNPACK_SWAP_BYTES
, GL_FALSE
);
3749 for (level
= 0; level
<= levels
; level
++) {
3750 if (newImage_width
== newwidth
&& newImage_height
== newheight
) { /* Use newImage for this level */
3751 glTexImage2D(target
, level
, internalFormat
, newImage_width
,
3752 newImage_height
, 0, format
, GL_UNSIGNED_SHORT
,
3755 if (otherImage
== NULL
) {
3757 image_size(newwidth
, newheight
, format
, GL_UNSIGNED_SHORT
);
3758 otherImage
= (GLushort
*) malloc(memreq
);
3759 if (otherImage
== NULL
) {
3760 glPixelStorei(GL_UNPACK_ALIGNMENT
, psm
.unpack_alignment
);
3761 glPixelStorei(GL_UNPACK_SKIP_ROWS
, psm
.unpack_skip_rows
);
3762 glPixelStorei(GL_UNPACK_SKIP_PIXELS
,psm
.unpack_skip_pixels
);
3763 glPixelStorei(GL_UNPACK_ROW_LENGTH
, psm
.unpack_row_length
);
3764 glPixelStorei(GL_UNPACK_SWAP_BYTES
, psm
.unpack_swap_bytes
);
3766 return GLU_OUT_OF_MEMORY
;
3769 scale_internal(cmpts
, newImage_width
, newImage_height
, newImage
,
3770 newwidth
, newheight
, otherImage
);
3771 /* Swap newImage and otherImage */
3772 imageTemp
= otherImage
;
3773 otherImage
= newImage
;
3774 newImage
= imageTemp
;
3776 newImage_width
= newwidth
;
3777 newImage_height
= newheight
;
3778 glTexImage2D(target
, level
, internalFormat
, newImage_width
,
3779 newImage_height
, 0, format
, GL_UNSIGNED_SHORT
,
3782 if (newwidth
> 1) newwidth
/= 2;
3783 if (newheight
> 1) newheight
/= 2;
3785 glPixelStorei(GL_UNPACK_ALIGNMENT
, psm
.unpack_alignment
);
3786 glPixelStorei(GL_UNPACK_SKIP_ROWS
, psm
.unpack_skip_rows
);
3787 glPixelStorei(GL_UNPACK_SKIP_PIXELS
, psm
.unpack_skip_pixels
);
3788 glPixelStorei(GL_UNPACK_ROW_LENGTH
, psm
.unpack_row_length
);
3789 glPixelStorei(GL_UNPACK_SWAP_BYTES
, psm
.unpack_swap_bytes
);
3791 free((GLbyte
*) newImage
);
3793 free((GLbyte
*) otherImage
);
3798 /* To make swapping images less error prone */
3799 #define __GLU_INIT_SWAP_IMAGE void *tmpImage
3800 #define __GLU_SWAP_IMAGE(a,b) tmpImage = a; a = b; b = tmpImage;
3802 static int gluBuild2DMipmapLevelsCore(GLenum target
, GLint internalFormat
,
3803 GLsizei width
, GLsizei height
,
3804 GLsizei widthPowerOf2
,
3805 GLsizei heightPowerOf2
,
3806 GLenum format
, GLenum type
,
3808 GLint baseLevel
,GLint maxLevel
,
3811 GLint newwidth
, newheight
;
3812 GLint level
, levels
;
3813 const void *usersImage
; /* passed from user. Don't touch! */
3814 void *srcImage
, *dstImage
; /* scratch area to build mipmapped images */
3815 __GLU_INIT_SWAP_IMAGE
;
3819 GLint myswap_bytes
, groups_per_line
, element_size
, group_size
;
3820 GLint rowsize
, padding
;
3821 PixelStorageModes psm
;
3823 assert(checkMipmapArgs(internalFormat
,format
,type
) == 0);
3824 assert(width
>= 1 && height
>= 1);
3826 if(type
== GL_BITMAP
) {
3827 return bitmapBuild2DMipmaps(target
, internalFormat
, width
, height
,
3828 format
, type
, data
);
3831 srcImage
= dstImage
= NULL
;
3833 newwidth
= widthPowerOf2
;
3834 newheight
= heightPowerOf2
;
3835 levels
= computeLog(newwidth
);
3836 level
= computeLog(newheight
);
3837 if (level
> levels
) levels
=level
;
3841 retrieveStoreModes(&psm
);
3842 myswap_bytes
= psm
.unpack_swap_bytes
;
3843 cmpts
= elements_per_group(format
,type
);
3844 if (psm
.unpack_row_length
> 0) {
3845 groups_per_line
= psm
.unpack_row_length
;
3847 groups_per_line
= width
;
3850 element_size
= bytes_per_element(type
);
3851 group_size
= element_size
* cmpts
;
3852 if (element_size
== 1) myswap_bytes
= 0;
3854 rowsize
= groups_per_line
* group_size
;
3855 padding
= (rowsize
% psm
.unpack_alignment
);
3857 rowsize
+= psm
.unpack_alignment
- padding
;
3859 usersImage
= (const GLubyte
*) data
+ psm
.unpack_skip_rows
* rowsize
+
3860 psm
.unpack_skip_pixels
* group_size
;
3862 glPixelStorei(GL_UNPACK_SKIP_ROWS
, 0);
3863 glPixelStorei(GL_UNPACK_SKIP_PIXELS
, 0);
3864 glPixelStorei(GL_UNPACK_ROW_LENGTH
, 0);
3868 /* already power-of-two square */
3869 if (width
== newwidth
&& height
== newheight
) {
3870 /* Use usersImage for level userLevel */
3871 if (baseLevel
<= level
&& level
<= maxLevel
) {
3872 glPixelStorei(GL_UNPACK_ROW_LENGTH
, psm
.unpack_row_length
);
3873 glTexImage2D(target
, level
, internalFormat
, width
,
3874 height
, 0, format
, type
,
3877 glPixelStorei(GL_UNPACK_ROW_LENGTH
, 0);
3878 if(levels
== 0) { /* we're done. clean up and return */
3879 glPixelStorei(GL_UNPACK_ALIGNMENT
, psm
.unpack_alignment
);
3880 glPixelStorei(GL_UNPACK_SKIP_ROWS
, psm
.unpack_skip_rows
);
3881 glPixelStorei(GL_UNPACK_SKIP_PIXELS
, psm
.unpack_skip_pixels
);
3882 glPixelStorei(GL_UNPACK_ROW_LENGTH
, psm
.unpack_row_length
);
3883 glPixelStorei(GL_UNPACK_SWAP_BYTES
, psm
.unpack_swap_bytes
);
3887 int nextWidth
= newwidth
/2;
3888 int nextHeight
= newheight
/2;
3891 if (nextWidth
< 1) nextWidth
= 1;
3892 if (nextHeight
< 1) nextHeight
= 1;
3893 memreq
= image_size(nextWidth
, nextHeight
, format
, type
);
3897 case GL_UNSIGNED_BYTE
:
3898 dstImage
= (GLubyte
*)malloc(memreq
);
3901 dstImage
= (GLbyte
*)malloc(memreq
);
3903 case GL_UNSIGNED_SHORT
:
3904 dstImage
= (GLushort
*)malloc(memreq
);
3907 dstImage
= (GLshort
*)malloc(memreq
);
3909 case GL_UNSIGNED_INT
:
3910 dstImage
= (GLuint
*)malloc(memreq
);
3913 dstImage
= (GLint
*)malloc(memreq
);
3916 dstImage
= (GLfloat
*)malloc(memreq
);
3918 case GL_UNSIGNED_BYTE_3_3_2
:
3919 case GL_UNSIGNED_BYTE_2_3_3_REV
:
3920 dstImage
= (GLubyte
*)malloc(memreq
);
3922 case GL_UNSIGNED_SHORT_5_6_5
:
3923 case GL_UNSIGNED_SHORT_5_6_5_REV
:
3924 case GL_UNSIGNED_SHORT_4_4_4_4
:
3925 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
3926 case GL_UNSIGNED_SHORT_5_5_5_1
:
3927 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
3928 dstImage
= (GLushort
*)malloc(memreq
);
3930 case GL_UNSIGNED_INT_8_8_8_8
:
3931 case GL_UNSIGNED_INT_8_8_8_8_REV
:
3932 case GL_UNSIGNED_INT_10_10_10_2
:
3933 case GL_UNSIGNED_INT_2_10_10_10_REV
:
3934 dstImage
= (GLuint
*)malloc(memreq
);
3937 return GLU_INVALID_ENUM
;
3939 if (dstImage
== NULL
) {
3940 glPixelStorei(GL_UNPACK_ALIGNMENT
, psm
.unpack_alignment
);
3941 glPixelStorei(GL_UNPACK_SKIP_ROWS
, psm
.unpack_skip_rows
);
3942 glPixelStorei(GL_UNPACK_SKIP_PIXELS
, psm
.unpack_skip_pixels
);
3943 glPixelStorei(GL_UNPACK_ROW_LENGTH
, psm
.unpack_row_length
);
3944 glPixelStorei(GL_UNPACK_SWAP_BYTES
, psm
.unpack_swap_bytes
);
3945 return GLU_OUT_OF_MEMORY
;
3949 case GL_UNSIGNED_BYTE
:
3950 halveImage_ubyte(cmpts
, width
, height
,
3951 (const GLubyte
*)usersImage
, (GLubyte
*)dstImage
,
3952 element_size
, rowsize
, group_size
);
3955 halveImage_byte(cmpts
, width
, height
,
3956 (const GLbyte
*)usersImage
, (GLbyte
*)dstImage
,
3957 element_size
, rowsize
, group_size
);
3959 case GL_UNSIGNED_SHORT
:
3960 halveImage_ushort(cmpts
, width
, height
,
3961 (const GLushort
*)usersImage
, (GLushort
*)dstImage
,
3962 element_size
, rowsize
, group_size
, myswap_bytes
);
3965 halveImage_short(cmpts
, width
, height
,
3966 (const GLshort
*)usersImage
, (GLshort
*)dstImage
,
3967 element_size
, rowsize
, group_size
, myswap_bytes
);
3969 case GL_UNSIGNED_INT
:
3970 halveImage_uint(cmpts
, width
, height
,
3971 (const GLuint
*)usersImage
, (GLuint
*)dstImage
,
3972 element_size
, rowsize
, group_size
, myswap_bytes
);
3975 halveImage_int(cmpts
, width
, height
,
3976 (const GLint
*)usersImage
, (GLint
*)dstImage
,
3977 element_size
, rowsize
, group_size
, myswap_bytes
);
3980 halveImage_float(cmpts
, width
, height
,
3981 (const GLfloat
*)usersImage
, (GLfloat
*)dstImage
,
3982 element_size
, rowsize
, group_size
, myswap_bytes
);
3984 case GL_UNSIGNED_BYTE_3_3_2
:
3985 assert(format
== GL_RGB
);
3986 halveImagePackedPixel(3,extract332
,shove332
,
3987 width
,height
,usersImage
,dstImage
,
3988 element_size
,rowsize
,myswap_bytes
);
3990 case GL_UNSIGNED_BYTE_2_3_3_REV
:
3991 assert(format
== GL_RGB
);
3992 halveImagePackedPixel(3,extract233rev
,shove233rev
,
3993 width
,height
,usersImage
,dstImage
,
3994 element_size
,rowsize
,myswap_bytes
);
3996 case GL_UNSIGNED_SHORT_5_6_5
:
3997 halveImagePackedPixel(3,extract565
,shove565
,
3998 width
,height
,usersImage
,dstImage
,
3999 element_size
,rowsize
,myswap_bytes
);
4001 case GL_UNSIGNED_SHORT_5_6_5_REV
:
4002 halveImagePackedPixel(3,extract565rev
,shove565rev
,
4003 width
,height
,usersImage
,dstImage
,
4004 element_size
,rowsize
,myswap_bytes
);
4006 case GL_UNSIGNED_SHORT_4_4_4_4
:
4007 halveImagePackedPixel(4,extract4444
,shove4444
,
4008 width
,height
,usersImage
,dstImage
,
4009 element_size
,rowsize
,myswap_bytes
);
4011 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
4012 halveImagePackedPixel(4,extract4444rev
,shove4444rev
,
4013 width
,height
,usersImage
,dstImage
,
4014 element_size
,rowsize
,myswap_bytes
);
4016 case GL_UNSIGNED_SHORT_5_5_5_1
:
4017 halveImagePackedPixel(4,extract5551
,shove5551
,
4018 width
,height
,usersImage
,dstImage
,
4019 element_size
,rowsize
,myswap_bytes
);
4021 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
4022 halveImagePackedPixel(4,extract1555rev
,shove1555rev
,
4023 width
,height
,usersImage
,dstImage
,
4024 element_size
,rowsize
,myswap_bytes
);
4026 case GL_UNSIGNED_INT_8_8_8_8
:
4027 halveImagePackedPixel(4,extract8888
,shove8888
,
4028 width
,height
,usersImage
,dstImage
,
4029 element_size
,rowsize
,myswap_bytes
);
4031 case GL_UNSIGNED_INT_8_8_8_8_REV
:
4032 halveImagePackedPixel(4,extract8888rev
,shove8888rev
,
4033 width
,height
,usersImage
,dstImage
,
4034 element_size
,rowsize
,myswap_bytes
);
4036 case GL_UNSIGNED_INT_10_10_10_2
:
4037 halveImagePackedPixel(4,extract1010102
,shove1010102
,
4038 width
,height
,usersImage
,dstImage
,
4039 element_size
,rowsize
,myswap_bytes
);
4041 case GL_UNSIGNED_INT_2_10_10_10_REV
:
4042 halveImagePackedPixel(4,extract2101010rev
,shove2101010rev
,
4043 width
,height
,usersImage
,dstImage
,
4044 element_size
,rowsize
,myswap_bytes
);
4051 newheight
= height
/2;
4053 if (newwidth
< 1) newwidth
= 1;
4054 if (newheight
< 1) newheight
= 1;
4057 rowsize
= newwidth
* group_size
;
4058 memreq
= image_size(newwidth
, newheight
, format
, type
);
4059 /* Swap srcImage and dstImage */
4060 __GLU_SWAP_IMAGE(srcImage
,dstImage
);
4062 case GL_UNSIGNED_BYTE
:
4063 dstImage
= (GLubyte
*)malloc(memreq
);
4066 dstImage
= (GLbyte
*)malloc(memreq
);
4068 case GL_UNSIGNED_SHORT
:
4069 dstImage
= (GLushort
*)malloc(memreq
);
4072 dstImage
= (GLshort
*)malloc(memreq
);
4074 case GL_UNSIGNED_INT
:
4075 dstImage
= (GLuint
*)malloc(memreq
);
4078 dstImage
= (GLint
*)malloc(memreq
);
4081 dstImage
= (GLfloat
*)malloc(memreq
);
4083 case GL_UNSIGNED_BYTE_3_3_2
:
4084 case GL_UNSIGNED_BYTE_2_3_3_REV
:
4085 dstImage
= (GLubyte
*)malloc(memreq
);
4087 case GL_UNSIGNED_SHORT_5_6_5
:
4088 case GL_UNSIGNED_SHORT_5_6_5_REV
:
4089 case GL_UNSIGNED_SHORT_4_4_4_4
:
4090 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
4091 case GL_UNSIGNED_SHORT_5_5_5_1
:
4092 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
4093 dstImage
= (GLushort
*)malloc(memreq
);
4095 case GL_UNSIGNED_INT_8_8_8_8
:
4096 case GL_UNSIGNED_INT_8_8_8_8_REV
:
4097 case GL_UNSIGNED_INT_10_10_10_2
:
4098 case GL_UNSIGNED_INT_2_10_10_10_REV
:
4099 dstImage
= (GLuint
*)malloc(memreq
);
4102 return GLU_INVALID_ENUM
;
4104 if (dstImage
== NULL
) {
4105 glPixelStorei(GL_UNPACK_ALIGNMENT
, psm
.unpack_alignment
);
4106 glPixelStorei(GL_UNPACK_SKIP_ROWS
, psm
.unpack_skip_rows
);
4107 glPixelStorei(GL_UNPACK_SKIP_PIXELS
, psm
.unpack_skip_pixels
);
4108 glPixelStorei(GL_UNPACK_ROW_LENGTH
, psm
.unpack_row_length
);
4109 glPixelStorei(GL_UNPACK_SWAP_BYTES
, psm
.unpack_swap_bytes
);
4110 return GLU_OUT_OF_MEMORY
;
4112 /* level userLevel+1 is in srcImage; level userLevel already saved */
4113 level
= userLevel
+1;
4114 } else { /* user's image is *not* nice power-of-2 sized square */
4115 memreq
= image_size(newwidth
, newheight
, format
, type
);
4117 case GL_UNSIGNED_BYTE
:
4118 dstImage
= (GLubyte
*)malloc(memreq
);
4121 dstImage
= (GLbyte
*)malloc(memreq
);
4123 case GL_UNSIGNED_SHORT
:
4124 dstImage
= (GLushort
*)malloc(memreq
);
4127 dstImage
= (GLshort
*)malloc(memreq
);
4129 case GL_UNSIGNED_INT
:
4130 dstImage
= (GLuint
*)malloc(memreq
);
4133 dstImage
= (GLint
*)malloc(memreq
);
4136 dstImage
= (GLfloat
*)malloc(memreq
);
4138 case GL_UNSIGNED_BYTE_3_3_2
:
4139 case GL_UNSIGNED_BYTE_2_3_3_REV
:
4140 dstImage
= (GLubyte
*)malloc(memreq
);
4142 case GL_UNSIGNED_SHORT_5_6_5
:
4143 case GL_UNSIGNED_SHORT_5_6_5_REV
:
4144 case GL_UNSIGNED_SHORT_4_4_4_4
:
4145 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
4146 case GL_UNSIGNED_SHORT_5_5_5_1
:
4147 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
4148 dstImage
= (GLushort
*)malloc(memreq
);
4150 case GL_UNSIGNED_INT_8_8_8_8
:
4151 case GL_UNSIGNED_INT_8_8_8_8_REV
:
4152 case GL_UNSIGNED_INT_10_10_10_2
:
4153 case GL_UNSIGNED_INT_2_10_10_10_REV
:
4154 dstImage
= (GLuint
*)malloc(memreq
);
4157 return GLU_INVALID_ENUM
;
4160 if (dstImage
== NULL
) {
4161 glPixelStorei(GL_UNPACK_ALIGNMENT
, psm
.unpack_alignment
);
4162 glPixelStorei(GL_UNPACK_SKIP_ROWS
, psm
.unpack_skip_rows
);
4163 glPixelStorei(GL_UNPACK_SKIP_PIXELS
, psm
.unpack_skip_pixels
);
4164 glPixelStorei(GL_UNPACK_ROW_LENGTH
, psm
.unpack_row_length
);
4165 glPixelStorei(GL_UNPACK_SWAP_BYTES
, psm
.unpack_swap_bytes
);
4166 return GLU_OUT_OF_MEMORY
;
4170 case GL_UNSIGNED_BYTE
:
4171 scale_internal_ubyte(cmpts
, width
, height
,
4172 (const GLubyte
*)usersImage
, newwidth
, newheight
,
4173 (GLubyte
*)dstImage
, element_size
,
4174 rowsize
, group_size
);
4177 scale_internal_byte(cmpts
, width
, height
,
4178 (const GLbyte
*)usersImage
, newwidth
, newheight
,
4179 (GLbyte
*)dstImage
, element_size
,
4180 rowsize
, group_size
);
4182 case GL_UNSIGNED_SHORT
:
4183 scale_internal_ushort(cmpts
, width
, height
,
4184 (const GLushort
*)usersImage
, newwidth
, newheight
,
4185 (GLushort
*)dstImage
, element_size
,
4186 rowsize
, group_size
, myswap_bytes
);
4189 scale_internal_short(cmpts
, width
, height
,
4190 (const GLshort
*)usersImage
, newwidth
, newheight
,
4191 (GLshort
*)dstImage
, element_size
,
4192 rowsize
, group_size
, myswap_bytes
);
4194 case GL_UNSIGNED_INT
:
4195 scale_internal_uint(cmpts
, width
, height
,
4196 (const GLuint
*)usersImage
, newwidth
, newheight
,
4197 (GLuint
*)dstImage
, element_size
,
4198 rowsize
, group_size
, myswap_bytes
);
4201 scale_internal_int(cmpts
, width
, height
,
4202 (const GLint
*)usersImage
, newwidth
, newheight
,
4203 (GLint
*)dstImage
, element_size
,
4204 rowsize
, group_size
, myswap_bytes
);
4207 scale_internal_float(cmpts
, width
, height
,
4208 (const GLfloat
*)usersImage
, newwidth
, newheight
,
4209 (GLfloat
*)dstImage
, element_size
,
4210 rowsize
, group_size
, myswap_bytes
);
4212 case GL_UNSIGNED_BYTE_3_3_2
:
4213 scaleInternalPackedPixel(3,extract332
,shove332
,
4214 width
, height
,usersImage
,
4215 newwidth
,newheight
,(void *)dstImage
,
4216 element_size
,rowsize
,myswap_bytes
);
4218 case GL_UNSIGNED_BYTE_2_3_3_REV
:
4219 scaleInternalPackedPixel(3,extract233rev
,shove233rev
,
4220 width
, height
,usersImage
,
4221 newwidth
,newheight
,(void *)dstImage
,
4222 element_size
,rowsize
,myswap_bytes
);
4224 case GL_UNSIGNED_SHORT_5_6_5
:
4225 scaleInternalPackedPixel(3,extract565
,shove565
,
4226 width
, height
,usersImage
,
4227 newwidth
,newheight
,(void *)dstImage
,
4228 element_size
,rowsize
,myswap_bytes
);
4230 case GL_UNSIGNED_SHORT_5_6_5_REV
:
4231 scaleInternalPackedPixel(3,extract565rev
,shove565rev
,
4232 width
, height
,usersImage
,
4233 newwidth
,newheight
,(void *)dstImage
,
4234 element_size
,rowsize
,myswap_bytes
);
4236 case GL_UNSIGNED_SHORT_4_4_4_4
:
4237 scaleInternalPackedPixel(4,extract4444
,shove4444
,
4238 width
, height
,usersImage
,
4239 newwidth
,newheight
,(void *)dstImage
,
4240 element_size
,rowsize
,myswap_bytes
);
4242 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
4243 scaleInternalPackedPixel(4,extract4444rev
,shove4444rev
,
4244 width
, height
,usersImage
,
4245 newwidth
,newheight
,(void *)dstImage
,
4246 element_size
,rowsize
,myswap_bytes
);
4248 case GL_UNSIGNED_SHORT_5_5_5_1
:
4249 scaleInternalPackedPixel(4,extract5551
,shove5551
,
4250 width
, height
,usersImage
,
4251 newwidth
,newheight
,(void *)dstImage
,
4252 element_size
,rowsize
,myswap_bytes
);
4254 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
4255 scaleInternalPackedPixel(4,extract1555rev
,shove1555rev
,
4256 width
, height
,usersImage
,
4257 newwidth
,newheight
,(void *)dstImage
,
4258 element_size
,rowsize
,myswap_bytes
);
4260 case GL_UNSIGNED_INT_8_8_8_8
:
4261 scaleInternalPackedPixel(4,extract8888
,shove8888
,
4262 width
, height
,usersImage
,
4263 newwidth
,newheight
,(void *)dstImage
,
4264 element_size
,rowsize
,myswap_bytes
);
4266 case GL_UNSIGNED_INT_8_8_8_8_REV
:
4267 scaleInternalPackedPixel(4,extract8888rev
,shove8888rev
,
4268 width
, height
,usersImage
,
4269 newwidth
,newheight
,(void *)dstImage
,
4270 element_size
,rowsize
,myswap_bytes
);
4272 case GL_UNSIGNED_INT_10_10_10_2
:
4273 scaleInternalPackedPixel(4,extract1010102
,shove1010102
,
4274 width
, height
,usersImage
,
4275 newwidth
,newheight
,(void *)dstImage
,
4276 element_size
,rowsize
,myswap_bytes
);
4278 case GL_UNSIGNED_INT_2_10_10_10_REV
:
4279 scaleInternalPackedPixel(4,extract2101010rev
,shove2101010rev
,
4280 width
, height
,usersImage
,
4281 newwidth
,newheight
,(void *)dstImage
,
4282 element_size
,rowsize
,myswap_bytes
);
4289 rowsize
= newwidth
* group_size
;
4290 /* Swap dstImage and srcImage */
4291 __GLU_SWAP_IMAGE(srcImage
,dstImage
);
4293 if(levels
!= 0) { /* use as little memory as possible */
4295 int nextWidth
= newwidth
/2;
4296 int nextHeight
= newheight
/2;
4297 if (nextWidth
< 1) nextWidth
= 1;
4298 if (nextHeight
< 1) nextHeight
= 1;
4300 memreq
= image_size(nextWidth
, nextHeight
, format
, type
);
4304 case GL_UNSIGNED_BYTE
:
4305 dstImage
= (GLubyte
*)malloc(memreq
);
4308 dstImage
= (GLbyte
*)malloc(memreq
);
4310 case GL_UNSIGNED_SHORT
:
4311 dstImage
= (GLushort
*)malloc(memreq
);
4314 dstImage
= (GLshort
*)malloc(memreq
);
4316 case GL_UNSIGNED_INT
:
4317 dstImage
= (GLuint
*)malloc(memreq
);
4320 dstImage
= (GLint
*)malloc(memreq
);
4323 dstImage
= (GLfloat
*)malloc(memreq
);
4325 case GL_UNSIGNED_BYTE_3_3_2
:
4326 case GL_UNSIGNED_BYTE_2_3_3_REV
:
4327 dstImage
= (GLubyte
*)malloc(memreq
);
4329 case GL_UNSIGNED_SHORT_5_6_5
:
4330 case GL_UNSIGNED_SHORT_5_6_5_REV
:
4331 case GL_UNSIGNED_SHORT_4_4_4_4
:
4332 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
4333 case GL_UNSIGNED_SHORT_5_5_5_1
:
4334 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
4335 dstImage
= (GLushort
*)malloc(memreq
);
4337 case GL_UNSIGNED_INT_8_8_8_8
:
4338 case GL_UNSIGNED_INT_8_8_8_8_REV
:
4339 case GL_UNSIGNED_INT_10_10_10_2
:
4340 case GL_UNSIGNED_INT_2_10_10_10_REV
:
4341 dstImage
= (GLuint
*)malloc(memreq
);
4344 return GLU_INVALID_ENUM
;
4346 if (dstImage
== NULL
) {
4347 glPixelStorei(GL_UNPACK_ALIGNMENT
, psm
.unpack_alignment
);
4348 glPixelStorei(GL_UNPACK_SKIP_ROWS
, psm
.unpack_skip_rows
);
4349 glPixelStorei(GL_UNPACK_SKIP_PIXELS
, psm
.unpack_skip_pixels
);
4350 glPixelStorei(GL_UNPACK_ROW_LENGTH
, psm
.unpack_row_length
);
4351 glPixelStorei(GL_UNPACK_SWAP_BYTES
, psm
.unpack_swap_bytes
);
4352 return GLU_OUT_OF_MEMORY
;
4355 /* level userLevel is in srcImage; nothing saved yet */
4359 glPixelStorei(GL_UNPACK_SWAP_BYTES
, GL_FALSE
);
4360 if (baseLevel
<= level
&& level
<= maxLevel
) {
4361 glTexImage2D(target
, level
, internalFormat
, newwidth
, newheight
, 0,
4362 format
, type
, (void *)srcImage
);
4365 level
++; /* update current level for the loop */
4366 for (; level
<= levels
; level
++) {
4368 case GL_UNSIGNED_BYTE
:
4369 halveImage_ubyte(cmpts
, newwidth
, newheight
,
4370 (GLubyte
*)srcImage
, (GLubyte
*)dstImage
, element_size
,
4371 rowsize
, group_size
);
4374 halveImage_byte(cmpts
, newwidth
, newheight
,
4375 (GLbyte
*)srcImage
, (GLbyte
*)dstImage
, element_size
,
4376 rowsize
, group_size
);
4378 case GL_UNSIGNED_SHORT
:
4379 halveImage_ushort(cmpts
, newwidth
, newheight
,
4380 (GLushort
*)srcImage
, (GLushort
*)dstImage
, element_size
,
4381 rowsize
, group_size
, myswap_bytes
);
4384 halveImage_short(cmpts
, newwidth
, newheight
,
4385 (GLshort
*)srcImage
, (GLshort
*)dstImage
, element_size
,
4386 rowsize
, group_size
, myswap_bytes
);
4388 case GL_UNSIGNED_INT
:
4389 halveImage_uint(cmpts
, newwidth
, newheight
,
4390 (GLuint
*)srcImage
, (GLuint
*)dstImage
, element_size
,
4391 rowsize
, group_size
, myswap_bytes
);
4394 halveImage_int(cmpts
, newwidth
, newheight
,
4395 (GLint
*)srcImage
, (GLint
*)dstImage
, element_size
,
4396 rowsize
, group_size
, myswap_bytes
);
4399 halveImage_float(cmpts
, newwidth
, newheight
,
4400 (GLfloat
*)srcImage
, (GLfloat
*)dstImage
, element_size
,
4401 rowsize
, group_size
, myswap_bytes
);
4403 case GL_UNSIGNED_BYTE_3_3_2
:
4404 halveImagePackedPixel(3,extract332
,shove332
,
4406 srcImage
,dstImage
,element_size
,rowsize
,
4409 case GL_UNSIGNED_BYTE_2_3_3_REV
:
4410 halveImagePackedPixel(3,extract233rev
,shove233rev
,
4412 srcImage
,dstImage
,element_size
,rowsize
,
4415 case GL_UNSIGNED_SHORT_5_6_5
:
4416 halveImagePackedPixel(3,extract565
,shove565
,
4418 srcImage
,dstImage
,element_size
,rowsize
,
4421 case GL_UNSIGNED_SHORT_5_6_5_REV
:
4422 halveImagePackedPixel(3,extract565rev
,shove565rev
,
4424 srcImage
,dstImage
,element_size
,rowsize
,
4427 case GL_UNSIGNED_SHORT_4_4_4_4
:
4428 halveImagePackedPixel(4,extract4444
,shove4444
,
4430 srcImage
,dstImage
,element_size
,rowsize
,
4433 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
4434 halveImagePackedPixel(4,extract4444rev
,shove4444rev
,
4436 srcImage
,dstImage
,element_size
,rowsize
,
4439 case GL_UNSIGNED_SHORT_5_5_5_1
:
4440 halveImagePackedPixel(4,extract5551
,shove5551
,
4442 srcImage
,dstImage
,element_size
,rowsize
,
4445 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
4446 halveImagePackedPixel(4,extract1555rev
,shove1555rev
,
4448 srcImage
,dstImage
,element_size
,rowsize
,
4451 case GL_UNSIGNED_INT_8_8_8_8
:
4452 halveImagePackedPixel(4,extract8888
,shove8888
,
4454 srcImage
,dstImage
,element_size
,rowsize
,
4457 case GL_UNSIGNED_INT_8_8_8_8_REV
:
4458 halveImagePackedPixel(4,extract8888rev
,shove8888rev
,
4460 srcImage
,dstImage
,element_size
,rowsize
,
4463 case GL_UNSIGNED_INT_10_10_10_2
:
4464 halveImagePackedPixel(4,extract1010102
,shove1010102
,
4466 srcImage
,dstImage
,element_size
,rowsize
,
4469 case GL_UNSIGNED_INT_2_10_10_10_REV
:
4470 halveImagePackedPixel(4,extract2101010rev
,shove2101010rev
,
4472 srcImage
,dstImage
,element_size
,rowsize
,
4480 __GLU_SWAP_IMAGE(srcImage
,dstImage
);
4482 if (newwidth
> 1) { newwidth
/= 2; rowsize
/= 2;}
4483 if (newheight
> 1) newheight
/= 2;
4485 /* compute amount to pad per row, if any */
4486 int rowPad
= rowsize
% psm
.unpack_alignment
;
4488 /* should row be padded? */
4489 if (rowPad
== 0) { /* nope, row should not be padded */
4490 /* call tex image with srcImage untouched since it's not padded */
4491 if (baseLevel
<= level
&& level
<= maxLevel
) {
4492 glTexImage2D(target
, level
, internalFormat
, newwidth
, newheight
, 0,
4493 format
, type
, (void *) srcImage
);
4496 else { /* yes, row should be padded */
4497 /* compute length of new row in bytes, including padding */
4498 int newRowLength
= rowsize
+ psm
.unpack_alignment
- rowPad
;
4499 int ii
; unsigned char *dstTrav
, *srcTrav
; /* indices for copying */
4501 /* allocate new image for mipmap of size newRowLength x newheight */
4502 void *newMipmapImage
= malloc((size_t) (newRowLength
*newheight
));
4503 if (newMipmapImage
== NULL
) {
4504 /* out of memory so return */
4505 glPixelStorei(GL_UNPACK_ALIGNMENT
, psm
.unpack_alignment
);
4506 glPixelStorei(GL_UNPACK_SKIP_ROWS
, psm
.unpack_skip_rows
);
4507 glPixelStorei(GL_UNPACK_SKIP_PIXELS
, psm
.unpack_skip_pixels
);
4508 glPixelStorei(GL_UNPACK_ROW_LENGTH
, psm
.unpack_row_length
);
4509 glPixelStorei(GL_UNPACK_SWAP_BYTES
, psm
.unpack_swap_bytes
);
4510 return GLU_OUT_OF_MEMORY
;
4513 /* copy image from srcImage into newMipmapImage by rows */
4515 dstTrav
= (unsigned char *) newMipmapImage
,
4516 srcTrav
= (unsigned char *) srcImage
;
4519 dstTrav
+= newRowLength
, /* make sure the correct distance... */
4520 srcTrav
+= rowsize
) { /* ...is skipped */
4521 memcpy(dstTrav
,srcTrav
,rowsize
);
4522 /* note that the pad bytes are not visited and will contain
4523 * garbage, which is ok.
4527 /* ...and use this new image for mipmapping instead */
4528 if (baseLevel
<= level
&& level
<= maxLevel
) {
4529 glTexImage2D(target
, level
, internalFormat
, newwidth
, newheight
, 0,
4530 format
, type
, newMipmapImage
);
4532 free(newMipmapImage
); /* don't forget to free it! */
4536 glPixelStorei(GL_UNPACK_ALIGNMENT
, psm
.unpack_alignment
);
4537 glPixelStorei(GL_UNPACK_SKIP_ROWS
, psm
.unpack_skip_rows
);
4538 glPixelStorei(GL_UNPACK_SKIP_PIXELS
, psm
.unpack_skip_pixels
);
4539 glPixelStorei(GL_UNPACK_ROW_LENGTH
, psm
.unpack_row_length
);
4540 glPixelStorei(GL_UNPACK_SWAP_BYTES
, psm
.unpack_swap_bytes
);
4542 free(srcImage
); /*if you get to here, a srcImage has always been malloc'ed*/
4543 if (dstImage
) { /* if it's non-rectangular and only 1 level */
4547 } /* gluBuild2DMipmapLevelsCore() */
4550 gluBuild2DMipmapLevels(GLenum target
, GLint internalFormat
,
4551 GLsizei width
, GLsizei height
,
4552 GLenum format
, GLenum type
,
4553 GLint userLevel
, GLint baseLevel
, GLint maxLevel
,
4558 int rc
= checkMipmapArgs(internalFormat
,format
,type
);
4559 if (rc
!= 0) return rc
;
4561 if (width
< 1 || height
< 1) {
4562 return GLU_INVALID_VALUE
;
4565 levels
= computeLog(width
);
4566 level
= computeLog(height
);
4567 if (level
> levels
) levels
=level
;
4570 if (!isLegalLevels(userLevel
,baseLevel
,maxLevel
,levels
))
4571 return GLU_INVALID_VALUE
;
4573 return gluBuild2DMipmapLevelsCore(target
, internalFormat
,
4577 userLevel
, baseLevel
, maxLevel
,
4579 } /* gluBuild2DMipmapLevels() */
4582 gluBuild2DMipmaps(GLenum target
, GLint internalFormat
,
4583 GLsizei width
, GLsizei height
,
4584 GLenum format
, GLenum type
,
4587 GLint widthPowerOf2
, heightPowerOf2
;
4590 int rc
= checkMipmapArgs(internalFormat
,format
,type
);
4591 if (rc
!= 0) return rc
;
4593 if (width
< 1 || height
< 1) {
4594 return GLU_INVALID_VALUE
;
4597 closestFit(target
,width
,height
,internalFormat
,format
,type
,
4598 &widthPowerOf2
,&heightPowerOf2
);
4600 levels
= computeLog(widthPowerOf2
);
4601 level
= computeLog(heightPowerOf2
);
4602 if (level
> levels
) levels
=level
;
4604 return gluBuild2DMipmapLevelsCore(target
,internalFormat
,
4606 widthPowerOf2
,heightPowerOf2
,
4609 } /* gluBuild2DMipmaps() */
4613 ** This routine is for the limited case in which
4614 ** type == GL_UNSIGNED_BYTE && format != index &&
4615 ** unpack_alignment = 1 && unpack_swap_bytes == false
4617 ** so all of the work data can be kept as ubytes instead of shorts.
4619 static int fastBuild2DMipmaps(const PixelStorageModes
*psm
,
4620 GLenum target
, GLint components
, GLint width
,
4621 GLint height
, GLenum format
,
4622 GLenum type
, void *data
)
4624 GLint newwidth
, newheight
;
4625 GLint level
, levels
;
4627 GLint newImage_width
;
4628 GLint newImage_height
;
4629 GLubyte
*otherImage
;
4636 glGetIntegerv(GL_MAX_TEXTURE_SIZE
, &maxsize
);
4637 newwidth
= nearestPower(width
);
4638 if (newwidth
> maxsize
) newwidth
= maxsize
;
4639 newheight
= nearestPower(height
);
4640 if (newheight
> maxsize
) newheight
= maxsize
;
4642 closestFit(target
,width
,height
,components
,format
,type
,
4643 &newwidth
,&newheight
);
4645 levels
= computeLog(newwidth
);
4646 level
= computeLog(newheight
);
4647 if (level
> levels
) levels
=level
;
4649 cmpts
= elements_per_group(format
,type
);
4653 ** No need to copy the user data if its in the packed correctly.
4654 ** Make sure that later routines don't change that data.
4656 if (psm
->unpack_skip_rows
== 0 && psm
->unpack_skip_pixels
== 0) {
4657 newImage
= (GLubyte
*)data
;
4658 newImage_width
= width
;
4659 newImage_height
= height
;
4662 GLint groups_per_line
;
4663 GLint elements_per_line
;
4664 const GLubyte
*start
;
4665 const GLubyte
*iter
;
4669 newImage
= (GLubyte
*)
4670 malloc(image_size(width
, height
, format
, GL_UNSIGNED_BYTE
));
4671 newImage_width
= width
;
4672 newImage_height
= height
;
4673 if (newImage
== NULL
) {
4674 return GLU_OUT_OF_MEMORY
;
4678 ** Abbreviated version of fill_image for this restricted case.
4680 if (psm
->unpack_row_length
> 0) {
4681 groups_per_line
= psm
->unpack_row_length
;
4683 groups_per_line
= width
;
4685 rowsize
= groups_per_line
* cmpts
;
4686 elements_per_line
= width
* cmpts
;
4687 start
= (const GLubyte
*) data
+ psm
->unpack_skip_rows
* rowsize
+
4688 psm
->unpack_skip_pixels
* cmpts
;
4691 for (i
= 0; i
< height
; i
++) {
4693 for (j
= 0; j
< elements_per_line
; j
++) {
4703 glPixelStorei(GL_UNPACK_ALIGNMENT
, 1);
4704 glPixelStorei(GL_UNPACK_SKIP_ROWS
, 0);
4705 glPixelStorei(GL_UNPACK_SKIP_PIXELS
, 0);
4706 glPixelStorei(GL_UNPACK_ROW_LENGTH
, 0);
4707 glPixelStorei(GL_UNPACK_SWAP_BYTES
, GL_FALSE
);
4709 for (level
= 0; level
<= levels
; level
++) {
4710 if (newImage_width
== newwidth
&& newImage_height
== newheight
) {
4711 /* Use newImage for this level */
4712 glTexImage2D(target
, level
, components
, newImage_width
,
4713 newImage_height
, 0, format
, GL_UNSIGNED_BYTE
,
4716 if (otherImage
== NULL
) {
4718 image_size(newwidth
, newheight
, format
, GL_UNSIGNED_BYTE
);
4719 otherImage
= (GLubyte
*) malloc(memreq
);
4720 if (otherImage
== NULL
) {
4721 glPixelStorei(GL_UNPACK_ALIGNMENT
, psm
->unpack_alignment
);
4722 glPixelStorei(GL_UNPACK_SKIP_ROWS
, psm
->unpack_skip_rows
);
4723 glPixelStorei(GL_UNPACK_SKIP_PIXELS
, psm
->unpack_skip_pixels
);
4724 glPixelStorei(GL_UNPACK_ROW_LENGTH
,psm
->unpack_row_length
);
4725 glPixelStorei(GL_UNPACK_SWAP_BYTES
,psm
->unpack_swap_bytes
);
4726 return GLU_OUT_OF_MEMORY
;
4730 scale_internal_ubyte(cmpts, newImage_width, newImage_height,
4731 newImage, newwidth, newheight, otherImage);
4733 /* Swap newImage and otherImage */
4734 imageTemp
= otherImage
;
4735 otherImage
= newImage
;
4736 newImage
= imageTemp
;
4738 newImage_width
= newwidth
;
4739 newImage_height
= newheight
;
4740 glTexImage2D(target
, level
, components
, newImage_width
,
4741 newImage_height
, 0, format
, GL_UNSIGNED_BYTE
,
4744 if (newwidth
> 1) newwidth
/= 2;
4745 if (newheight
> 1) newheight
/= 2;
4747 glPixelStorei(GL_UNPACK_ALIGNMENT
, psm
->unpack_alignment
);
4748 glPixelStorei(GL_UNPACK_SKIP_ROWS
, psm
->unpack_skip_rows
);
4749 glPixelStorei(GL_UNPACK_SKIP_PIXELS
, psm
->unpack_skip_pixels
);
4750 glPixelStorei(GL_UNPACK_ROW_LENGTH
, psm
->unpack_row_length
);
4751 glPixelStorei(GL_UNPACK_SWAP_BYTES
, psm
->unpack_swap_bytes
);
4753 if (newImage
!= (const GLubyte
*)data
) {
4754 free((GLbyte
*) newImage
);
4756 if (otherImage
&& otherImage
!= (const GLubyte
*)data
) {
4757 free((GLbyte
*) otherImage
);
4766 static GLint
elements_per_group(GLenum format
, GLenum type
)
4769 * Return the number of elements per group of a specified format
4772 /* If the type is packedpixels then answer is 1 (ignore format) */
4773 if (type
== GL_UNSIGNED_BYTE_3_3_2
||
4774 type
== GL_UNSIGNED_BYTE_2_3_3_REV
||
4775 type
== GL_UNSIGNED_SHORT_5_6_5
||
4776 type
== GL_UNSIGNED_SHORT_5_6_5_REV
||
4777 type
== GL_UNSIGNED_SHORT_4_4_4_4
||
4778 type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
||
4779 type
== GL_UNSIGNED_SHORT_5_5_5_1
||
4780 type
== GL_UNSIGNED_SHORT_1_5_5_5_REV
||
4781 type
== GL_UNSIGNED_INT_8_8_8_8
||
4782 type
== GL_UNSIGNED_INT_8_8_8_8_REV
||
4783 type
== GL_UNSIGNED_INT_10_10_10_2
||
4784 type
== GL_UNSIGNED_INT_2_10_10_10_REV
) {
4788 /* Types are not packed pixels, so get elements per group */
4793 case GL_LUMINANCE_ALPHA
:
4803 static GLfloat
bytes_per_element(GLenum type
)
4806 * Return the number of bytes per element, based on the element type
4811 case GL_UNSIGNED_SHORT
:
4812 return(sizeof(GLushort
));
4814 return(sizeof(GLshort
));
4815 case GL_UNSIGNED_BYTE
:
4816 return(sizeof(GLubyte
));
4818 return(sizeof(GLbyte
));
4820 return(sizeof(GLint
));
4821 case GL_UNSIGNED_INT
:
4822 return(sizeof(GLuint
));
4824 return(sizeof(GLfloat
));
4825 case GL_UNSIGNED_BYTE_3_3_2
:
4826 case GL_UNSIGNED_BYTE_2_3_3_REV
:
4827 return(sizeof(GLubyte
));
4828 case GL_UNSIGNED_SHORT_5_6_5
:
4829 case GL_UNSIGNED_SHORT_5_6_5_REV
:
4830 case GL_UNSIGNED_SHORT_4_4_4_4
:
4831 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
4832 case GL_UNSIGNED_SHORT_5_5_5_1
:
4833 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
4834 return(sizeof(GLushort
));
4835 case GL_UNSIGNED_INT_8_8_8_8
:
4836 case GL_UNSIGNED_INT_8_8_8_8_REV
:
4837 case GL_UNSIGNED_INT_10_10_10_2
:
4838 case GL_UNSIGNED_INT_2_10_10_10_REV
:
4839 return(sizeof(GLuint
));
4845 static GLint
is_index(GLenum format
)
4847 return format
== GL_COLOR_INDEX
|| format
== GL_STENCIL_INDEX
;
4851 ** Compute memory required for internal packed array of data of given type
4854 static GLint
image_size(GLint width
, GLint height
, GLenum format
, GLenum type
)
4861 components
= elements_per_group(format
,type
);
4862 if (type
== GL_BITMAP
) {
4863 bytes_per_row
= (width
+ 7) / 8;
4865 bytes_per_row
= bytes_per_element(type
) * width
;
4867 return bytes_per_row
* height
* components
;
4871 ** Extract array from user's data applying all pixel store modes.
4872 ** The internal format used is an array of unsigned shorts.
4874 static void fill_image(const PixelStorageModes
*psm
,
4875 GLint width
, GLint height
, GLenum format
,
4876 GLenum type
, GLboolean index_format
,
4877 const void *userdata
, GLushort
*newimage
)
4883 GLint groups_per_line
;
4885 GLint elements_per_line
;
4886 const GLubyte
*start
;
4887 const GLubyte
*iter
;
4892 myswap_bytes
= psm
->unpack_swap_bytes
;
4893 components
= elements_per_group(format
,type
);
4894 if (psm
->unpack_row_length
> 0) {
4895 groups_per_line
= psm
->unpack_row_length
;
4897 groups_per_line
= width
;
4900 /* All formats except GL_BITMAP fall out trivially */
4901 if (type
== GL_BITMAP
) {
4905 rowsize
= (groups_per_line
* components
+ 7) / 8;
4906 padding
= (rowsize
% psm
->unpack_alignment
);
4908 rowsize
+= psm
->unpack_alignment
- padding
;
4910 start
= (const GLubyte
*) userdata
+ psm
->unpack_skip_rows
* rowsize
+
4911 (psm
->unpack_skip_pixels
* components
/ 8);
4912 elements_per_line
= width
* components
;
4914 for (i
= 0; i
< height
; i
++) {
4916 bit_offset
= (psm
->unpack_skip_pixels
* components
) % 8;
4917 for (j
= 0; j
< elements_per_line
; j
++) {
4919 if (psm
->unpack_lsb_first
) {
4920 current_bit
= iter
[0] & (1 << bit_offset
);
4922 current_bit
= iter
[0] & (1 << (7 - bit_offset
));
4934 if (bit_offset
== 8) {
4943 element_size
= bytes_per_element(type
);
4944 group_size
= element_size
* components
;
4945 if (element_size
== 1) myswap_bytes
= 0;
4947 rowsize
= groups_per_line
* group_size
;
4948 padding
= (rowsize
% psm
->unpack_alignment
);
4950 rowsize
+= psm
->unpack_alignment
- padding
;
4952 start
= (const GLubyte
*) userdata
+ psm
->unpack_skip_rows
* rowsize
+
4953 psm
->unpack_skip_pixels
* group_size
;
4954 elements_per_line
= width
* components
;
4957 for (i
= 0; i
< height
; i
++) {
4959 for (j
= 0; j
< elements_per_line
; j
++) {
4961 float extractComponents
[4];
4964 case GL_UNSIGNED_BYTE_3_3_2
:
4965 extract332(0,iter
,extractComponents
);
4966 for (k
= 0; k
< 3; k
++) {
4967 *iter2
++ = (GLushort
)(extractComponents
[k
]*65535);
4970 case GL_UNSIGNED_BYTE_2_3_3_REV
:
4971 extract233rev(0,iter
,extractComponents
);
4972 for (k
= 0; k
< 3; k
++) {
4973 *iter2
++ = (GLushort
)(extractComponents
[k
]*65535);
4976 case GL_UNSIGNED_BYTE
:
4980 *iter2
++ = (*iter
) * 257;
4985 *iter2
++ = *((const GLbyte
*) iter
);
4988 *iter2
++ = (*((const GLbyte
*) iter
)) * 516;
4991 case GL_UNSIGNED_SHORT_5_6_5
:
4992 extract565(myswap_bytes
,iter
,extractComponents
);
4993 for (k
= 0; k
< 3; k
++) {
4994 *iter2
++ = (GLushort
)(extractComponents
[k
]*65535);
4997 case GL_UNSIGNED_SHORT_5_6_5_REV
:
4998 extract565rev(myswap_bytes
,iter
,extractComponents
);
4999 for (k
= 0; k
< 3; k
++) {
5000 *iter2
++ = (GLushort
)(extractComponents
[k
]*65535);
5003 case GL_UNSIGNED_SHORT_4_4_4_4
:
5004 extract4444(myswap_bytes
,iter
,extractComponents
);
5005 for (k
= 0; k
< 4; k
++) {
5006 *iter2
++ = (GLushort
)(extractComponents
[k
]*65535);
5009 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
5010 extract4444rev(myswap_bytes
,iter
,extractComponents
);
5011 for (k
= 0; k
< 4; k
++) {
5012 *iter2
++ = (GLushort
)(extractComponents
[k
]*65535);
5015 case GL_UNSIGNED_SHORT_5_5_5_1
:
5016 extract5551(myswap_bytes
,iter
,extractComponents
);
5017 for (k
= 0; k
< 4; k
++) {
5018 *iter2
++ = (GLushort
)(extractComponents
[k
]*65535);
5021 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
5022 extract1555rev(myswap_bytes
,iter
,extractComponents
);
5023 for (k
= 0; k
< 4; k
++) {
5024 *iter2
++ = (GLushort
)(extractComponents
[k
]*65535);
5027 case GL_UNSIGNED_SHORT
:
5030 widget
.ub
[0] = iter
[1];
5031 widget
.ub
[1] = iter
[0];
5033 widget
.ub
[0] = iter
[0];
5034 widget
.ub
[1] = iter
[1];
5036 if (type
== GL_SHORT
) {
5038 *iter2
++ = widget
.s
[0];
5041 *iter2
++ = widget
.s
[0]*2;
5044 *iter2
++ = widget
.us
[0];
5047 case GL_UNSIGNED_INT_8_8_8_8
:
5048 extract8888(myswap_bytes
,iter
,extractComponents
);
5049 for (k
= 0; k
< 4; k
++) {
5050 *iter2
++ = (GLushort
)(extractComponents
[k
]*65535);
5053 case GL_UNSIGNED_INT_8_8_8_8_REV
:
5054 extract8888rev(myswap_bytes
,iter
,extractComponents
);
5055 for (k
= 0; k
< 4; k
++) {
5056 *iter2
++ = (GLushort
)(extractComponents
[k
]*65535);
5059 case GL_UNSIGNED_INT_10_10_10_2
:
5060 extract1010102(myswap_bytes
,iter
,extractComponents
);
5061 for (k
= 0; k
< 4; k
++) {
5062 *iter2
++ = (GLushort
)(extractComponents
[k
]*65535);
5065 case GL_UNSIGNED_INT_2_10_10_10_REV
:
5066 extract2101010rev(myswap_bytes
,iter
,extractComponents
);
5067 for (k
= 0; k
< 4; k
++) {
5068 *iter2
++ = (GLushort
)(extractComponents
[k
]*65535);
5072 case GL_UNSIGNED_INT
:
5075 widget
.ub
[0] = iter
[3];
5076 widget
.ub
[1] = iter
[2];
5077 widget
.ub
[2] = iter
[1];
5078 widget
.ub
[3] = iter
[0];
5080 widget
.ub
[0] = iter
[0];
5081 widget
.ub
[1] = iter
[1];
5082 widget
.ub
[2] = iter
[2];
5083 widget
.ub
[3] = iter
[3];
5085 if (type
== GL_FLOAT
) {
5087 *iter2
++ = widget
.f
;
5089 *iter2
++ = 65535 * widget
.f
;
5091 } else if (type
== GL_UNSIGNED_INT
) {
5093 *iter2
++ = widget
.ui
;
5095 *iter2
++ = widget
.ui
>> 16;
5099 *iter2
++ = widget
.i
;
5101 *iter2
++ = widget
.i
>> 15;
5106 iter
+= element_size
;
5110 /* want 'iter' pointing at start, not within, row for assertion
5117 /* iterators should be one byte past end */
5118 if (!isTypePackedPixel(type
)) {
5119 assert(iter2
== &newimage
[width
*height
*components
]);
5122 assert(iter2
== &newimage
[width
*height
*
5123 elements_per_group(format
,0)]);
5125 assert( iter
== &((const GLubyte
*)userdata
)[rowsize
*height
+
5126 psm
->unpack_skip_rows
* rowsize
+
5127 psm
->unpack_skip_pixels
* group_size
] );
5130 } /* fill_image() */
5133 ** Insert array into user's data applying all pixel store modes.
5134 ** The internal format is an array of unsigned shorts.
5135 ** empty_image() because it is the opposite of fill_image().
5137 static void empty_image(const PixelStorageModes
*psm
,
5138 GLint width
, GLint height
, GLenum format
,
5139 GLenum type
, GLboolean index_format
,
5140 const GLushort
*oldimage
, void *userdata
)
5146 GLint groups_per_line
;
5148 GLint elements_per_line
;
5151 const GLushort
*iter2
;
5155 myswap_bytes
= psm
->pack_swap_bytes
;
5156 components
= elements_per_group(format
,type
);
5157 if (psm
->pack_row_length
> 0) {
5158 groups_per_line
= psm
->pack_row_length
;
5160 groups_per_line
= width
;
5163 /* All formats except GL_BITMAP fall out trivially */
5164 if (type
== GL_BITMAP
) {
5168 rowsize
= (groups_per_line
* components
+ 7) / 8;
5169 padding
= (rowsize
% psm
->pack_alignment
);
5171 rowsize
+= psm
->pack_alignment
- padding
;
5173 start
= (GLubyte
*) userdata
+ psm
->pack_skip_rows
* rowsize
+
5174 (psm
->pack_skip_pixels
* components
/ 8);
5175 elements_per_line
= width
* components
;
5177 for (i
= 0; i
< height
; i
++) {
5179 bit_offset
= (psm
->pack_skip_pixels
* components
) % 8;
5180 for (j
= 0; j
< elements_per_line
; j
++) {
5182 current_bit
= iter2
[0] & 1;
5184 if (iter2
[0] > 32767) {
5192 if (psm
->pack_lsb_first
) {
5193 *iter
|= (1 << bit_offset
);
5195 *iter
|= (1 << (7 - bit_offset
));
5198 if (psm
->pack_lsb_first
) {
5199 *iter
&= ~(1 << bit_offset
);
5201 *iter
&= ~(1 << (7 - bit_offset
));
5206 if (bit_offset
== 8) {
5215 float shoveComponents
[4];
5217 element_size
= bytes_per_element(type
);
5218 group_size
= element_size
* components
;
5219 if (element_size
== 1) myswap_bytes
= 0;
5221 rowsize
= groups_per_line
* group_size
;
5222 padding
= (rowsize
% psm
->pack_alignment
);
5224 rowsize
+= psm
->pack_alignment
- padding
;
5226 start
= (GLubyte
*) userdata
+ psm
->pack_skip_rows
* rowsize
+
5227 psm
->pack_skip_pixels
* group_size
;
5228 elements_per_line
= width
* components
;
5231 for (i
= 0; i
< height
; i
++) {
5233 for (j
= 0; j
< elements_per_line
; j
++) {
5237 case GL_UNSIGNED_BYTE_3_3_2
:
5238 for (k
= 0; k
< 3; k
++) {
5239 shoveComponents
[k
]= *iter2
++ / 65535.0;
5241 shove332(shoveComponents
,0,(void *)iter
);
5243 case GL_UNSIGNED_BYTE_2_3_3_REV
:
5244 for (k
= 0; k
< 3; k
++) {
5245 shoveComponents
[k
]= *iter2
++ / 65535.0;
5247 shove233rev(shoveComponents
,0,(void *)iter
);
5249 case GL_UNSIGNED_BYTE
:
5253 *iter
= *iter2
++ >> 8;
5258 *((GLbyte
*) iter
) = *iter2
++;
5260 *((GLbyte
*) iter
) = *iter2
++ >> 9;
5263 case GL_UNSIGNED_SHORT_5_6_5
:
5264 for (k
= 0; k
< 3; k
++) {
5265 shoveComponents
[k
]= *iter2
++ / 65535.0;
5267 shove565(shoveComponents
,0,(void *)&widget
.us
[0]);
5269 iter
[0] = widget
.ub
[1];
5270 iter
[1] = widget
.ub
[0];
5273 *(GLushort
*)iter
= widget
.us
[0];
5276 case GL_UNSIGNED_SHORT_5_6_5_REV
:
5277 for (k
= 0; k
< 3; k
++) {
5278 shoveComponents
[k
]= *iter2
++ / 65535.0;
5280 shove565rev(shoveComponents
,0,(void *)&widget
.us
[0]);
5282 iter
[0] = widget
.ub
[1];
5283 iter
[1] = widget
.ub
[0];
5286 *(GLushort
*)iter
= widget
.us
[0];
5289 case GL_UNSIGNED_SHORT_4_4_4_4
:
5290 for (k
= 0; k
< 4; k
++) {
5291 shoveComponents
[k
]= *iter2
++ / 65535.0;
5293 shove4444(shoveComponents
,0,(void *)&widget
.us
[0]);
5295 iter
[0] = widget
.ub
[1];
5296 iter
[1] = widget
.ub
[0];
5298 *(GLushort
*)iter
= widget
.us
[0];
5301 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
5302 for (k
= 0; k
< 4; k
++) {
5303 shoveComponents
[k
]= *iter2
++ / 65535.0;
5305 shove4444rev(shoveComponents
,0,(void *)&widget
.us
[0]);
5307 iter
[0] = widget
.ub
[1];
5308 iter
[1] = widget
.ub
[0];
5310 *(GLushort
*)iter
= widget
.us
[0];
5313 case GL_UNSIGNED_SHORT_5_5_5_1
:
5314 for (k
= 0; k
< 4; k
++) {
5315 shoveComponents
[k
]= *iter2
++ / 65535.0;
5317 shove5551(shoveComponents
,0,(void *)&widget
.us
[0]);
5319 iter
[0] = widget
.ub
[1];
5320 iter
[1] = widget
.ub
[0];
5322 *(GLushort
*)iter
= widget
.us
[0];
5325 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
5326 for (k
= 0; k
< 4; k
++) {
5327 shoveComponents
[k
]= *iter2
++ / 65535.0;
5329 shove1555rev(shoveComponents
,0,(void *)&widget
.us
[0]);
5331 iter
[0] = widget
.ub
[1];
5332 iter
[1] = widget
.ub
[0];
5334 *(GLushort
*)iter
= widget
.us
[0];
5337 case GL_UNSIGNED_SHORT
:
5339 if (type
== GL_SHORT
) {
5341 widget
.s
[0] = *iter2
++;
5343 widget
.s
[0] = *iter2
++ >> 1;
5346 widget
.us
[0] = *iter2
++;
5349 iter
[0] = widget
.ub
[1];
5350 iter
[1] = widget
.ub
[0];
5352 iter
[0] = widget
.ub
[0];
5353 iter
[1] = widget
.ub
[1];
5356 case GL_UNSIGNED_INT_8_8_8_8
:
5357 for (k
= 0; k
< 4; k
++) {
5358 shoveComponents
[k
]= *iter2
++ / 65535.0;
5360 shove8888(shoveComponents
,0,(void *)&widget
.ui
);
5362 iter
[3] = widget
.ub
[0];
5363 iter
[2] = widget
.ub
[1];
5364 iter
[1] = widget
.ub
[2];
5365 iter
[0] = widget
.ub
[3];
5367 *(GLuint
*)iter
= widget
.ui
;
5371 case GL_UNSIGNED_INT_8_8_8_8_REV
:
5372 for (k
= 0; k
< 4; k
++) {
5373 shoveComponents
[k
]= *iter2
++ / 65535.0;
5375 shove8888rev(shoveComponents
,0,(void *)&widget
.ui
);
5377 iter
[3] = widget
.ub
[0];
5378 iter
[2] = widget
.ub
[1];
5379 iter
[1] = widget
.ub
[2];
5380 iter
[0] = widget
.ub
[3];
5382 *(GLuint
*)iter
= widget
.ui
;
5385 case GL_UNSIGNED_INT_10_10_10_2
:
5386 for (k
= 0; k
< 4; k
++) {
5387 shoveComponents
[k
]= *iter2
++ / 65535.0;
5389 shove1010102(shoveComponents
,0,(void *)&widget
.ui
);
5391 iter
[3] = widget
.ub
[0];
5392 iter
[2] = widget
.ub
[1];
5393 iter
[1] = widget
.ub
[2];
5394 iter
[0] = widget
.ub
[3];
5396 *(GLuint
*)iter
= widget
.ui
;
5399 case GL_UNSIGNED_INT_2_10_10_10_REV
:
5400 for (k
= 0; k
< 4; k
++) {
5401 shoveComponents
[k
]= *iter2
++ / 65535.0;
5403 shove2101010rev(shoveComponents
,0,(void *)&widget
.ui
);
5405 iter
[3] = widget
.ub
[0];
5406 iter
[2] = widget
.ub
[1];
5407 iter
[1] = widget
.ub
[2];
5408 iter
[0] = widget
.ub
[3];
5410 *(GLuint
*)iter
= widget
.ui
;
5414 case GL_UNSIGNED_INT
:
5416 if (type
== GL_FLOAT
) {
5418 widget
.f
= *iter2
++;
5420 widget
.f
= *iter2
++ / (float) 65535.0;
5422 } else if (type
== GL_UNSIGNED_INT
) {
5424 widget
.ui
= *iter2
++;
5426 widget
.ui
= (unsigned int) *iter2
++ * 65537;
5430 widget
.i
= *iter2
++;
5432 widget
.i
= ((unsigned int) *iter2
++ * 65537)/2;
5436 iter
[3] = widget
.ub
[0];
5437 iter
[2] = widget
.ub
[1];
5438 iter
[1] = widget
.ub
[2];
5439 iter
[0] = widget
.ub
[3];
5441 iter
[0] = widget
.ub
[0];
5442 iter
[1] = widget
.ub
[1];
5443 iter
[2] = widget
.ub
[2];
5444 iter
[3] = widget
.ub
[3];
5448 iter
+= element_size
;
5452 /* want 'iter' pointing at start, not within, row for assertion
5459 /* iterators should be one byte past end */
5460 if (!isTypePackedPixel(type
)) {
5461 assert(iter2
== &oldimage
[width
*height
*components
]);
5464 assert(iter2
== &oldimage
[width
*height
*
5465 elements_per_group(format
,0)]);
5467 assert( iter
== &((GLubyte
*)userdata
)[rowsize
*height
+
5468 psm
->pack_skip_rows
* rowsize
+
5469 psm
->pack_skip_pixels
* group_size
] );
5472 } /* empty_image() */
5474 /*--------------------------------------------------------------------------
5475 * Decimation of packed pixel types
5476 *--------------------------------------------------------------------------
5478 static void extract332(int isSwap
,
5479 const void *packedPixel
, GLfloat extractComponents
[])
5481 GLubyte ubyte
= *(const GLubyte
*)packedPixel
;
5483 isSwap
= isSwap
; /* turn off warnings */
5485 /* 11100000 == 0xe0 */
5486 /* 00011100 == 0x1c */
5487 /* 00000011 == 0x03 */
5489 extractComponents
[0]= (float)((ubyte
& 0xe0) >> 5) / 7.0;
5490 extractComponents
[1]= (float)((ubyte
& 0x1c) >> 2) / 7.0; /* 7 = 2^3-1 */
5491 extractComponents
[2]= (float)((ubyte
& 0x03) ) / 3.0; /* 3 = 2^2-1 */
5492 } /* extract332() */
5494 static void shove332(const GLfloat shoveComponents
[],
5495 int index
, void *packedPixel
)
5497 /* 11100000 == 0xe0 */
5498 /* 00011100 == 0x1c */
5499 /* 00000011 == 0x03 */
5501 assert(0.0 <= shoveComponents
[0] && shoveComponents
[0] <= 1.0);
5502 assert(0.0 <= shoveComponents
[1] && shoveComponents
[1] <= 1.0);
5503 assert(0.0 <= shoveComponents
[2] && shoveComponents
[2] <= 1.0);
5505 /* due to limited precision, need to round before shoving */
5506 ((GLubyte
*)packedPixel
)[index
] =
5507 ((GLubyte
)((shoveComponents
[0] * 7)+0.5) << 5) & 0xe0;
5508 ((GLubyte
*)packedPixel
)[index
] |=
5509 ((GLubyte
)((shoveComponents
[1] * 7)+0.5) << 2) & 0x1c;
5510 ((GLubyte
*)packedPixel
)[index
] |=
5511 ((GLubyte
)((shoveComponents
[2] * 3)+0.5) ) & 0x03;
5514 static void extract233rev(int isSwap
,
5515 const void *packedPixel
, GLfloat extractComponents
[])
5517 GLubyte ubyte
= *(const GLubyte
*)packedPixel
;
5519 isSwap
= isSwap
; /* turn off warnings */
5521 /* 0000,0111 == 0x07 */
5522 /* 0011,1000 == 0x38 */
5523 /* 1100,0000 == 0xC0 */
5525 extractComponents
[0]= (float)((ubyte
& 0x07) ) / 7.0;
5526 extractComponents
[1]= (float)((ubyte
& 0x38) >> 3) / 7.0;
5527 extractComponents
[2]= (float)((ubyte
& 0xC0) >> 6) / 3.0;
5528 } /* extract233rev() */
5530 static void shove233rev(const GLfloat shoveComponents
[],
5531 int index
, void *packedPixel
)
5533 /* 0000,0111 == 0x07 */
5534 /* 0011,1000 == 0x38 */
5535 /* 1100,0000 == 0xC0 */
5537 assert(0.0 <= shoveComponents
[0] && shoveComponents
[0] <= 1.0);
5538 assert(0.0 <= shoveComponents
[1] && shoveComponents
[1] <= 1.0);
5539 assert(0.0 <= shoveComponents
[2] && shoveComponents
[2] <= 1.0);
5541 /* due to limited precision, need to round before shoving */
5542 ((GLubyte
*)packedPixel
)[index
] =
5543 ((GLubyte
)((shoveComponents
[0] * 7.0)+0.5) ) & 0x07;
5544 ((GLubyte
*)packedPixel
)[index
]|=
5545 ((GLubyte
)((shoveComponents
[1] * 7.0)+0.5) << 3) & 0x38;
5546 ((GLubyte
*)packedPixel
)[index
]|=
5547 ((GLubyte
)((shoveComponents
[2] * 3.0)+0.5) << 6) & 0xC0;
5548 } /* shove233rev() */
5550 static void extract565(int isSwap
,
5551 const void *packedPixel
, GLfloat extractComponents
[])
5553 GLushort ushort
= *(const GLushort
*)packedPixel
;
5556 ushort
= __GLU_SWAP_2_BYTES(packedPixel
);
5559 ushort
= *(const GLushort
*)packedPixel
;
5562 /* 11111000,00000000 == 0xf800 */
5563 /* 00000111,11100000 == 0x07e0 */
5564 /* 00000000,00011111 == 0x001f */
5566 extractComponents
[0]=(float)((ushort
& 0xf800) >> 11) / 31.0;/* 31 = 2^5-1*/
5567 extractComponents
[1]=(float)((ushort
& 0x07e0) >> 5) / 63.0;/* 63 = 2^6-1*/
5568 extractComponents
[2]=(float)((ushort
& 0x001f) ) / 31.0;
5569 } /* extract565() */
5571 static void shove565(const GLfloat shoveComponents
[],
5572 int index
,void *packedPixel
)
5574 /* 11111000,00000000 == 0xf800 */
5575 /* 00000111,11100000 == 0x07e0 */
5576 /* 00000000,00011111 == 0x001f */
5578 assert(0.0 <= shoveComponents
[0] && shoveComponents
[0] <= 1.0);
5579 assert(0.0 <= shoveComponents
[1] && shoveComponents
[1] <= 1.0);
5580 assert(0.0 <= shoveComponents
[2] && shoveComponents
[2] <= 1.0);
5582 /* due to limited precision, need to round before shoving */
5583 ((GLushort
*)packedPixel
)[index
] =
5584 ((GLushort
)((shoveComponents
[0] * 31)+0.5) << 11) & 0xf800;
5585 ((GLushort
*)packedPixel
)[index
]|=
5586 ((GLushort
)((shoveComponents
[1] * 63)+0.5) << 5) & 0x07e0;
5587 ((GLushort
*)packedPixel
)[index
]|=
5588 ((GLushort
)((shoveComponents
[2] * 31)+0.5) ) & 0x001f;
5591 static void extract565rev(int isSwap
,
5592 const void *packedPixel
, GLfloat extractComponents
[])
5594 GLushort ushort
= *(const GLushort
*)packedPixel
;
5597 ushort
= __GLU_SWAP_2_BYTES(packedPixel
);
5600 ushort
= *(const GLushort
*)packedPixel
;
5603 /* 00000000,00011111 == 0x001f */
5604 /* 00000111,11100000 == 0x07e0 */
5605 /* 11111000,00000000 == 0xf800 */
5607 extractComponents
[0]= (float)((ushort
& 0x001F) ) / 31.0;
5608 extractComponents
[1]= (float)((ushort
& 0x07E0) >> 5) / 63.0;
5609 extractComponents
[2]= (float)((ushort
& 0xF800) >> 11) / 31.0;
5610 } /* extract565rev() */
5612 static void shove565rev(const GLfloat shoveComponents
[],
5613 int index
,void *packedPixel
)
5615 /* 00000000,00011111 == 0x001f */
5616 /* 00000111,11100000 == 0x07e0 */
5617 /* 11111000,00000000 == 0xf800 */
5619 assert(0.0 <= shoveComponents
[0] && shoveComponents
[0] <= 1.0);
5620 assert(0.0 <= shoveComponents
[1] && shoveComponents
[1] <= 1.0);
5621 assert(0.0 <= shoveComponents
[2] && shoveComponents
[2] <= 1.0);
5623 /* due to limited precision, need to round before shoving */
5624 ((GLushort
*)packedPixel
)[index
] =
5625 ((GLushort
)((shoveComponents
[0] * 31.0)+0.5) ) & 0x001F;
5626 ((GLushort
*)packedPixel
)[index
]|=
5627 ((GLushort
)((shoveComponents
[1] * 63.0)+0.5) << 5) & 0x07E0;
5628 ((GLushort
*)packedPixel
)[index
]|=
5629 ((GLushort
)((shoveComponents
[2] * 31.0)+0.5) << 11) & 0xF800;
5630 } /* shove565rev() */
5632 static void extract4444(int isSwap
,const void *packedPixel
,
5633 GLfloat extractComponents
[])
5638 ushort
= __GLU_SWAP_2_BYTES(packedPixel
);
5641 ushort
= *(const GLushort
*)packedPixel
;
5644 /* 11110000,00000000 == 0xf000 */
5645 /* 00001111,00000000 == 0x0f00 */
5646 /* 00000000,11110000 == 0x00f0 */
5647 /* 00000000,00001111 == 0x000f */
5649 extractComponents
[0]= (float)((ushort
& 0xf000) >> 12) / 15.0;/* 15=2^4-1 */
5650 extractComponents
[1]= (float)((ushort
& 0x0f00) >> 8) / 15.0;
5651 extractComponents
[2]= (float)((ushort
& 0x00f0) >> 4) / 15.0;
5652 extractComponents
[3]= (float)((ushort
& 0x000f) ) / 15.0;
5653 } /* extract4444() */
5655 static void shove4444(const GLfloat shoveComponents
[],
5656 int index
,void *packedPixel
)
5658 assert(0.0 <= shoveComponents
[0] && shoveComponents
[0] <= 1.0);
5659 assert(0.0 <= shoveComponents
[1] && shoveComponents
[1] <= 1.0);
5660 assert(0.0 <= shoveComponents
[2] && shoveComponents
[2] <= 1.0);
5661 assert(0.0 <= shoveComponents
[3] && shoveComponents
[3] <= 1.0);
5663 /* due to limited precision, need to round before shoving */
5664 ((GLushort
*)packedPixel
)[index
] =
5665 ((GLushort
)((shoveComponents
[0] * 15)+0.5) << 12) & 0xf000;
5666 ((GLushort
*)packedPixel
)[index
]|=
5667 ((GLushort
)((shoveComponents
[1] * 15)+0.5) << 8) & 0x0f00;
5668 ((GLushort
*)packedPixel
)[index
]|=
5669 ((GLushort
)((shoveComponents
[2] * 15)+0.5) << 4) & 0x00f0;
5670 ((GLushort
*)packedPixel
)[index
]|=
5671 ((GLushort
)((shoveComponents
[3] * 15)+0.5) ) & 0x000f;
5674 static void extract4444rev(int isSwap
,const void *packedPixel
,
5675 GLfloat extractComponents
[])
5680 ushort
= __GLU_SWAP_2_BYTES(packedPixel
);
5683 ushort
= *(const GLushort
*)packedPixel
;
5686 /* 00000000,00001111 == 0x000f */
5687 /* 00000000,11110000 == 0x00f0 */
5688 /* 00001111,00000000 == 0x0f00 */
5689 /* 11110000,00000000 == 0xf000 */
5692 extractComponents
[0]= (float)((ushort
& 0x000F) ) / 15.0;
5693 extractComponents
[1]= (float)((ushort
& 0x00F0) >> 4) / 15.0;
5694 extractComponents
[2]= (float)((ushort
& 0x0F00) >> 8) / 15.0;
5695 extractComponents
[3]= (float)((ushort
& 0xF000) >> 12) / 15.0;
5696 } /* extract4444rev() */
5698 static void shove4444rev(const GLfloat shoveComponents
[],
5699 int index
,void *packedPixel
)
5701 /* 00000000,00001111 == 0x000f */
5702 /* 00000000,11110000 == 0x00f0 */
5703 /* 00001111,00000000 == 0x0f00 */
5704 /* 11110000,00000000 == 0xf000 */
5706 assert(0.0 <= shoveComponents
[0] && shoveComponents
[0] <= 1.0);
5707 assert(0.0 <= shoveComponents
[1] && shoveComponents
[1] <= 1.0);
5708 assert(0.0 <= shoveComponents
[2] && shoveComponents
[2] <= 1.0);
5709 assert(0.0 <= shoveComponents
[3] && shoveComponents
[3] <= 1.0);
5711 /* due to limited precision, need to round before shoving */
5712 ((GLushort
*)packedPixel
)[index
] =
5713 ((GLushort
)((shoveComponents
[0] * 15)+0.5) ) & 0x000F;
5714 ((GLushort
*)packedPixel
)[index
]|=
5715 ((GLushort
)((shoveComponents
[1] * 15)+0.5) << 4) & 0x00F0;
5716 ((GLushort
*)packedPixel
)[index
]|=
5717 ((GLushort
)((shoveComponents
[2] * 15)+0.5) << 8) & 0x0F00;
5718 ((GLushort
*)packedPixel
)[index
]|=
5719 ((GLushort
)((shoveComponents
[3] * 15)+0.5) << 12) & 0xF000;
5720 } /* shove4444rev() */
5722 static void extract5551(int isSwap
,const void *packedPixel
,
5723 GLfloat extractComponents
[])
5728 ushort
= __GLU_SWAP_2_BYTES(packedPixel
);
5731 ushort
= *(const GLushort
*)packedPixel
;
5734 /* 11111000,00000000 == 0xf800 */
5735 /* 00000111,11000000 == 0x07c0 */
5736 /* 00000000,00111110 == 0x003e */
5737 /* 00000000,00000001 == 0x0001 */
5739 extractComponents
[0]=(float)((ushort
& 0xf800) >> 11) / 31.0;/* 31 = 2^5-1*/
5740 extractComponents
[1]=(float)((ushort
& 0x07c0) >> 6) / 31.0;
5741 extractComponents
[2]=(float)((ushort
& 0x003e) >> 1) / 31.0;
5742 extractComponents
[3]=(float)((ushort
& 0x0001) );
5743 } /* extract5551() */
5745 static void shove5551(const GLfloat shoveComponents
[],
5746 int index
,void *packedPixel
)
5748 /* 11111000,00000000 == 0xf800 */
5749 /* 00000111,11000000 == 0x07c0 */
5750 /* 00000000,00111110 == 0x003e */
5751 /* 00000000,00000001 == 0x0001 */
5753 assert(0.0 <= shoveComponents
[0] && shoveComponents
[0] <= 1.0);
5754 assert(0.0 <= shoveComponents
[1] && shoveComponents
[1] <= 1.0);
5755 assert(0.0 <= shoveComponents
[2] && shoveComponents
[2] <= 1.0);
5756 assert(0.0 <= shoveComponents
[3] && shoveComponents
[3] <= 1.0);
5758 /* due to limited precision, need to round before shoving */
5759 ((GLushort
*)packedPixel
)[index
] =
5760 ((GLushort
)((shoveComponents
[0] * 31)+0.5) << 11) & 0xf800;
5761 ((GLushort
*)packedPixel
)[index
]|=
5762 ((GLushort
)((shoveComponents
[1] * 31)+0.5) << 6) & 0x07c0;
5763 ((GLushort
*)packedPixel
)[index
]|=
5764 ((GLushort
)((shoveComponents
[2] * 31)+0.5) << 1) & 0x003e;
5765 ((GLushort
*)packedPixel
)[index
]|=
5766 ((GLushort
)((shoveComponents
[3])+0.5) ) & 0x0001;
5769 static void extract1555rev(int isSwap
,const void *packedPixel
,
5770 GLfloat extractComponents
[])
5775 ushort
= __GLU_SWAP_2_BYTES(packedPixel
);
5778 ushort
= *(const GLushort
*)packedPixel
;
5781 /* 00000000,00011111 == 0x001F */
5782 /* 00000011,11100000 == 0x03E0 */
5783 /* 01111100,00000000 == 0x7C00 */
5784 /* 10000000,00000000 == 0x8000 */
5787 extractComponents
[0]= (float)((ushort
& 0x001F) ) / 31.0;
5788 extractComponents
[1]= (float)((ushort
& 0x03E0) >> 5) / 31.0;
5789 extractComponents
[2]= (float)((ushort
& 0x7C00) >> 10) / 31.0;
5790 extractComponents
[3]= (float)((ushort
& 0x8000) >> 15);
5791 } /* extract1555rev() */
5793 static void shove1555rev(const GLfloat shoveComponents
[],
5794 int index
,void *packedPixel
)
5796 /* 00000000,00011111 == 0x001F */
5797 /* 00000011,11100000 == 0x03E0 */
5798 /* 01111100,00000000 == 0x7C00 */
5799 /* 10000000,00000000 == 0x8000 */
5801 assert(0.0 <= shoveComponents
[0] && shoveComponents
[0] <= 1.0);
5802 assert(0.0 <= shoveComponents
[1] && shoveComponents
[1] <= 1.0);
5803 assert(0.0 <= shoveComponents
[2] && shoveComponents
[2] <= 1.0);
5804 assert(0.0 <= shoveComponents
[3] && shoveComponents
[3] <= 1.0);
5806 /* due to limited precision, need to round before shoving */
5807 ((GLushort
*)packedPixel
)[index
] =
5808 ((GLushort
)((shoveComponents
[0] * 31)+0.5) ) & 0x001F;
5809 ((GLushort
*)packedPixel
)[index
]|=
5810 ((GLushort
)((shoveComponents
[1] * 31)+0.5) << 5) & 0x03E0;
5811 ((GLushort
*)packedPixel
)[index
]|=
5812 ((GLushort
)((shoveComponents
[2] * 31)+0.5) << 10) & 0x7C00;
5813 ((GLushort
*)packedPixel
)[index
]|=
5814 ((GLushort
)((shoveComponents
[3])+0.5) << 15) & 0x8000;
5815 } /* shove1555rev() */
5817 static void extract8888(int isSwap
,
5818 const void *packedPixel
, GLfloat extractComponents
[])
5823 uint
= __GLU_SWAP_4_BYTES(packedPixel
);
5826 uint
= *(const GLuint
*)packedPixel
;
5829 /* 11111111,00000000,00000000,00000000 == 0xff000000 */
5830 /* 00000000,11111111,00000000,00000000 == 0x00ff0000 */
5831 /* 00000000,00000000,11111111,00000000 == 0x0000ff00 */
5832 /* 00000000,00000000,00000000,11111111 == 0x000000ff */
5835 extractComponents
[0]= (float)((uint
& 0xff000000) >> 24) / 255.0;
5836 extractComponents
[1]= (float)((uint
& 0x00ff0000) >> 16) / 255.0;
5837 extractComponents
[2]= (float)((uint
& 0x0000ff00) >> 8) / 255.0;
5838 extractComponents
[3]= (float)((uint
& 0x000000ff) ) / 255.0;
5839 } /* extract8888() */
5841 static void shove8888(const GLfloat shoveComponents
[],
5842 int index
,void *packedPixel
)
5844 /* 11111111,00000000,00000000,00000000 == 0xff000000 */
5845 /* 00000000,11111111,00000000,00000000 == 0x00ff0000 */
5846 /* 00000000,00000000,11111111,00000000 == 0x0000ff00 */
5847 /* 00000000,00000000,00000000,11111111 == 0x000000ff */
5849 assert(0.0 <= shoveComponents
[0] && shoveComponents
[0] <= 1.0);
5850 assert(0.0 <= shoveComponents
[1] && shoveComponents
[1] <= 1.0);
5851 assert(0.0 <= shoveComponents
[2] && shoveComponents
[2] <= 1.0);
5852 assert(0.0 <= shoveComponents
[3] && shoveComponents
[3] <= 1.0);
5854 /* due to limited precision, need to round before shoving */
5855 ((GLuint
*)packedPixel
)[index
] =
5856 ((GLuint
)((shoveComponents
[0] * 255)+0.5) << 24) & 0xff000000;
5857 ((GLuint
*)packedPixel
)[index
]|=
5858 ((GLuint
)((shoveComponents
[1] * 255)+0.5) << 16) & 0x00ff0000;
5859 ((GLuint
*)packedPixel
)[index
]|=
5860 ((GLuint
)((shoveComponents
[2] * 255)+0.5) << 8) & 0x0000ff00;
5861 ((GLuint
*)packedPixel
)[index
]|=
5862 ((GLuint
)((shoveComponents
[3] * 255)+0.5) ) & 0x000000ff;
5865 static void extract8888rev(int isSwap
,
5866 const void *packedPixel
,GLfloat extractComponents
[])
5871 uint
= __GLU_SWAP_4_BYTES(packedPixel
);
5874 uint
= *(const GLuint
*)packedPixel
;
5877 /* 00000000,00000000,00000000,11111111 == 0x000000ff */
5878 /* 00000000,00000000,11111111,00000000 == 0x0000ff00 */
5879 /* 00000000,11111111,00000000,00000000 == 0x00ff0000 */
5880 /* 11111111,00000000,00000000,00000000 == 0xff000000 */
5883 extractComponents
[0]= (float)((uint
& 0x000000FF) ) / 255.0;
5884 extractComponents
[1]= (float)((uint
& 0x0000FF00) >> 8) / 255.0;
5885 extractComponents
[2]= (float)((uint
& 0x00FF0000) >> 16) / 255.0;
5886 extractComponents
[3]= (float)((uint
& 0xFF000000) >> 24) / 255.0;
5887 } /* extract8888rev() */
5889 static void shove8888rev(const GLfloat shoveComponents
[],
5890 int index
,void *packedPixel
)
5892 /* 00000000,00000000,00000000,11111111 == 0x000000ff */
5893 /* 00000000,00000000,11111111,00000000 == 0x0000ff00 */
5894 /* 00000000,11111111,00000000,00000000 == 0x00ff0000 */
5895 /* 11111111,00000000,00000000,00000000 == 0xff000000 */
5897 assert(0.0 <= shoveComponents
[0] && shoveComponents
[0] <= 1.0);
5898 assert(0.0 <= shoveComponents
[1] && shoveComponents
[1] <= 1.0);
5899 assert(0.0 <= shoveComponents
[2] && shoveComponents
[2] <= 1.0);
5900 assert(0.0 <= shoveComponents
[3] && shoveComponents
[3] <= 1.0);
5902 /* due to limited precision, need to round before shoving */
5903 ((GLuint
*)packedPixel
)[index
] =
5904 ((GLuint
)((shoveComponents
[0] * 255)+0.5) ) & 0x000000FF;
5905 ((GLuint
*)packedPixel
)[index
]|=
5906 ((GLuint
)((shoveComponents
[1] * 255)+0.5) << 8) & 0x0000FF00;
5907 ((GLuint
*)packedPixel
)[index
]|=
5908 ((GLuint
)((shoveComponents
[2] * 255)+0.5) << 16) & 0x00FF0000;
5909 ((GLuint
*)packedPixel
)[index
]|=
5910 ((GLuint
)((shoveComponents
[3] * 255)+0.5) << 24) & 0xFF000000;
5911 } /* shove8888rev() */
5913 static void extract1010102(int isSwap
,
5914 const void *packedPixel
,GLfloat extractComponents
[])
5919 uint
= __GLU_SWAP_4_BYTES(packedPixel
);
5922 uint
= *(const GLuint
*)packedPixel
;
5925 /* 11111111,11000000,00000000,00000000 == 0xffc00000 */
5926 /* 00000000,00111111,11110000,00000000 == 0x003ff000 */
5927 /* 00000000,00000000,00001111,11111100 == 0x00000ffc */
5928 /* 00000000,00000000,00000000,00000011 == 0x00000003 */
5931 extractComponents
[0]= (float)((uint
& 0xffc00000) >> 22) / 1023.0;
5932 extractComponents
[1]= (float)((uint
& 0x003ff000) >> 12) / 1023.0;
5933 extractComponents
[2]= (float)((uint
& 0x00000ffc) >> 2) / 1023.0;
5934 extractComponents
[3]= (float)((uint
& 0x00000003) ) / 3.0;
5935 } /* extract1010102() */
5937 static void shove1010102(const GLfloat shoveComponents
[],
5938 int index
,void *packedPixel
)
5940 /* 11111111,11000000,00000000,00000000 == 0xffc00000 */
5941 /* 00000000,00111111,11110000,00000000 == 0x003ff000 */
5942 /* 00000000,00000000,00001111,11111100 == 0x00000ffc */
5943 /* 00000000,00000000,00000000,00000011 == 0x00000003 */
5945 assert(0.0 <= shoveComponents
[0] && shoveComponents
[0] <= 1.0);
5946 assert(0.0 <= shoveComponents
[1] && shoveComponents
[1] <= 1.0);
5947 assert(0.0 <= shoveComponents
[2] && shoveComponents
[2] <= 1.0);
5948 assert(0.0 <= shoveComponents
[3] && shoveComponents
[3] <= 1.0);
5950 /* due to limited precision, need to round before shoving */
5951 ((GLuint
*)packedPixel
)[index
] =
5952 ((GLuint
)((shoveComponents
[0] * 1023)+0.5) << 22) & 0xffc00000;
5953 ((GLuint
*)packedPixel
)[index
]|=
5954 ((GLuint
)((shoveComponents
[1] * 1023)+0.5) << 12) & 0x003ff000;
5955 ((GLuint
*)packedPixel
)[index
]|=
5956 ((GLuint
)((shoveComponents
[2] * 1023)+0.5) << 2) & 0x00000ffc;
5957 ((GLuint
*)packedPixel
)[index
]|=
5958 ((GLuint
)((shoveComponents
[3] * 3)+0.5) ) & 0x00000003;
5959 } /* shove1010102() */
5961 static void extract2101010rev(int isSwap
,
5962 const void *packedPixel
,
5963 GLfloat extractComponents
[])
5968 uint
= __GLU_SWAP_4_BYTES(packedPixel
);
5971 uint
= *(const GLuint
*)packedPixel
;
5974 /* 00000000,00000000,00000011,11111111 == 0x000003FF */
5975 /* 00000000,00001111,11111100,00000000 == 0x000FFC00 */
5976 /* 00111111,11110000,00000000,00000000 == 0x3FF00000 */
5977 /* 11000000,00000000,00000000,00000000 == 0xC0000000 */
5980 extractComponents
[0]= (float)((uint
& 0x000003FF) ) / 1023.0;
5981 extractComponents
[1]= (float)((uint
& 0x000FFC00) >> 10) / 1023.0;
5982 extractComponents
[2]= (float)((uint
& 0x3FF00000) >> 20) / 1023.0;
5983 extractComponents
[3]= (float)((uint
& 0xC0000000) >> 30) / 3.0;
5985 } /* extract2101010rev() */
5987 static void shove2101010rev(const GLfloat shoveComponents
[],
5988 int index
,void *packedPixel
)
5990 /* 00000000,00000000,00000011,11111111 == 0x000003FF */
5991 /* 00000000,00001111,11111100,00000000 == 0x000FFC00 */
5992 /* 00111111,11110000,00000000,00000000 == 0x3FF00000 */
5993 /* 11000000,00000000,00000000,00000000 == 0xC0000000 */
5995 assert(0.0 <= shoveComponents
[0] && shoveComponents
[0] <= 1.0);
5996 assert(0.0 <= shoveComponents
[1] && shoveComponents
[1] <= 1.0);
5997 assert(0.0 <= shoveComponents
[2] && shoveComponents
[2] <= 1.0);
5998 assert(0.0 <= shoveComponents
[3] && shoveComponents
[3] <= 1.0);
6000 /* due to limited precision, need to round before shoving */
6001 ((GLuint
*)packedPixel
)[index
] =
6002 ((GLuint
)((shoveComponents
[0] * 1023)+0.5) ) & 0x000003FF;
6003 ((GLuint
*)packedPixel
)[index
]|=
6004 ((GLuint
)((shoveComponents
[1] * 1023)+0.5) << 10) & 0x000FFC00;
6005 ((GLuint
*)packedPixel
)[index
]|=
6006 ((GLuint
)((shoveComponents
[2] * 1023)+0.5) << 20) & 0x3FF00000;
6007 ((GLuint
*)packedPixel
)[index
]|=
6008 ((GLuint
)((shoveComponents
[3] * 3)+0.5) << 30) & 0xC0000000;
6009 } /* shove2101010rev() */
6011 static void scaleInternalPackedPixel(int components
,
6012 void (*extractPackedPixel
)
6013 (int, const void *,GLfloat
[]),
6014 void (*shovePackedPixel
)
6015 (const GLfloat
[], int, void *),
6016 GLint widthIn
,GLint heightIn
,
6018 GLint widthOut
,GLint heightOut
,
6020 GLint pixelSizeInBytes
,
6021 GLint rowSizeInBytes
,GLint isSwap
)
6027 /* Max components in a format is 4, so... */
6029 float extractTotals
[4], extractMoreTotals
[4], shoveTotals
[4];
6034 const char *temp
, *temp0
;
6037 int lowx_int
, highx_int
, lowy_int
, highy_int
;
6038 float x_percent
, y_percent
;
6039 float lowx_float
, highx_float
, lowy_float
, highy_float
;
6040 float convy_float
, convx_float
;
6041 int convy_int
, convx_int
;
6043 const char *left
, *right
;
6045 if (widthIn
== widthOut
*2 && heightIn
== heightOut
*2) {
6046 halveImagePackedPixel(components
,extractPackedPixel
,shovePackedPixel
,
6047 widthIn
, heightIn
, dataIn
, dataOut
,
6048 pixelSizeInBytes
,rowSizeInBytes
,isSwap
);
6051 convy
= (float) heightIn
/heightOut
;
6052 convx
= (float) widthIn
/widthOut
;
6053 convy_int
= floor(convy
);
6054 convy_float
= convy
- convy_int
;
6055 convx_int
= floor(convx
);
6056 convx_float
= convx
- convx_int
;
6058 area
= convx
* convy
;
6062 highy_int
= convy_int
;
6063 highy_float
= convy_float
;
6065 for (i
= 0; i
< heightOut
; i
++) {
6068 highx_int
= convx_int
;
6069 highx_float
= convx_float
;
6071 for (j
= 0; j
< widthOut
; j
++) {
6073 ** Ok, now apply box filter to box that goes from (lowx, lowy)
6074 ** to (highx, highy) on input data into this pixel on output
6077 totals
[0] = totals
[1] = totals
[2] = totals
[3] = 0.0;
6079 /* calculate the value for pixels in the 1st row */
6080 xindex
= lowx_int
*pixelSizeInBytes
;
6081 if((highy_int
>lowy_int
) && (highx_int
>lowx_int
)) {
6083 y_percent
= 1-lowy_float
;
6084 temp
= (const char *)dataIn
+ xindex
+ lowy_int
* rowSizeInBytes
;
6085 percent
= y_percent
* (1-lowx_float
);
6087 for (k
= 0, temp_index
= temp
; k
< components
;
6088 k
++, temp_index
+= element_size
) {
6090 totals
[k
] += __GLU_SWAP_2_BYTES(temp_index
) * percent
;
6092 totals
[k
] += *(const GLushort
*)temp_index
* percent
;
6096 (*extractPackedPixel
)(isSwap
,temp
,extractTotals
);
6097 for (k
= 0; k
< components
; k
++) {
6098 totals
[k
]+= extractTotals
[k
] * percent
;
6102 for(l
= lowx_int
+1; l
< highx_int
; l
++) {
6103 temp
+= pixelSizeInBytes
;
6105 for (k
= 0, temp_index
= temp
; k
< components
;
6106 k
++, temp_index
+= element_size
) {
6109 __GLU_SWAP_2_BYTES(temp_index
) * y_percent
;
6111 totals
[k
] += *(const GLushort
*)temp_index
* y_percent
;
6115 (*extractPackedPixel
)(isSwap
,temp
,extractTotals
);
6116 for (k
= 0; k
< components
; k
++) {
6117 totals
[k
]+= extractTotals
[k
] * y_percent
;
6121 temp
+= pixelSizeInBytes
;
6123 percent
= y_percent
* highx_float
;
6125 for (k
= 0, temp_index
= temp
; k
< components
;
6126 k
++, temp_index
+= element_size
) {
6128 totals
[k
] += __GLU_SWAP_2_BYTES(temp_index
) * percent
;
6130 totals
[k
] += *(const GLushort
*)temp_index
* percent
;
6134 (*extractPackedPixel
)(isSwap
,temp
,extractTotals
);
6135 for (k
= 0; k
< components
; k
++) {
6136 totals
[k
]+= extractTotals
[k
] * percent
;
6140 /* calculate the value for pixels in the last row */
6142 y_percent
= highy_float
;
6143 percent
= y_percent
* (1-lowx_float
);
6144 temp
= (const char *)dataIn
+ xindex
+ highy_int
* rowSizeInBytes
;
6146 for (k
= 0, temp_index
= temp
; k
< components
;
6147 k
++, temp_index
+= element_size
) {
6149 totals
[k
] += __GLU_SWAP_2_BYTES(temp_index
) * percent
;
6151 totals
[k
] += *(const GLushort
*)temp_index
* percent
;
6155 (*extractPackedPixel
)(isSwap
,temp
,extractTotals
);
6156 for (k
= 0; k
< components
; k
++) {
6157 totals
[k
]+= extractTotals
[k
] * percent
;
6160 for(l
= lowx_int
+1; l
< highx_int
; l
++) {
6161 temp
+= pixelSizeInBytes
;
6163 for (k
= 0, temp_index
= temp
; k
< components
;
6164 k
++, temp_index
+= element_size
) {
6167 __GLU_SWAP_2_BYTES(temp_index
) * y_percent
;
6169 totals
[k
] += *(const GLushort
*)temp_index
* y_percent
;
6173 (*extractPackedPixel
)(isSwap
,temp
,extractTotals
);
6174 for (k
= 0; k
< components
; k
++) {
6175 totals
[k
]+= extractTotals
[k
] * y_percent
;
6180 temp
+= pixelSizeInBytes
;
6181 percent
= y_percent
* highx_float
;
6183 for (k
= 0, temp_index
= temp
; k
< components
;
6184 k
++, temp_index
+= element_size
) {
6186 totals
[k
] += __GLU_SWAP_2_BYTES(temp_index
) * percent
;
6188 totals
[k
] += *(const GLushort
*)temp_index
* percent
;
6192 (*extractPackedPixel
)(isSwap
,temp
,extractTotals
);
6193 for (k
= 0; k
< components
; k
++) {
6194 totals
[k
]+= extractTotals
[k
] * percent
;
6198 /* calculate the value for pixels in the 1st and last column */
6199 for(m
= lowy_int
+1; m
< highy_int
; m
++) {
6200 left
+= rowSizeInBytes
;
6201 right
+= rowSizeInBytes
;
6203 for (k
= 0; k
< components
;
6204 k
++, left
+= element_size
, right
+= element_size
) {
6207 __GLU_SWAP_2_BYTES(left
) * (1-lowx_float
) +
6208 __GLU_SWAP_2_BYTES(right
) * highx_float
;
6210 totals
[k
] += *(const GLushort
*)left
* (1-lowx_float
)
6211 + *(const GLushort
*)right
* highx_float
;
6215 (*extractPackedPixel
)(isSwap
,left
,extractTotals
);
6216 (*extractPackedPixel
)(isSwap
,right
,extractMoreTotals
);
6217 for (k
= 0; k
< components
; k
++) {
6218 totals
[k
]+= (extractTotals
[k
]*(1-lowx_float
) +
6219 extractMoreTotals
[k
]*highx_float
);
6223 } else if (highy_int
> lowy_int
) {
6224 x_percent
= highx_float
- lowx_float
;
6225 percent
= (1-lowy_float
)*x_percent
;
6226 temp
= (const char *)dataIn
+ xindex
+ lowy_int
*rowSizeInBytes
;
6228 for (k
= 0, temp_index
= temp
; k
< components
;
6229 k
++, temp_index
+= element_size
) {
6231 totals
[k
] += __GLU_SWAP_2_BYTES(temp_index
) * percent
;
6233 totals
[k
] += *(const GLushort
*)temp_index
* percent
;
6237 (*extractPackedPixel
)(isSwap
,temp
,extractTotals
);
6238 for (k
= 0; k
< components
; k
++) {
6239 totals
[k
]+= extractTotals
[k
] * percent
;
6242 for(m
= lowy_int
+1; m
< highy_int
; m
++) {
6243 temp
+= rowSizeInBytes
;
6245 for (k
= 0, temp_index
= temp
; k
< components
;
6246 k
++, temp_index
+= element_size
) {
6249 __GLU_SWAP_2_BYTES(temp_index
) * x_percent
;
6251 totals
[k
] += *(const GLushort
*)temp_index
* x_percent
;
6255 (*extractPackedPixel
)(isSwap
,temp
,extractTotals
);
6256 for (k
= 0; k
< components
; k
++) {
6257 totals
[k
]+= extractTotals
[k
] * x_percent
;
6261 percent
= x_percent
* highy_float
;
6262 temp
+= rowSizeInBytes
;
6264 for (k
= 0, temp_index
= temp
; k
< components
;
6265 k
++, temp_index
+= element_size
) {
6267 totals
[k
] += __GLU_SWAP_2_BYTES(temp_index
) * percent
;
6269 totals
[k
] += *(const GLushort
*)temp_index
* percent
;
6273 (*extractPackedPixel
)(isSwap
,temp
,extractTotals
);
6274 for (k
= 0; k
< components
; k
++) {
6275 totals
[k
]+= extractTotals
[k
] * percent
;
6278 } else if (highx_int
> lowx_int
) {
6279 y_percent
= highy_float
- lowy_float
;
6280 percent
= (1-lowx_float
)*y_percent
;
6281 temp
= (const char *)dataIn
+ xindex
+ lowy_int
*rowSizeInBytes
;
6283 for (k
= 0, temp_index
= temp
; k
< components
;
6284 k
++, temp_index
+= element_size
) {
6286 totals
[k
] += __GLU_SWAP_2_BYTES(temp_index
) * percent
;
6288 totals
[k
] += *(const GLushort
*)temp_index
* percent
;
6292 (*extractPackedPixel
)(isSwap
,temp
,extractTotals
);
6293 for (k
= 0; k
< components
; k
++) {
6294 totals
[k
]+= extractTotals
[k
] * percent
;
6297 for (l
= lowx_int
+1; l
< highx_int
; l
++) {
6298 temp
+= pixelSizeInBytes
;
6300 for (k
= 0, temp_index
= temp
; k
< components
;
6301 k
++, temp_index
+= element_size
) {
6304 __GLU_SWAP_2_BYTES(temp_index
) * y_percent
;
6306 totals
[k
] += *(const GLushort
*)temp_index
* y_percent
;
6310 (*extractPackedPixel
)(isSwap
,temp
,extractTotals
);
6311 for (k
= 0; k
< components
; k
++) {
6312 totals
[k
]+= extractTotals
[k
] * y_percent
;
6316 temp
+= pixelSizeInBytes
;
6317 percent
= y_percent
* highx_float
;
6319 for (k
= 0, temp_index
= temp
; k
< components
;
6320 k
++, temp_index
+= element_size
) {
6322 totals
[k
] += __GLU_SWAP_2_BYTES(temp_index
) * percent
;
6324 totals
[k
] += *(const GLushort
*)temp_index
* percent
;
6328 (*extractPackedPixel
)(isSwap
,temp
,extractTotals
);
6329 for (k
= 0; k
< components
; k
++) {
6330 totals
[k
]+= extractTotals
[k
] * percent
;
6334 percent
= (highy_float
-lowy_float
)*(highx_float
-lowx_float
);
6335 temp
= (const char *)dataIn
+ xindex
+ lowy_int
* rowSizeInBytes
;
6337 for (k
= 0, temp_index
= temp
; k
< components
;
6338 k
++, temp_index
+= element_size
) {
6340 totals
[k
] += __GLU_SWAP_2_BYTES(temp_index
) * percent
;
6342 totals
[k
] += *(const GLushort
*)temp_index
* percent
;
6346 (*extractPackedPixel
)(isSwap
,temp
,extractTotals
);
6347 for (k
= 0; k
< components
; k
++) {
6348 totals
[k
]+= extractTotals
[k
] * percent
;
6353 /* this is for the pixels in the body */
6354 temp0
= (const char *)dataIn
+ xindex
+ pixelSizeInBytes
+ (lowy_int
+1)*rowSizeInBytes
;
6355 for (m
= lowy_int
+1; m
< highy_int
; m
++) {
6357 for(l
= lowx_int
+1; l
< highx_int
; l
++) {
6359 for (k
= 0, temp_index
= temp
; k
< components
;
6360 k
++, temp_index
+= element_size
) {
6362 totals
[k
] += __GLU_SWAP_2_BYTES(temp_index
);
6364 totals
[k
] += *(const GLushort
*)temp_index
;
6368 (*extractPackedPixel
)(isSwap
,temp
,extractTotals
);
6369 for (k
= 0; k
< components
; k
++) {
6370 totals
[k
]+= extractTotals
[k
];
6373 temp
+= pixelSizeInBytes
;
6375 temp0
+= rowSizeInBytes
;
6378 outindex
= (j
+ (i
* widthOut
)); /* * (components == 1) */
6380 for (k
= 0; k
< components
; k
++) {
6381 dataout
[outindex
+ k
] = totals
[k
]/area
;
6382 /*printf("totals[%d] = %f\n", k, totals[k]);*/
6385 for (k
= 0; k
< components
; k
++) {
6386 shoveTotals
[k
]= totals
[k
]/area
;
6388 (*shovePackedPixel
)(shoveTotals
,outindex
,(void *)dataOut
);
6390 lowx_int
= highx_int
;
6391 lowx_float
= highx_float
;
6392 highx_int
+= convx_int
;
6393 highx_float
+= convx_float
;
6394 if(highx_float
> 1) {
6399 lowy_int
= highy_int
;
6400 lowy_float
= highy_float
;
6401 highy_int
+= convy_int
;
6402 highy_float
+= convy_float
;
6403 if(highy_float
> 1) {
6409 assert(outindex
== (widthOut
*heightOut
- 1));
6410 } /* scaleInternalPackedPixel() */
6412 /* rowSizeInBytes is at least the width (in bytes) due to padding on
6413 * inputs; not always equal. Output NEVER has row padding.
6415 static void halveImagePackedPixel(int components
,
6416 void (*extractPackedPixel
)
6417 (int, const void *,GLfloat
[]),
6418 void (*shovePackedPixel
)
6419 (const GLfloat
[],int, void *),
6420 GLint width
, GLint height
,
6421 const void *dataIn
, void *dataOut
,
6422 GLint pixelSizeInBytes
,
6423 GLint rowSizeInBytes
, GLint isSwap
)
6425 /* handle case where there is only 1 column/row */
6426 if (width
== 1 || height
== 1) {
6427 assert(!(width
== 1 && height
== 1)); /* can't be 1x1 */
6428 halve1DimagePackedPixel(components
,extractPackedPixel
,shovePackedPixel
,
6429 width
,height
,dataIn
,dataOut
,pixelSizeInBytes
,
6430 rowSizeInBytes
,isSwap
);
6437 int halfWidth
= width
/ 2;
6438 int halfHeight
= height
/ 2;
6439 const char *src
= (const char *) dataIn
;
6440 int padBytes
= rowSizeInBytes
- (width
*pixelSizeInBytes
);
6443 for (ii
= 0; ii
< halfHeight
; ii
++) {
6444 for (jj
= 0; jj
< halfWidth
; jj
++) {
6446 float totals
[4]; /* 4 is maximum components */
6447 float extractTotals
[BOX4
][4]; /* 4 is maximum components */
6450 (*extractPackedPixel
)(isSwap
,src
,
6451 &extractTotals
[0][0]);
6452 (*extractPackedPixel
)(isSwap
,(src
+pixelSizeInBytes
),
6453 &extractTotals
[1][0]);
6454 (*extractPackedPixel
)(isSwap
,(src
+rowSizeInBytes
),
6455 &extractTotals
[2][0]);
6456 (*extractPackedPixel
)(isSwap
,
6457 (src
+rowSizeInBytes
+pixelSizeInBytes
),
6458 &extractTotals
[3][0]);
6459 for (cc
= 0; cc
< components
; cc
++) {
6462 /* grab 4 pixels to average */
6464 /* totals[RED]= extractTotals[0][RED]+extractTotals[1][RED]+
6465 * extractTotals[2][RED]+extractTotals[3][RED];
6466 * totals[RED]/= 4.0;
6468 for (kk
= 0; kk
< BOX4
; kk
++) {
6469 totals
[cc
]+= extractTotals
[kk
][cc
];
6471 totals
[cc
]/= (float)BOX4
;
6473 (*shovePackedPixel
)(totals
,outIndex
,dataOut
);
6476 /* skip over to next square of 4 */
6477 src
+= pixelSizeInBytes
+ pixelSizeInBytes
;
6479 /* skip past pad bytes, if any, to get to next row */
6482 /* src is at beginning of a row here, but it's the second row of
6483 * the square block of 4 pixels that we just worked on so we
6484 * need to go one more row.
6492 src
+= rowSizeInBytes
;
6495 /* both pointers must reach one byte after the end */
6496 assert(src
== &((const char *)dataIn
)[rowSizeInBytes
*height
]);
6497 assert(outIndex
== halfWidth
* halfHeight
);
6499 } /* halveImagePackedPixel() */
6501 static void halve1DimagePackedPixel(int components
,
6502 void (*extractPackedPixel
)
6503 (int, const void *,GLfloat
[]),
6504 void (*shovePackedPixel
)
6505 (const GLfloat
[],int, void *),
6506 GLint width
, GLint height
,
6507 const void *dataIn
, void *dataOut
,
6508 GLint pixelSizeInBytes
,
6509 GLint rowSizeInBytes
, GLint isSwap
)
6511 int halfWidth
= width
/ 2;
6512 int halfHeight
= height
/ 2;
6513 const char *src
= (const char *) dataIn
;
6516 assert(width
== 1 || height
== 1); /* must be 1D */
6517 assert(width
!= height
); /* can't be square */
6519 if (height
== 1) { /* 1 row */
6522 assert(width
!= 1); /* widthxheight can't be 1x1 */
6525 /* one horizontal row with possible pad bytes */
6527 for (jj
= 0; jj
< halfWidth
; jj
++) {
6529 float totals
[4]; /* 4 is maximum components */
6530 float extractTotals
[BOX2
][4]; /* 4 is maximum components */
6533 /* average two at a time, instead of four */
6534 (*extractPackedPixel
)(isSwap
,src
,
6535 &extractTotals
[0][0]);
6536 (*extractPackedPixel
)(isSwap
,(src
+pixelSizeInBytes
),
6537 &extractTotals
[1][0]);
6538 for (cc
= 0; cc
< components
; cc
++) {
6541 /* grab 2 pixels to average */
6543 /* totals[RED]= extractTotals[0][RED]+extractTotals[1][RED];
6544 * totals[RED]/= 2.0;
6546 for (kk
= 0; kk
< BOX2
; kk
++) {
6547 totals
[cc
]+= extractTotals
[kk
][cc
];
6549 totals
[cc
]/= (float)BOX2
;
6551 (*shovePackedPixel
)(totals
,outIndex
,dataOut
);
6554 /* skip over to next group of 2 */
6555 src
+= pixelSizeInBytes
+ pixelSizeInBytes
;
6559 int padBytes
= rowSizeInBytes
- (width
*pixelSizeInBytes
);
6560 src
+= padBytes
; /* for assertion only */
6562 assert(src
== &((const char *)dataIn
)[rowSizeInBytes
]);
6563 assert(outIndex
== halfWidth
* halfHeight
);
6565 else if (width
== 1) { /* 1 column */
6568 assert(height
!= 1); /* widthxheight can't be 1x1 */
6570 /* one vertical column with possible pad bytes per row */
6571 /* average two at a time */
6573 for (jj
= 0; jj
< halfHeight
; jj
++) {
6575 float totals
[4]; /* 4 is maximum components */
6576 float extractTotals
[BOX2
][4]; /* 4 is maximum components */
6579 /* average two at a time, instead of four */
6580 (*extractPackedPixel
)(isSwap
,src
,
6581 &extractTotals
[0][0]);
6582 (*extractPackedPixel
)(isSwap
,(src
+rowSizeInBytes
),
6583 &extractTotals
[1][0]);
6584 for (cc
= 0; cc
< components
; cc
++) {
6587 /* grab 2 pixels to average */
6589 /* totals[RED]= extractTotals[0][RED]+extractTotals[1][RED];
6590 * totals[RED]/= 2.0;
6592 for (kk
= 0; kk
< BOX2
; kk
++) {
6593 totals
[cc
]+= extractTotals
[kk
][cc
];
6595 totals
[cc
]/= (float)BOX2
;
6597 (*shovePackedPixel
)(totals
,outIndex
,dataOut
);
6600 src
+= rowSizeInBytes
+ rowSizeInBytes
; /* go to row after next */
6603 assert(src
== &((const char *)dataIn
)[rowSizeInBytes
*height
]);
6604 assert(outIndex
== halfWidth
* halfHeight
);
6606 } /* halve1DimagePackedPixel() */
6608 /*===========================================================================*/
6610 #ifdef RESOLVE_3D_TEXTURE_SUPPORT
6612 * This section ensures that GLU 1.3 will load and run on
6613 * a GL 1.1 implementation. It dynamically resolves the
6614 * call to glTexImage3D() which might not be available.
6615 * Or is it might be supported as an extension.
6616 * Contributed by Gerk Huisma <gerk@five-d.demon.nl>.
6619 typedef void (GLAPIENTRY
*TexImage3Dproc
)( GLenum target
, GLint level
,
6620 GLenum internalFormat
,
6621 GLsizei width
, GLsizei height
,
6622 GLsizei depth
, GLint border
,
6623 GLenum format
, GLenum type
,
6624 const GLvoid
*pixels
);
6626 static TexImage3Dproc pTexImage3D
= 0;
6628 #if !defined(_WIN32) && !defined(__WIN32__)
6630 # include <sys/types.h>
6632 WINGDIAPI PROC WINAPI
wglGetProcAddress(LPCSTR
);
6635 static void gluTexImage3D( GLenum target
, GLint level
,
6636 GLenum internalFormat
,
6637 GLsizei width
, GLsizei height
,
6638 GLsizei depth
, GLint border
,
6639 GLenum format
, GLenum type
,
6640 const GLvoid
*pixels
)
6643 #if defined(_WIN32) || defined(__WIN32__)
6644 pTexImage3D
= (TexImage3Dproc
) wglGetProcAddress("glTexImage3D");
6646 pTexImage3D
= (TexImage3Dproc
) wglGetProcAddress("glTexImage3DEXT");
6648 void *libHandle
= dlopen("libgl.so", RTLD_LAZY
);
6649 pTexImage3D
= TexImage3Dproc
) dlsym(libHandle
, "glTexImage3D" );
6651 pTexImage3D
= (TexImage3Dproc
) dlsym(libHandle
,"glTexImage3DEXT");
6656 /* Now call glTexImage3D */
6658 pTexImage3D(target
, level
, internalFormat
, width
, height
,
6659 depth
, border
, format
, type
, pixels
);
6664 /* Only bind to a GL 1.2 implementation: */
6665 #define gluTexImage3D glTexImage3D
6669 static GLint
imageSize3D(GLint width
, GLint height
, GLint depth
,
6670 GLenum format
, GLenum type
)
6672 int components
= elements_per_group(format
,type
);
6673 int bytes_per_row
= bytes_per_element(type
) * width
;
6675 assert(width
> 0 && height
> 0 && depth
> 0);
6676 assert(type
!= GL_BITMAP
);
6678 return bytes_per_row
* height
* depth
* components
;
6679 } /* imageSize3D() */
6681 static void fillImage3D(const PixelStorageModes
*psm
,
6682 GLint width
, GLint height
, GLint depth
, GLenum format
,
6683 GLenum type
, GLboolean indexFormat
,
6684 const void *userImage
, GLushort
*newImage
)
6693 int elementsPerLine
;
6696 const GLubyte
*start
, *rowStart
, *iter
;
6700 myswapBytes
= psm
->unpack_swap_bytes
;
6701 components
= elements_per_group(format
,type
);
6702 if (psm
->unpack_row_length
> 0) {
6703 groupsPerLine
= psm
->unpack_row_length
;
6706 groupsPerLine
= width
;
6708 elementSize
= bytes_per_element(type
);
6709 groupSize
= elementSize
* components
;
6710 if (elementSize
== 1) myswapBytes
= 0;
6713 if (psm
->unpack_image_height
> 0) {
6714 rowsPerImage
= psm
->unpack_image_height
;
6717 rowsPerImage
= height
;
6721 rowSize
= groupsPerLine
* groupSize
;
6722 padding
= rowSize
% psm
->unpack_alignment
;
6724 rowSize
+= psm
->unpack_alignment
- padding
;
6727 imageSize
= rowsPerImage
* rowSize
; /* 3dstuff */
6729 start
= (const GLubyte
*)userImage
+ psm
->unpack_skip_rows
* rowSize
+
6730 psm
->unpack_skip_pixels
* groupSize
+
6732 psm
->unpack_skip_images
* imageSize
;
6733 elementsPerLine
= width
* components
;
6736 for (dd
= 0; dd
< depth
; dd
++) {
6739 for (hh
= 0; hh
< height
; hh
++) {
6742 for (ww
= 0; ww
< elementsPerLine
; ww
++) {
6744 float extractComponents
[4];
6747 case GL_UNSIGNED_BYTE
:
6751 *iter2
++ = (*iter
) * 257;
6756 *iter2
++ = *((const GLbyte
*) iter
);
6759 *iter2
++ = (*((const GLbyte
*) iter
)) * 516;
6762 case GL_UNSIGNED_BYTE_3_3_2
:
6763 extract332(0,iter
,extractComponents
);
6764 for (k
= 0; k
< 3; k
++) {
6765 *iter2
++ = (GLushort
)(extractComponents
[k
]*65535);
6768 case GL_UNSIGNED_BYTE_2_3_3_REV
:
6769 extract233rev(0,iter
,extractComponents
);
6770 for (k
= 0; k
< 3; k
++) {
6771 *iter2
++ = (GLushort
)(extractComponents
[k
]*65535);
6774 case GL_UNSIGNED_SHORT_5_6_5
:
6775 extract565(myswapBytes
,iter
,extractComponents
);
6776 for (k
= 0; k
< 3; k
++) {
6777 *iter2
++ = (GLushort
)(extractComponents
[k
]*65535);
6780 case GL_UNSIGNED_SHORT_5_6_5_REV
:
6781 extract565rev(myswapBytes
,iter
,extractComponents
);
6782 for (k
= 0; k
< 3; k
++) {
6783 *iter2
++ = (GLushort
)(extractComponents
[k
]*65535);
6786 case GL_UNSIGNED_SHORT_4_4_4_4
:
6787 extract4444(myswapBytes
,iter
,extractComponents
);
6788 for (k
= 0; k
< 4; k
++) {
6789 *iter2
++ = (GLushort
)(extractComponents
[k
]*65535);
6792 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
6793 extract4444rev(myswapBytes
,iter
,extractComponents
);
6794 for (k
= 0; k
< 4; k
++) {
6795 *iter2
++ = (GLushort
)(extractComponents
[k
]*65535);
6798 case GL_UNSIGNED_SHORT_5_5_5_1
:
6799 extract5551(myswapBytes
,iter
,extractComponents
);
6800 for (k
= 0; k
< 4; k
++) {
6801 *iter2
++ = (GLushort
)(extractComponents
[k
]*65535);
6804 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
6805 extract1555rev(myswapBytes
,iter
,extractComponents
);
6806 for (k
= 0; k
< 4; k
++) {
6807 *iter2
++ = (GLushort
)(extractComponents
[k
]*65535);
6810 case GL_UNSIGNED_SHORT
:
6813 widget
.ub
[0] = iter
[1];
6814 widget
.ub
[1] = iter
[0];
6816 widget
.ub
[0] = iter
[0];
6817 widget
.ub
[1] = iter
[1];
6819 if (type
== GL_SHORT
) {
6821 *iter2
++ = widget
.s
[0];
6824 *iter2
++ = widget
.s
[0]*2;
6827 *iter2
++ = widget
.us
[0];
6830 case GL_UNSIGNED_INT_8_8_8_8
:
6831 extract8888(myswapBytes
,iter
,extractComponents
);
6832 for (k
= 0; k
< 4; k
++) {
6833 *iter2
++ = (GLushort
)(extractComponents
[k
]*65535);
6836 case GL_UNSIGNED_INT_8_8_8_8_REV
:
6837 extract8888rev(myswapBytes
,iter
,extractComponents
);
6838 for (k
= 0; k
< 4; k
++) {
6839 *iter2
++ = (GLushort
)(extractComponents
[k
]*65535);
6842 case GL_UNSIGNED_INT_10_10_10_2
:
6843 extract1010102(myswapBytes
,iter
,extractComponents
);
6844 for (k
= 0; k
< 4; k
++) {
6845 *iter2
++ = (GLushort
)(extractComponents
[k
]*65535);
6848 case GL_UNSIGNED_INT_2_10_10_10_REV
:
6849 extract2101010rev(myswapBytes
,iter
,extractComponents
);
6850 for (k
= 0; k
< 4; k
++) {
6851 *iter2
++ = (GLushort
)(extractComponents
[k
]*65535);
6855 case GL_UNSIGNED_INT
:
6858 widget
.ub
[0] = iter
[3];
6859 widget
.ub
[1] = iter
[2];
6860 widget
.ub
[2] = iter
[1];
6861 widget
.ub
[3] = iter
[0];
6863 widget
.ub
[0] = iter
[0];
6864 widget
.ub
[1] = iter
[1];
6865 widget
.ub
[2] = iter
[2];
6866 widget
.ub
[3] = iter
[3];
6868 if (type
== GL_FLOAT
) {
6870 *iter2
++ = widget
.f
;
6872 *iter2
++ = 65535 * widget
.f
;
6874 } else if (type
== GL_UNSIGNED_INT
) {
6876 *iter2
++ = widget
.ui
;
6878 *iter2
++ = widget
.ui
>> 16;
6882 *iter2
++ = widget
.i
;
6884 *iter2
++ = widget
.i
>> 15;
6896 iter
= rowStart
; /* for assertion purposes */
6902 /* iterators should be one byte past end */
6903 if (!isTypePackedPixel(type
)) {
6904 assert(iter2
== &newImage
[width
*height
*depth
*components
]);
6907 assert(iter2
== &newImage
[width
*height
*depth
*
6908 elements_per_group(format
,0)]);
6910 assert( iter
== &((const GLubyte
*)userImage
)[rowSize
*height
*depth
+
6911 psm
->unpack_skip_rows
* rowSize
+
6912 psm
->unpack_skip_pixels
* groupSize
+
6914 psm
->unpack_skip_images
* imageSize
] );
6915 } /* fillImage3D () */
6917 static void scaleInternal3D(GLint components
,
6918 GLint widthIn
, GLint heightIn
, GLint depthIn
,
6919 const GLushort
*dataIn
,
6920 GLint widthOut
, GLint heightOut
, GLint depthOut
,
6923 float x
, lowx
, highx
, convx
, halfconvx
;
6924 float y
, lowy
, highy
, convy
, halfconvy
;
6925 float z
, lowz
, highz
, convz
, halfconvz
;
6926 float xpercent
,ypercent
,zpercent
;
6928 /* Max components in a format is 4, so... */
6931 int i
,j
,d
,k
,zint
,yint
,xint
,xindex
,yindex
,zindex
;
6934 convz
= (float) depthIn
/depthOut
;
6935 convy
= (float) heightIn
/heightOut
;
6936 convx
= (float) widthIn
/widthOut
;
6937 halfconvx
= convx
/2;
6938 halfconvy
= convy
/2;
6939 halfconvz
= convz
/2;
6940 for (d
= 0; d
< depthOut
; d
++) {
6941 z
= convz
* (d
+0.5);
6942 if (depthIn
> depthOut
) {
6943 highz
= z
+ halfconvz
;
6944 lowz
= z
- halfconvz
;
6949 for (i
= 0; i
< heightOut
; i
++) {
6950 y
= convy
* (i
+0.5);
6951 if (heightIn
> heightOut
) {
6952 highy
= y
+ halfconvy
;
6953 lowy
= y
- halfconvy
;
6958 for (j
= 0; j
< widthOut
; j
++) {
6959 x
= convx
* (j
+0.5);
6960 if (widthIn
> widthOut
) {
6961 highx
= x
+ halfconvx
;
6962 lowx
= x
- halfconvx
;
6969 ** Ok, now apply box filter to box that goes from (lowx, lowy,
6970 ** lowz) to (highx, highy, highz) on input data into this pixel
6973 totals
[0] = totals
[1] = totals
[2] = totals
[3] = 0.0;
6979 zindex
= (zint
+ depthIn
) % depthIn
;
6980 if (highz
< zint
+1) {
6981 zpercent
= highz
- z
;
6983 zpercent
= zint
+1 - z
;
6989 yindex
= (yint
+ heightIn
) % heightIn
;
6990 if (highy
< yint
+1) {
6991 ypercent
= highy
- y
;
6993 ypercent
= yint
+1 - y
;
7000 xindex
= (xint
+ widthIn
) % widthIn
;
7001 if (highx
< xint
+1) {
7002 xpercent
= highx
- x
;
7004 xpercent
= xint
+1 - x
;
7007 percent
= xpercent
* ypercent
* zpercent
;
7010 temp
= (xindex
+ (yindex
*widthIn
) +
7011 (zindex
*widthIn
*heightIn
)) * components
;
7012 for (k
= 0; k
< components
; k
++) {
7013 assert(0 <= (temp
+k
) &&
7015 (widthIn
*heightIn
*depthIn
*components
));
7016 totals
[k
] += dataIn
[temp
+ k
] * percent
;
7031 temp
= (j
+ (i
* widthOut
) +
7032 (d
*widthOut
*heightOut
)) * components
;
7033 for (k
= 0; k
< components
; k
++) {
7034 /* totals[] should be rounded in the case of enlarging an
7035 * RGB ramp when the type is 332 or 4444
7037 assert(0 <= (temp
+k
) &&
7038 (temp
+k
) < (widthOut
*heightOut
*depthOut
*components
));
7039 dataOut
[temp
+ k
] = (totals
[k
]+0.5)/volume
;
7044 } /* scaleInternal3D() */
7046 static void emptyImage3D(const PixelStorageModes
*psm
,
7047 GLint width
, GLint height
, GLint depth
,
7048 GLenum format
, GLenum type
, GLboolean indexFormat
,
7049 const GLushort
*oldImage
, void *userImage
)
7058 GLubyte
*start
, *rowStart
, *iter
;
7059 int elementsPerLine
;
7060 const GLushort
*iter2
;
7065 myswapBytes
= psm
->pack_swap_bytes
;
7066 components
= elements_per_group(format
,type
);
7067 if (psm
->pack_row_length
> 0) {
7068 groupsPerLine
= psm
->pack_row_length
;
7071 groupsPerLine
= width
;
7074 elementSize
= bytes_per_element(type
);
7075 groupSize
= elementSize
* components
;
7076 if (elementSize
== 1) myswapBytes
= 0;
7079 if (psm
->pack_image_height
> 0) {
7080 rowsPerImage
= psm
->pack_image_height
;
7083 rowsPerImage
= height
;
7088 rowSize
= groupsPerLine
* groupSize
;
7089 padding
= rowSize
% psm
->pack_alignment
;
7091 rowSize
+= psm
->pack_alignment
- padding
;
7094 imageSize
= rowsPerImage
* rowSize
; /* 3dstuff */
7096 start
= (GLubyte
*)userImage
+ psm
->pack_skip_rows
* rowSize
+
7097 psm
->pack_skip_pixels
* groupSize
+
7099 psm
->pack_skip_images
* imageSize
;
7100 elementsPerLine
= width
* components
;
7103 for (dd
= 0; dd
< depth
; dd
++) {
7106 for (ii
= 0; ii
< height
; ii
++) {
7109 for (jj
= 0; jj
< elementsPerLine
; jj
++) {
7111 float shoveComponents
[4];
7114 case GL_UNSIGNED_BYTE
:
7118 *iter
= *iter2
++ >> 8;
7123 *((GLbyte
*) iter
) = *iter2
++;
7125 *((GLbyte
*) iter
) = *iter2
++ >> 9;
7128 case GL_UNSIGNED_BYTE_3_3_2
:
7129 for (k
= 0; k
< 3; k
++) {
7130 shoveComponents
[k
]= *iter2
++ / 65535.0;
7132 shove332(shoveComponents
,0,(void *)iter
);
7134 case GL_UNSIGNED_BYTE_2_3_3_REV
:
7135 for (k
= 0; k
< 3; k
++) {
7136 shoveComponents
[k
]= *iter2
++ / 65535.0;
7138 shove233rev(shoveComponents
,0,(void *)iter
);
7140 case GL_UNSIGNED_SHORT_5_6_5
:
7141 for (k
= 0; k
< 3; k
++) {
7142 shoveComponents
[k
]= *iter2
++ / 65535.0;
7144 shove565(shoveComponents
,0,(void *)&widget
.us
[0]);
7146 iter
[0] = widget
.ub
[1];
7147 iter
[1] = widget
.ub
[0];
7150 *(GLushort
*)iter
= widget
.us
[0];
7153 case GL_UNSIGNED_SHORT_5_6_5_REV
:
7154 for (k
= 0; k
< 3; k
++) {
7155 shoveComponents
[k
]= *iter2
++ / 65535.0;
7157 shove565rev(shoveComponents
,0,(void *)&widget
.us
[0]);
7159 iter
[0] = widget
.ub
[1];
7160 iter
[1] = widget
.ub
[0];
7163 *(GLushort
*)iter
= widget
.us
[0];
7166 case GL_UNSIGNED_SHORT_4_4_4_4
:
7167 for (k
= 0; k
< 4; k
++) {
7168 shoveComponents
[k
]= *iter2
++ / 65535.0;
7170 shove4444(shoveComponents
,0,(void *)&widget
.us
[0]);
7172 iter
[0] = widget
.ub
[1];
7173 iter
[1] = widget
.ub
[0];
7175 *(GLushort
*)iter
= widget
.us
[0];
7178 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
7179 for (k
= 0; k
< 4; k
++) {
7180 shoveComponents
[k
]= *iter2
++ / 65535.0;
7182 shove4444rev(shoveComponents
,0,(void *)&widget
.us
[0]);
7184 iter
[0] = widget
.ub
[1];
7185 iter
[1] = widget
.ub
[0];
7187 *(GLushort
*)iter
= widget
.us
[0];
7190 case GL_UNSIGNED_SHORT_5_5_5_1
:
7191 for (k
= 0; k
< 4; k
++) {
7192 shoveComponents
[k
]= *iter2
++ / 65535.0;
7194 shove5551(shoveComponents
,0,(void *)&widget
.us
[0]);
7196 iter
[0] = widget
.ub
[1];
7197 iter
[1] = widget
.ub
[0];
7199 *(GLushort
*)iter
= widget
.us
[0];
7202 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
7203 for (k
= 0; k
< 4; k
++) {
7204 shoveComponents
[k
]= *iter2
++ / 65535.0;
7206 shove1555rev(shoveComponents
,0,(void *)&widget
.us
[0]);
7208 iter
[0] = widget
.ub
[1];
7209 iter
[1] = widget
.ub
[0];
7211 *(GLushort
*)iter
= widget
.us
[0];
7214 case GL_UNSIGNED_SHORT
:
7216 if (type
== GL_SHORT
) {
7218 widget
.s
[0] = *iter2
++;
7220 widget
.s
[0] = *iter2
++ >> 1;
7223 widget
.us
[0] = *iter2
++;
7226 iter
[0] = widget
.ub
[1];
7227 iter
[1] = widget
.ub
[0];
7229 iter
[0] = widget
.ub
[0];
7230 iter
[1] = widget
.ub
[1];
7233 case GL_UNSIGNED_INT_8_8_8_8
:
7234 for (k
= 0; k
< 4; k
++) {
7235 shoveComponents
[k
]= *iter2
++ / 65535.0;
7237 shove8888(shoveComponents
,0,(void *)&widget
.ui
);
7239 iter
[3] = widget
.ub
[0];
7240 iter
[2] = widget
.ub
[1];
7241 iter
[1] = widget
.ub
[2];
7242 iter
[0] = widget
.ub
[3];
7244 *(GLuint
*)iter
= widget
.ui
;
7247 case GL_UNSIGNED_INT_8_8_8_8_REV
:
7248 for (k
= 0; k
< 4; k
++) {
7249 shoveComponents
[k
]= *iter2
++ / 65535.0;
7251 shove8888rev(shoveComponents
,0,(void *)&widget
.ui
);
7253 iter
[3] = widget
.ub
[0];
7254 iter
[2] = widget
.ub
[1];
7255 iter
[1] = widget
.ub
[2];
7256 iter
[0] = widget
.ub
[3];
7258 *(GLuint
*)iter
= widget
.ui
;
7261 case GL_UNSIGNED_INT_10_10_10_2
:
7262 for (k
= 0; k
< 4; k
++) {
7263 shoveComponents
[k
]= *iter2
++ / 65535.0;
7265 shove1010102(shoveComponents
,0,(void *)&widget
.ui
);
7267 iter
[3] = widget
.ub
[0];
7268 iter
[2] = widget
.ub
[1];
7269 iter
[1] = widget
.ub
[2];
7270 iter
[0] = widget
.ub
[3];
7272 *(GLuint
*)iter
= widget
.ui
;
7275 case GL_UNSIGNED_INT_2_10_10_10_REV
:
7276 for (k
= 0; k
< 4; k
++) {
7277 shoveComponents
[k
]= *iter2
++ / 65535.0;
7279 shove2101010rev(shoveComponents
,0,(void *)&widget
.ui
);
7281 iter
[3] = widget
.ub
[0];
7282 iter
[2] = widget
.ub
[1];
7283 iter
[1] = widget
.ub
[2];
7284 iter
[0] = widget
.ub
[3];
7286 *(GLuint
*)iter
= widget
.ui
;
7290 case GL_UNSIGNED_INT
:
7292 if (type
== GL_FLOAT
) {
7294 widget
.f
= *iter2
++;
7296 widget
.f
= *iter2
++ / (float) 65535.0;
7298 } else if (type
== GL_UNSIGNED_INT
) {
7300 widget
.ui
= *iter2
++;
7302 widget
.ui
= (unsigned int) *iter2
++ * 65537;
7306 widget
.i
= *iter2
++;
7308 widget
.i
= ((unsigned int) *iter2
++ * 65537)/2;
7312 iter
[3] = widget
.ub
[0];
7313 iter
[2] = widget
.ub
[1];
7314 iter
[1] = widget
.ub
[2];
7315 iter
[0] = widget
.ub
[3];
7317 iter
[0] = widget
.ub
[0];
7318 iter
[1] = widget
.ub
[1];
7319 iter
[2] = widget
.ub
[2];
7320 iter
[3] = widget
.ub
[3];
7336 /* iterators should be one byte past end */
7337 if (!isTypePackedPixel(type
)) {
7338 assert(iter2
== &oldImage
[width
*height
*depth
*components
]);
7341 assert(iter2
== &oldImage
[width
*height
*depth
*
7342 elements_per_group(format
,0)]);
7344 assert( iter
== &((GLubyte
*)userImage
)[rowSize
*height
*depth
+
7345 psm
->unpack_skip_rows
* rowSize
+
7346 psm
->unpack_skip_pixels
* groupSize
+
7348 psm
->unpack_skip_images
* imageSize
] );
7349 } /* emptyImage3D() */
7352 int gluScaleImage3D(GLenum format
,
7353 GLint widthIn
, GLint heightIn
, GLint depthIn
,
7354 GLenum typeIn
, const void *dataIn
,
7355 GLint widthOut
, GLint heightOut
, GLint depthOut
,
7356 GLenum typeOut
, void *dataOut
)
7359 GLushort
*beforeImage
, *afterImage
;
7360 PixelStorageModes psm
;
7362 if (widthIn
== 0 || heightIn
== 0 || depthIn
== 0 ||
7363 widthOut
== 0 || heightOut
== 0 || depthOut
== 0) {
7367 if (widthIn
< 0 || heightIn
< 0 || depthIn
< 0 ||
7368 widthOut
< 0 || heightOut
< 0 || depthOut
< 0) {
7369 return GLU_INVALID_VALUE
;
7372 if (!legalFormat(format
) || !legalType(typeIn
) || !legalType(typeOut
) ||
7373 typeIn
== GL_BITMAP
|| typeOut
== GL_BITMAP
) {
7374 return GLU_INVALID_ENUM
;
7376 if (!isLegalFormatForPackedPixelType(format
, typeIn
)) {
7377 return GLU_INVALID_OPERATION
;
7379 if (!isLegalFormatForPackedPixelType(format
, typeOut
)) {
7380 return GLU_INVALID_OPERATION
;
7383 beforeImage
= malloc(imageSize3D(widthIn
, heightIn
, depthIn
, format
,
7384 GL_UNSIGNED_SHORT
));
7385 afterImage
= malloc(imageSize3D(widthOut
, heightOut
, depthOut
, format
,
7386 GL_UNSIGNED_SHORT
));
7387 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() */