2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * 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 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 * \file mipmap.c mipmap generation and teximage resizing functions.
38 #include "../../gallium/auxiliary/util/u_format_rgb9e5.h"
39 #include "../../gallium/auxiliary/util/u_format_r11g11b10f.h"
44 bytes_per_pixel(GLenum datatype
, GLuint comps
)
48 if (datatype
== GL_UNSIGNED_INT_8_24_REV_MESA
||
49 datatype
== GL_UNSIGNED_INT_24_8_MESA
)
52 b
= _mesa_sizeof_packed_type(datatype
);
55 if (_mesa_type_is_packed(datatype
))
63 * \name Support macros for do_row and do_row_3d
65 * The macro madness is here for two reasons. First, it compacts the code
66 * slightly. Second, it makes it much easier to adjust the specifics of the
67 * filter to tune the rounding characteristics.
70 #define DECLARE_ROW_POINTERS(t, e) \
71 const t(*rowA)[e] = (const t(*)[e]) srcRowA; \
72 const t(*rowB)[e] = (const t(*)[e]) srcRowB; \
73 const t(*rowC)[e] = (const t(*)[e]) srcRowC; \
74 const t(*rowD)[e] = (const t(*)[e]) srcRowD; \
75 t(*dst)[e] = (t(*)[e]) dstRow
77 #define DECLARE_ROW_POINTERS0(t) \
78 const t *rowA = (const t *) srcRowA; \
79 const t *rowB = (const t *) srcRowB; \
80 const t *rowC = (const t *) srcRowC; \
81 const t *rowD = (const t *) srcRowD; \
84 #define FILTER_SUM_3D(Aj, Ak, Bj, Bk, Cj, Ck, Dj, Dk) \
85 ((unsigned) Aj + (unsigned) Ak \
86 + (unsigned) Bj + (unsigned) Bk \
87 + (unsigned) Cj + (unsigned) Ck \
88 + (unsigned) Dj + (unsigned) Dk \
91 #define FILTER_3D(e) \
93 dst[i][e] = FILTER_SUM_3D(rowA[j][e], rowA[k][e], \
94 rowB[j][e], rowB[k][e], \
95 rowC[j][e], rowC[k][e], \
96 rowD[j][e], rowD[k][e]); \
99 #define FILTER_SUM_3D_SIGNED(Aj, Ak, Bj, Bk, Cj, Ck, Dj, Dk) \
106 #define FILTER_3D_SIGNED(e) \
108 dst[i][e] = FILTER_SUM_3D_SIGNED(rowA[j][e], rowA[k][e], \
109 rowB[j][e], rowB[k][e], \
110 rowC[j][e], rowC[k][e], \
111 rowD[j][e], rowD[k][e]); \
114 #define FILTER_F_3D(e) \
116 dst[i][e] = (rowA[j][e] + rowA[k][e] \
117 + rowB[j][e] + rowB[k][e] \
118 + rowC[j][e] + rowC[k][e] \
119 + rowD[j][e] + rowD[k][e]) * 0.125F; \
122 #define FILTER_HF_3D(e) \
124 const GLfloat aj = _mesa_half_to_float(rowA[j][e]); \
125 const GLfloat ak = _mesa_half_to_float(rowA[k][e]); \
126 const GLfloat bj = _mesa_half_to_float(rowB[j][e]); \
127 const GLfloat bk = _mesa_half_to_float(rowB[k][e]); \
128 const GLfloat cj = _mesa_half_to_float(rowC[j][e]); \
129 const GLfloat ck = _mesa_half_to_float(rowC[k][e]); \
130 const GLfloat dj = _mesa_half_to_float(rowD[j][e]); \
131 const GLfloat dk = _mesa_half_to_float(rowD[k][e]); \
132 dst[i][e] = _mesa_float_to_half((aj + ak + bj + bk + cj + ck + dj + dk) \
139 * Average together two rows of a source image to produce a single new
140 * row in the dest image. It's legal for the two source rows to point
141 * to the same data. The source width must be equal to either the
142 * dest width or two times the dest width.
143 * \param datatype GL_UNSIGNED_BYTE, GL_UNSIGNED_SHORT, GL_FLOAT, etc.
144 * \param comps number of components per pixel (1..4)
147 do_row(GLenum datatype
, GLuint comps
, GLint srcWidth
,
148 const GLvoid
*srcRowA
, const GLvoid
*srcRowB
,
149 GLint dstWidth
, GLvoid
*dstRow
)
151 const GLuint k0
= (srcWidth
== dstWidth
) ? 0 : 1;
152 const GLuint colStride
= (srcWidth
== dstWidth
) ? 1 : 2;
157 /* This assertion is no longer valid with non-power-of-2 textures
158 assert(srcWidth == dstWidth || srcWidth == 2 * dstWidth);
161 if (datatype
== GL_UNSIGNED_BYTE
&& comps
== 4) {
163 const GLubyte(*rowA
)[4] = (const GLubyte(*)[4]) srcRowA
;
164 const GLubyte(*rowB
)[4] = (const GLubyte(*)[4]) srcRowB
;
165 GLubyte(*dst
)[4] = (GLubyte(*)[4]) dstRow
;
166 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
167 i
++, j
+= colStride
, k
+= colStride
) {
168 dst
[i
][0] = (rowA
[j
][0] + rowA
[k
][0] + rowB
[j
][0] + rowB
[k
][0]) / 4;
169 dst
[i
][1] = (rowA
[j
][1] + rowA
[k
][1] + rowB
[j
][1] + rowB
[k
][1]) / 4;
170 dst
[i
][2] = (rowA
[j
][2] + rowA
[k
][2] + rowB
[j
][2] + rowB
[k
][2]) / 4;
171 dst
[i
][3] = (rowA
[j
][3] + rowA
[k
][3] + rowB
[j
][3] + rowB
[k
][3]) / 4;
174 else if (datatype
== GL_UNSIGNED_BYTE
&& comps
== 3) {
176 const GLubyte(*rowA
)[3] = (const GLubyte(*)[3]) srcRowA
;
177 const GLubyte(*rowB
)[3] = (const GLubyte(*)[3]) srcRowB
;
178 GLubyte(*dst
)[3] = (GLubyte(*)[3]) dstRow
;
179 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
180 i
++, j
+= colStride
, k
+= colStride
) {
181 dst
[i
][0] = (rowA
[j
][0] + rowA
[k
][0] + rowB
[j
][0] + rowB
[k
][0]) / 4;
182 dst
[i
][1] = (rowA
[j
][1] + rowA
[k
][1] + rowB
[j
][1] + rowB
[k
][1]) / 4;
183 dst
[i
][2] = (rowA
[j
][2] + rowA
[k
][2] + rowB
[j
][2] + rowB
[k
][2]) / 4;
186 else if (datatype
== GL_UNSIGNED_BYTE
&& comps
== 2) {
188 const GLubyte(*rowA
)[2] = (const GLubyte(*)[2]) srcRowA
;
189 const GLubyte(*rowB
)[2] = (const GLubyte(*)[2]) srcRowB
;
190 GLubyte(*dst
)[2] = (GLubyte(*)[2]) dstRow
;
191 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
192 i
++, j
+= colStride
, k
+= colStride
) {
193 dst
[i
][0] = (rowA
[j
][0] + rowA
[k
][0] + rowB
[j
][0] + rowB
[k
][0]) >> 2;
194 dst
[i
][1] = (rowA
[j
][1] + rowA
[k
][1] + rowB
[j
][1] + rowB
[k
][1]) >> 2;
197 else if (datatype
== GL_UNSIGNED_BYTE
&& comps
== 1) {
199 const GLubyte
*rowA
= (const GLubyte
*) srcRowA
;
200 const GLubyte
*rowB
= (const GLubyte
*) srcRowB
;
201 GLubyte
*dst
= (GLubyte
*) dstRow
;
202 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
203 i
++, j
+= colStride
, k
+= colStride
) {
204 dst
[i
] = (rowA
[j
] + rowA
[k
] + rowB
[j
] + rowB
[k
]) >> 2;
208 else if (datatype
== GL_BYTE
&& comps
== 4) {
210 const GLbyte(*rowA
)[4] = (const GLbyte(*)[4]) srcRowA
;
211 const GLbyte(*rowB
)[4] = (const GLbyte(*)[4]) srcRowB
;
212 GLbyte(*dst
)[4] = (GLbyte(*)[4]) dstRow
;
213 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
214 i
++, j
+= colStride
, k
+= colStride
) {
215 dst
[i
][0] = (rowA
[j
][0] + rowA
[k
][0] + rowB
[j
][0] + rowB
[k
][0]) / 4;
216 dst
[i
][1] = (rowA
[j
][1] + rowA
[k
][1] + rowB
[j
][1] + rowB
[k
][1]) / 4;
217 dst
[i
][2] = (rowA
[j
][2] + rowA
[k
][2] + rowB
[j
][2] + rowB
[k
][2]) / 4;
218 dst
[i
][3] = (rowA
[j
][3] + rowA
[k
][3] + rowB
[j
][3] + rowB
[k
][3]) / 4;
221 else if (datatype
== GL_BYTE
&& comps
== 3) {
223 const GLbyte(*rowA
)[3] = (const GLbyte(*)[3]) srcRowA
;
224 const GLbyte(*rowB
)[3] = (const GLbyte(*)[3]) srcRowB
;
225 GLbyte(*dst
)[3] = (GLbyte(*)[3]) dstRow
;
226 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
227 i
++, j
+= colStride
, k
+= colStride
) {
228 dst
[i
][0] = (rowA
[j
][0] + rowA
[k
][0] + rowB
[j
][0] + rowB
[k
][0]) / 4;
229 dst
[i
][1] = (rowA
[j
][1] + rowA
[k
][1] + rowB
[j
][1] + rowB
[k
][1]) / 4;
230 dst
[i
][2] = (rowA
[j
][2] + rowA
[k
][2] + rowB
[j
][2] + rowB
[k
][2]) / 4;
233 else if (datatype
== GL_BYTE
&& comps
== 2) {
235 const GLbyte(*rowA
)[2] = (const GLbyte(*)[2]) srcRowA
;
236 const GLbyte(*rowB
)[2] = (const GLbyte(*)[2]) srcRowB
;
237 GLbyte(*dst
)[2] = (GLbyte(*)[2]) dstRow
;
238 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
239 i
++, j
+= colStride
, k
+= colStride
) {
240 dst
[i
][0] = (rowA
[j
][0] + rowA
[k
][0] + rowB
[j
][0] + rowB
[k
][0]) / 4;
241 dst
[i
][1] = (rowA
[j
][1] + rowA
[k
][1] + rowB
[j
][1] + rowB
[k
][1]) / 4;
244 else if (datatype
== GL_BYTE
&& comps
== 1) {
246 const GLbyte
*rowA
= (const GLbyte
*) srcRowA
;
247 const GLbyte
*rowB
= (const GLbyte
*) srcRowB
;
248 GLbyte
*dst
= (GLbyte
*) dstRow
;
249 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
250 i
++, j
+= colStride
, k
+= colStride
) {
251 dst
[i
] = (rowA
[j
] + rowA
[k
] + rowB
[j
] + rowB
[k
]) / 4;
255 else if (datatype
== GL_UNSIGNED_SHORT
&& comps
== 4) {
257 const GLushort(*rowA
)[4] = (const GLushort(*)[4]) srcRowA
;
258 const GLushort(*rowB
)[4] = (const GLushort(*)[4]) srcRowB
;
259 GLushort(*dst
)[4] = (GLushort(*)[4]) dstRow
;
260 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
261 i
++, j
+= colStride
, k
+= colStride
) {
262 dst
[i
][0] = (rowA
[j
][0] + rowA
[k
][0] + rowB
[j
][0] + rowB
[k
][0]) / 4;
263 dst
[i
][1] = (rowA
[j
][1] + rowA
[k
][1] + rowB
[j
][1] + rowB
[k
][1]) / 4;
264 dst
[i
][2] = (rowA
[j
][2] + rowA
[k
][2] + rowB
[j
][2] + rowB
[k
][2]) / 4;
265 dst
[i
][3] = (rowA
[j
][3] + rowA
[k
][3] + rowB
[j
][3] + rowB
[k
][3]) / 4;
268 else if (datatype
== GL_UNSIGNED_SHORT
&& comps
== 3) {
270 const GLushort(*rowA
)[3] = (const GLushort(*)[3]) srcRowA
;
271 const GLushort(*rowB
)[3] = (const GLushort(*)[3]) srcRowB
;
272 GLushort(*dst
)[3] = (GLushort(*)[3]) dstRow
;
273 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
274 i
++, j
+= colStride
, k
+= colStride
) {
275 dst
[i
][0] = (rowA
[j
][0] + rowA
[k
][0] + rowB
[j
][0] + rowB
[k
][0]) / 4;
276 dst
[i
][1] = (rowA
[j
][1] + rowA
[k
][1] + rowB
[j
][1] + rowB
[k
][1]) / 4;
277 dst
[i
][2] = (rowA
[j
][2] + rowA
[k
][2] + rowB
[j
][2] + rowB
[k
][2]) / 4;
280 else if (datatype
== GL_UNSIGNED_SHORT
&& comps
== 2) {
282 const GLushort(*rowA
)[2] = (const GLushort(*)[2]) srcRowA
;
283 const GLushort(*rowB
)[2] = (const GLushort(*)[2]) srcRowB
;
284 GLushort(*dst
)[2] = (GLushort(*)[2]) dstRow
;
285 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
286 i
++, j
+= colStride
, k
+= colStride
) {
287 dst
[i
][0] = (rowA
[j
][0] + rowA
[k
][0] + rowB
[j
][0] + rowB
[k
][0]) / 4;
288 dst
[i
][1] = (rowA
[j
][1] + rowA
[k
][1] + rowB
[j
][1] + rowB
[k
][1]) / 4;
291 else if (datatype
== GL_UNSIGNED_SHORT
&& comps
== 1) {
293 const GLushort
*rowA
= (const GLushort
*) srcRowA
;
294 const GLushort
*rowB
= (const GLushort
*) srcRowB
;
295 GLushort
*dst
= (GLushort
*) dstRow
;
296 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
297 i
++, j
+= colStride
, k
+= colStride
) {
298 dst
[i
] = (rowA
[j
] + rowA
[k
] + rowB
[j
] + rowB
[k
]) / 4;
302 else if (datatype
== GL_SHORT
&& comps
== 4) {
304 const GLshort(*rowA
)[4] = (const GLshort(*)[4]) srcRowA
;
305 const GLshort(*rowB
)[4] = (const GLshort(*)[4]) srcRowB
;
306 GLshort(*dst
)[4] = (GLshort(*)[4]) dstRow
;
307 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
308 i
++, j
+= colStride
, k
+= colStride
) {
309 dst
[i
][0] = (rowA
[j
][0] + rowA
[k
][0] + rowB
[j
][0] + rowB
[k
][0]) / 4;
310 dst
[i
][1] = (rowA
[j
][1] + rowA
[k
][1] + rowB
[j
][1] + rowB
[k
][1]) / 4;
311 dst
[i
][2] = (rowA
[j
][2] + rowA
[k
][2] + rowB
[j
][2] + rowB
[k
][2]) / 4;
312 dst
[i
][3] = (rowA
[j
][3] + rowA
[k
][3] + rowB
[j
][3] + rowB
[k
][3]) / 4;
315 else if (datatype
== GL_SHORT
&& comps
== 3) {
317 const GLshort(*rowA
)[3] = (const GLshort(*)[3]) srcRowA
;
318 const GLshort(*rowB
)[3] = (const GLshort(*)[3]) srcRowB
;
319 GLshort(*dst
)[3] = (GLshort(*)[3]) dstRow
;
320 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
321 i
++, j
+= colStride
, k
+= colStride
) {
322 dst
[i
][0] = (rowA
[j
][0] + rowA
[k
][0] + rowB
[j
][0] + rowB
[k
][0]) / 4;
323 dst
[i
][1] = (rowA
[j
][1] + rowA
[k
][1] + rowB
[j
][1] + rowB
[k
][1]) / 4;
324 dst
[i
][2] = (rowA
[j
][2] + rowA
[k
][2] + rowB
[j
][2] + rowB
[k
][2]) / 4;
327 else if (datatype
== GL_SHORT
&& comps
== 2) {
329 const GLshort(*rowA
)[2] = (const GLshort(*)[2]) srcRowA
;
330 const GLshort(*rowB
)[2] = (const GLshort(*)[2]) srcRowB
;
331 GLshort(*dst
)[2] = (GLshort(*)[2]) dstRow
;
332 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
333 i
++, j
+= colStride
, k
+= colStride
) {
334 dst
[i
][0] = (rowA
[j
][0] + rowA
[k
][0] + rowB
[j
][0] + rowB
[k
][0]) / 4;
335 dst
[i
][1] = (rowA
[j
][1] + rowA
[k
][1] + rowB
[j
][1] + rowB
[k
][1]) / 4;
338 else if (datatype
== GL_SHORT
&& comps
== 1) {
340 const GLshort
*rowA
= (const GLshort
*) srcRowA
;
341 const GLshort
*rowB
= (const GLshort
*) srcRowB
;
342 GLshort
*dst
= (GLshort
*) dstRow
;
343 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
344 i
++, j
+= colStride
, k
+= colStride
) {
345 dst
[i
] = (rowA
[j
] + rowA
[k
] + rowB
[j
] + rowB
[k
]) / 4;
349 else if (datatype
== GL_FLOAT
&& comps
== 4) {
351 const GLfloat(*rowA
)[4] = (const GLfloat(*)[4]) srcRowA
;
352 const GLfloat(*rowB
)[4] = (const GLfloat(*)[4]) srcRowB
;
353 GLfloat(*dst
)[4] = (GLfloat(*)[4]) dstRow
;
354 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
355 i
++, j
+= colStride
, k
+= colStride
) {
356 dst
[i
][0] = (rowA
[j
][0] + rowA
[k
][0] +
357 rowB
[j
][0] + rowB
[k
][0]) * 0.25F
;
358 dst
[i
][1] = (rowA
[j
][1] + rowA
[k
][1] +
359 rowB
[j
][1] + rowB
[k
][1]) * 0.25F
;
360 dst
[i
][2] = (rowA
[j
][2] + rowA
[k
][2] +
361 rowB
[j
][2] + rowB
[k
][2]) * 0.25F
;
362 dst
[i
][3] = (rowA
[j
][3] + rowA
[k
][3] +
363 rowB
[j
][3] + rowB
[k
][3]) * 0.25F
;
366 else if (datatype
== GL_FLOAT
&& comps
== 3) {
368 const GLfloat(*rowA
)[3] = (const GLfloat(*)[3]) srcRowA
;
369 const GLfloat(*rowB
)[3] = (const GLfloat(*)[3]) srcRowB
;
370 GLfloat(*dst
)[3] = (GLfloat(*)[3]) dstRow
;
371 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
372 i
++, j
+= colStride
, k
+= colStride
) {
373 dst
[i
][0] = (rowA
[j
][0] + rowA
[k
][0] +
374 rowB
[j
][0] + rowB
[k
][0]) * 0.25F
;
375 dst
[i
][1] = (rowA
[j
][1] + rowA
[k
][1] +
376 rowB
[j
][1] + rowB
[k
][1]) * 0.25F
;
377 dst
[i
][2] = (rowA
[j
][2] + rowA
[k
][2] +
378 rowB
[j
][2] + rowB
[k
][2]) * 0.25F
;
381 else if (datatype
== GL_FLOAT
&& comps
== 2) {
383 const GLfloat(*rowA
)[2] = (const GLfloat(*)[2]) srcRowA
;
384 const GLfloat(*rowB
)[2] = (const GLfloat(*)[2]) srcRowB
;
385 GLfloat(*dst
)[2] = (GLfloat(*)[2]) dstRow
;
386 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
387 i
++, j
+= colStride
, k
+= colStride
) {
388 dst
[i
][0] = (rowA
[j
][0] + rowA
[k
][0] +
389 rowB
[j
][0] + rowB
[k
][0]) * 0.25F
;
390 dst
[i
][1] = (rowA
[j
][1] + rowA
[k
][1] +
391 rowB
[j
][1] + rowB
[k
][1]) * 0.25F
;
394 else if (datatype
== GL_FLOAT
&& comps
== 1) {
396 const GLfloat
*rowA
= (const GLfloat
*) srcRowA
;
397 const GLfloat
*rowB
= (const GLfloat
*) srcRowB
;
398 GLfloat
*dst
= (GLfloat
*) dstRow
;
399 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
400 i
++, j
+= colStride
, k
+= colStride
) {
401 dst
[i
] = (rowA
[j
] + rowA
[k
] + rowB
[j
] + rowB
[k
]) * 0.25F
;
405 else if (datatype
== GL_HALF_FLOAT_ARB
&& comps
== 4) {
406 GLuint i
, j
, k
, comp
;
407 const GLhalfARB(*rowA
)[4] = (const GLhalfARB(*)[4]) srcRowA
;
408 const GLhalfARB(*rowB
)[4] = (const GLhalfARB(*)[4]) srcRowB
;
409 GLhalfARB(*dst
)[4] = (GLhalfARB(*)[4]) dstRow
;
410 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
411 i
++, j
+= colStride
, k
+= colStride
) {
412 for (comp
= 0; comp
< 4; comp
++) {
413 GLfloat aj
, ak
, bj
, bk
;
414 aj
= _mesa_half_to_float(rowA
[j
][comp
]);
415 ak
= _mesa_half_to_float(rowA
[k
][comp
]);
416 bj
= _mesa_half_to_float(rowB
[j
][comp
]);
417 bk
= _mesa_half_to_float(rowB
[k
][comp
]);
418 dst
[i
][comp
] = _mesa_float_to_half((aj
+ ak
+ bj
+ bk
) * 0.25F
);
422 else if (datatype
== GL_HALF_FLOAT_ARB
&& comps
== 3) {
423 GLuint i
, j
, k
, comp
;
424 const GLhalfARB(*rowA
)[3] = (const GLhalfARB(*)[3]) srcRowA
;
425 const GLhalfARB(*rowB
)[3] = (const GLhalfARB(*)[3]) srcRowB
;
426 GLhalfARB(*dst
)[3] = (GLhalfARB(*)[3]) dstRow
;
427 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
428 i
++, j
+= colStride
, k
+= colStride
) {
429 for (comp
= 0; comp
< 3; comp
++) {
430 GLfloat aj
, ak
, bj
, bk
;
431 aj
= _mesa_half_to_float(rowA
[j
][comp
]);
432 ak
= _mesa_half_to_float(rowA
[k
][comp
]);
433 bj
= _mesa_half_to_float(rowB
[j
][comp
]);
434 bk
= _mesa_half_to_float(rowB
[k
][comp
]);
435 dst
[i
][comp
] = _mesa_float_to_half((aj
+ ak
+ bj
+ bk
) * 0.25F
);
439 else if (datatype
== GL_HALF_FLOAT_ARB
&& comps
== 2) {
440 GLuint i
, j
, k
, comp
;
441 const GLhalfARB(*rowA
)[2] = (const GLhalfARB(*)[2]) srcRowA
;
442 const GLhalfARB(*rowB
)[2] = (const GLhalfARB(*)[2]) srcRowB
;
443 GLhalfARB(*dst
)[2] = (GLhalfARB(*)[2]) dstRow
;
444 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
445 i
++, j
+= colStride
, k
+= colStride
) {
446 for (comp
= 0; comp
< 2; comp
++) {
447 GLfloat aj
, ak
, bj
, bk
;
448 aj
= _mesa_half_to_float(rowA
[j
][comp
]);
449 ak
= _mesa_half_to_float(rowA
[k
][comp
]);
450 bj
= _mesa_half_to_float(rowB
[j
][comp
]);
451 bk
= _mesa_half_to_float(rowB
[k
][comp
]);
452 dst
[i
][comp
] = _mesa_float_to_half((aj
+ ak
+ bj
+ bk
) * 0.25F
);
456 else if (datatype
== GL_HALF_FLOAT_ARB
&& comps
== 1) {
458 const GLhalfARB
*rowA
= (const GLhalfARB
*) srcRowA
;
459 const GLhalfARB
*rowB
= (const GLhalfARB
*) srcRowB
;
460 GLhalfARB
*dst
= (GLhalfARB
*) dstRow
;
461 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
462 i
++, j
+= colStride
, k
+= colStride
) {
463 GLfloat aj
, ak
, bj
, bk
;
464 aj
= _mesa_half_to_float(rowA
[j
]);
465 ak
= _mesa_half_to_float(rowA
[k
]);
466 bj
= _mesa_half_to_float(rowB
[j
]);
467 bk
= _mesa_half_to_float(rowB
[k
]);
468 dst
[i
] = _mesa_float_to_half((aj
+ ak
+ bj
+ bk
) * 0.25F
);
472 else if (datatype
== GL_UNSIGNED_INT
&& comps
== 1) {
474 const GLuint
*rowA
= (const GLuint
*) srcRowA
;
475 const GLuint
*rowB
= (const GLuint
*) srcRowB
;
476 GLuint
*dst
= (GLuint
*) dstRow
;
477 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
478 i
++, j
+= colStride
, k
+= colStride
) {
479 dst
[i
] = (GLfloat
)(rowA
[j
] / 4 + rowA
[k
] / 4 + rowB
[j
] / 4 + rowB
[k
] / 4);
483 else if (datatype
== GL_UNSIGNED_SHORT_5_6_5
&& comps
== 3) {
485 const GLushort
*rowA
= (const GLushort
*) srcRowA
;
486 const GLushort
*rowB
= (const GLushort
*) srcRowB
;
487 GLushort
*dst
= (GLushort
*) dstRow
;
488 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
489 i
++, j
+= colStride
, k
+= colStride
) {
490 const GLint rowAr0
= rowA
[j
] & 0x1f;
491 const GLint rowAr1
= rowA
[k
] & 0x1f;
492 const GLint rowBr0
= rowB
[j
] & 0x1f;
493 const GLint rowBr1
= rowB
[k
] & 0x1f;
494 const GLint rowAg0
= (rowA
[j
] >> 5) & 0x3f;
495 const GLint rowAg1
= (rowA
[k
] >> 5) & 0x3f;
496 const GLint rowBg0
= (rowB
[j
] >> 5) & 0x3f;
497 const GLint rowBg1
= (rowB
[k
] >> 5) & 0x3f;
498 const GLint rowAb0
= (rowA
[j
] >> 11) & 0x1f;
499 const GLint rowAb1
= (rowA
[k
] >> 11) & 0x1f;
500 const GLint rowBb0
= (rowB
[j
] >> 11) & 0x1f;
501 const GLint rowBb1
= (rowB
[k
] >> 11) & 0x1f;
502 const GLint red
= (rowAr0
+ rowAr1
+ rowBr0
+ rowBr1
) >> 2;
503 const GLint green
= (rowAg0
+ rowAg1
+ rowBg0
+ rowBg1
) >> 2;
504 const GLint blue
= (rowAb0
+ rowAb1
+ rowBb0
+ rowBb1
) >> 2;
505 dst
[i
] = (blue
<< 11) | (green
<< 5) | red
;
508 else if (datatype
== GL_UNSIGNED_SHORT_4_4_4_4
&& comps
== 4) {
510 const GLushort
*rowA
= (const GLushort
*) srcRowA
;
511 const GLushort
*rowB
= (const GLushort
*) srcRowB
;
512 GLushort
*dst
= (GLushort
*) dstRow
;
513 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
514 i
++, j
+= colStride
, k
+= colStride
) {
515 const GLint rowAr0
= rowA
[j
] & 0xf;
516 const GLint rowAr1
= rowA
[k
] & 0xf;
517 const GLint rowBr0
= rowB
[j
] & 0xf;
518 const GLint rowBr1
= rowB
[k
] & 0xf;
519 const GLint rowAg0
= (rowA
[j
] >> 4) & 0xf;
520 const GLint rowAg1
= (rowA
[k
] >> 4) & 0xf;
521 const GLint rowBg0
= (rowB
[j
] >> 4) & 0xf;
522 const GLint rowBg1
= (rowB
[k
] >> 4) & 0xf;
523 const GLint rowAb0
= (rowA
[j
] >> 8) & 0xf;
524 const GLint rowAb1
= (rowA
[k
] >> 8) & 0xf;
525 const GLint rowBb0
= (rowB
[j
] >> 8) & 0xf;
526 const GLint rowBb1
= (rowB
[k
] >> 8) & 0xf;
527 const GLint rowAa0
= (rowA
[j
] >> 12) & 0xf;
528 const GLint rowAa1
= (rowA
[k
] >> 12) & 0xf;
529 const GLint rowBa0
= (rowB
[j
] >> 12) & 0xf;
530 const GLint rowBa1
= (rowB
[k
] >> 12) & 0xf;
531 const GLint red
= (rowAr0
+ rowAr1
+ rowBr0
+ rowBr1
) >> 2;
532 const GLint green
= (rowAg0
+ rowAg1
+ rowBg0
+ rowBg1
) >> 2;
533 const GLint blue
= (rowAb0
+ rowAb1
+ rowBb0
+ rowBb1
) >> 2;
534 const GLint alpha
= (rowAa0
+ rowAa1
+ rowBa0
+ rowBa1
) >> 2;
535 dst
[i
] = (alpha
<< 12) | (blue
<< 8) | (green
<< 4) | red
;
538 else if (datatype
== GL_UNSIGNED_SHORT_1_5_5_5_REV
&& comps
== 4) {
540 const GLushort
*rowA
= (const GLushort
*) srcRowA
;
541 const GLushort
*rowB
= (const GLushort
*) srcRowB
;
542 GLushort
*dst
= (GLushort
*) dstRow
;
543 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
544 i
++, j
+= colStride
, k
+= colStride
) {
545 const GLint rowAr0
= rowA
[j
] & 0x1f;
546 const GLint rowAr1
= rowA
[k
] & 0x1f;
547 const GLint rowBr0
= rowB
[j
] & 0x1f;
548 const GLint rowBr1
= rowB
[k
] & 0x1f;
549 const GLint rowAg0
= (rowA
[j
] >> 5) & 0x1f;
550 const GLint rowAg1
= (rowA
[k
] >> 5) & 0x1f;
551 const GLint rowBg0
= (rowB
[j
] >> 5) & 0x1f;
552 const GLint rowBg1
= (rowB
[k
] >> 5) & 0x1f;
553 const GLint rowAb0
= (rowA
[j
] >> 10) & 0x1f;
554 const GLint rowAb1
= (rowA
[k
] >> 10) & 0x1f;
555 const GLint rowBb0
= (rowB
[j
] >> 10) & 0x1f;
556 const GLint rowBb1
= (rowB
[k
] >> 10) & 0x1f;
557 const GLint rowAa0
= (rowA
[j
] >> 15) & 0x1;
558 const GLint rowAa1
= (rowA
[k
] >> 15) & 0x1;
559 const GLint rowBa0
= (rowB
[j
] >> 15) & 0x1;
560 const GLint rowBa1
= (rowB
[k
] >> 15) & 0x1;
561 const GLint red
= (rowAr0
+ rowAr1
+ rowBr0
+ rowBr1
) >> 2;
562 const GLint green
= (rowAg0
+ rowAg1
+ rowBg0
+ rowBg1
) >> 2;
563 const GLint blue
= (rowAb0
+ rowAb1
+ rowBb0
+ rowBb1
) >> 2;
564 const GLint alpha
= (rowAa0
+ rowAa1
+ rowBa0
+ rowBa1
) >> 2;
565 dst
[i
] = (alpha
<< 15) | (blue
<< 10) | (green
<< 5) | red
;
568 else if (datatype
== GL_UNSIGNED_SHORT_5_5_5_1
&& comps
== 4) {
570 const GLushort
*rowA
= (const GLushort
*) srcRowA
;
571 const GLushort
*rowB
= (const GLushort
*) srcRowB
;
572 GLushort
*dst
= (GLushort
*) dstRow
;
573 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
574 i
++, j
+= colStride
, k
+= colStride
) {
575 const GLint rowAr0
= (rowA
[j
] >> 11) & 0x1f;
576 const GLint rowAr1
= (rowA
[k
] >> 11) & 0x1f;
577 const GLint rowBr0
= (rowB
[j
] >> 11) & 0x1f;
578 const GLint rowBr1
= (rowB
[k
] >> 11) & 0x1f;
579 const GLint rowAg0
= (rowA
[j
] >> 6) & 0x1f;
580 const GLint rowAg1
= (rowA
[k
] >> 6) & 0x1f;
581 const GLint rowBg0
= (rowB
[j
] >> 6) & 0x1f;
582 const GLint rowBg1
= (rowB
[k
] >> 6) & 0x1f;
583 const GLint rowAb0
= (rowA
[j
] >> 1) & 0x1f;
584 const GLint rowAb1
= (rowA
[k
] >> 1) & 0x1f;
585 const GLint rowBb0
= (rowB
[j
] >> 1) & 0x1f;
586 const GLint rowBb1
= (rowB
[k
] >> 1) & 0x1f;
587 const GLint rowAa0
= (rowA
[j
] & 0x1);
588 const GLint rowAa1
= (rowA
[k
] & 0x1);
589 const GLint rowBa0
= (rowB
[j
] & 0x1);
590 const GLint rowBa1
= (rowB
[k
] & 0x1);
591 const GLint red
= (rowAr0
+ rowAr1
+ rowBr0
+ rowBr1
) >> 2;
592 const GLint green
= (rowAg0
+ rowAg1
+ rowBg0
+ rowBg1
) >> 2;
593 const GLint blue
= (rowAb0
+ rowAb1
+ rowBb0
+ rowBb1
) >> 2;
594 const GLint alpha
= (rowAa0
+ rowAa1
+ rowBa0
+ rowBa1
) >> 2;
595 dst
[i
] = (red
<< 11) | (green
<< 6) | (blue
<< 1) | alpha
;
599 else if (datatype
== GL_UNSIGNED_BYTE_3_3_2
&& comps
== 3) {
601 const GLubyte
*rowA
= (const GLubyte
*) srcRowA
;
602 const GLubyte
*rowB
= (const GLubyte
*) srcRowB
;
603 GLubyte
*dst
= (GLubyte
*) dstRow
;
604 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
605 i
++, j
+= colStride
, k
+= colStride
) {
606 const GLint rowAr0
= rowA
[j
] & 0x3;
607 const GLint rowAr1
= rowA
[k
] & 0x3;
608 const GLint rowBr0
= rowB
[j
] & 0x3;
609 const GLint rowBr1
= rowB
[k
] & 0x3;
610 const GLint rowAg0
= (rowA
[j
] >> 2) & 0x7;
611 const GLint rowAg1
= (rowA
[k
] >> 2) & 0x7;
612 const GLint rowBg0
= (rowB
[j
] >> 2) & 0x7;
613 const GLint rowBg1
= (rowB
[k
] >> 2) & 0x7;
614 const GLint rowAb0
= (rowA
[j
] >> 5) & 0x7;
615 const GLint rowAb1
= (rowA
[k
] >> 5) & 0x7;
616 const GLint rowBb0
= (rowB
[j
] >> 5) & 0x7;
617 const GLint rowBb1
= (rowB
[k
] >> 5) & 0x7;
618 const GLint red
= (rowAr0
+ rowAr1
+ rowBr0
+ rowBr1
) >> 2;
619 const GLint green
= (rowAg0
+ rowAg1
+ rowBg0
+ rowBg1
) >> 2;
620 const GLint blue
= (rowAb0
+ rowAb1
+ rowBb0
+ rowBb1
) >> 2;
621 dst
[i
] = (blue
<< 5) | (green
<< 2) | red
;
625 else if (datatype
== MESA_UNSIGNED_BYTE_4_4
&& comps
== 2) {
627 const GLubyte
*rowA
= (const GLubyte
*) srcRowA
;
628 const GLubyte
*rowB
= (const GLubyte
*) srcRowB
;
629 GLubyte
*dst
= (GLubyte
*) dstRow
;
630 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
631 i
++, j
+= colStride
, k
+= colStride
) {
632 const GLint rowAr0
= rowA
[j
] & 0xf;
633 const GLint rowAr1
= rowA
[k
] & 0xf;
634 const GLint rowBr0
= rowB
[j
] & 0xf;
635 const GLint rowBr1
= rowB
[k
] & 0xf;
636 const GLint rowAg0
= (rowA
[j
] >> 4) & 0xf;
637 const GLint rowAg1
= (rowA
[k
] >> 4) & 0xf;
638 const GLint rowBg0
= (rowB
[j
] >> 4) & 0xf;
639 const GLint rowBg1
= (rowB
[k
] >> 4) & 0xf;
640 const GLint r
= (rowAr0
+ rowAr1
+ rowBr0
+ rowBr1
) >> 2;
641 const GLint g
= (rowAg0
+ rowAg1
+ rowBg0
+ rowBg1
) >> 2;
642 dst
[i
] = (g
<< 4) | r
;
646 else if (datatype
== GL_UNSIGNED_INT_2_10_10_10_REV
&& comps
== 4) {
648 const GLuint
*rowA
= (const GLuint
*) srcRowA
;
649 const GLuint
*rowB
= (const GLuint
*) srcRowB
;
650 GLuint
*dst
= (GLuint
*) dstRow
;
651 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
652 i
++, j
+= colStride
, k
+= colStride
) {
653 const GLint rowAr0
= rowA
[j
] & 0x3ff;
654 const GLint rowAr1
= rowA
[k
] & 0x3ff;
655 const GLint rowBr0
= rowB
[j
] & 0x3ff;
656 const GLint rowBr1
= rowB
[k
] & 0x3ff;
657 const GLint rowAg0
= (rowA
[j
] >> 10) & 0x3ff;
658 const GLint rowAg1
= (rowA
[k
] >> 10) & 0x3ff;
659 const GLint rowBg0
= (rowB
[j
] >> 10) & 0x3ff;
660 const GLint rowBg1
= (rowB
[k
] >> 10) & 0x3ff;
661 const GLint rowAb0
= (rowA
[j
] >> 20) & 0x3ff;
662 const GLint rowAb1
= (rowA
[k
] >> 20) & 0x3ff;
663 const GLint rowBb0
= (rowB
[j
] >> 20) & 0x3ff;
664 const GLint rowBb1
= (rowB
[k
] >> 20) & 0x3ff;
665 const GLint rowAa0
= (rowA
[j
] >> 30) & 0x3;
666 const GLint rowAa1
= (rowA
[k
] >> 30) & 0x3;
667 const GLint rowBa0
= (rowB
[j
] >> 30) & 0x3;
668 const GLint rowBa1
= (rowB
[k
] >> 30) & 0x3;
669 const GLint red
= (rowAr0
+ rowAr1
+ rowBr0
+ rowBr1
) >> 2;
670 const GLint green
= (rowAg0
+ rowAg1
+ rowBg0
+ rowBg1
) >> 2;
671 const GLint blue
= (rowAb0
+ rowAb1
+ rowBb0
+ rowBb1
) >> 2;
672 const GLint alpha
= (rowAa0
+ rowAa1
+ rowBa0
+ rowBa1
) >> 2;
673 dst
[i
] = (alpha
<< 30) | (blue
<< 20) | (green
<< 10) | red
;
677 else if (datatype
== GL_UNSIGNED_INT_5_9_9_9_REV
&& comps
== 3) {
679 const GLuint
*rowA
= (const GLuint
*) srcRowA
;
680 const GLuint
*rowB
= (const GLuint
*) srcRowB
;
681 GLuint
*dst
= (GLuint
*)dstRow
;
682 GLfloat res
[3], rowAj
[3], rowBj
[3], rowAk
[3], rowBk
[3];
683 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
684 i
++, j
+= colStride
, k
+= colStride
) {
685 rgb9e5_to_float3(rowA
[j
], rowAj
);
686 rgb9e5_to_float3(rowB
[j
], rowBj
);
687 rgb9e5_to_float3(rowA
[k
], rowAk
);
688 rgb9e5_to_float3(rowB
[k
], rowBk
);
689 res
[0] = (rowAj
[0] + rowAk
[0] + rowBj
[0] + rowBk
[0]) * 0.25F
;
690 res
[1] = (rowAj
[1] + rowAk
[1] + rowBj
[1] + rowBk
[1]) * 0.25F
;
691 res
[2] = (rowAj
[2] + rowAk
[2] + rowBj
[2] + rowBk
[2]) * 0.25F
;
692 dst
[i
] = float3_to_rgb9e5(res
);
696 else if (datatype
== GL_UNSIGNED_INT_10F_11F_11F_REV
&& comps
== 3) {
698 const GLuint
*rowA
= (const GLuint
*) srcRowA
;
699 const GLuint
*rowB
= (const GLuint
*) srcRowB
;
700 GLuint
*dst
= (GLuint
*)dstRow
;
701 GLfloat res
[3], rowAj
[3], rowBj
[3], rowAk
[3], rowBk
[3];
702 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
703 i
++, j
+= colStride
, k
+= colStride
) {
704 r11g11b10f_to_float3(rowA
[j
], rowAj
);
705 r11g11b10f_to_float3(rowB
[j
], rowBj
);
706 r11g11b10f_to_float3(rowA
[k
], rowAk
);
707 r11g11b10f_to_float3(rowB
[k
], rowBk
);
708 res
[0] = (rowAj
[0] + rowAk
[0] + rowBj
[0] + rowBk
[0]) * 0.25F
;
709 res
[1] = (rowAj
[1] + rowAk
[1] + rowBj
[1] + rowBk
[1]) * 0.25F
;
710 res
[2] = (rowAj
[2] + rowAk
[2] + rowBj
[2] + rowBk
[2]) * 0.25F
;
711 dst
[i
] = float3_to_r11g11b10f(res
);
715 else if (datatype
== GL_FLOAT_32_UNSIGNED_INT_24_8_REV
&& comps
== 1) {
717 const GLfloat
*rowA
= (const GLfloat
*) srcRowA
;
718 const GLfloat
*rowB
= (const GLfloat
*) srcRowB
;
719 GLfloat
*dst
= (GLfloat
*) dstRow
;
720 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
721 i
++, j
+= colStride
, k
+= colStride
) {
722 dst
[i
*2] = (rowA
[j
*2] + rowA
[k
*2] + rowB
[j
*2] + rowB
[k
*2]) * 0.25F
;
726 else if (datatype
== GL_UNSIGNED_INT_24_8_MESA
&& comps
== 2) {
728 const GLuint
*rowA
= (const GLuint
*) srcRowA
;
729 const GLuint
*rowB
= (const GLuint
*) srcRowB
;
730 GLuint
*dst
= (GLuint
*) dstRow
;
731 /* note: averaging stencil values seems weird, but what else? */
732 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
733 i
++, j
+= colStride
, k
+= colStride
) {
734 GLuint z
= (((rowA
[j
] >> 8) + (rowA
[k
] >> 8) +
735 (rowB
[j
] >> 8) + (rowB
[k
] >> 8)) / 4) << 8;
736 GLuint s
= ((rowA
[j
] & 0xff) + (rowA
[k
] & 0xff) +
737 (rowB
[j
] & 0xff) + (rowB
[k
] & 0xff)) / 4;
741 else if (datatype
== GL_UNSIGNED_INT_8_24_REV_MESA
&& comps
== 2) {
743 const GLuint
*rowA
= (const GLuint
*) srcRowA
;
744 const GLuint
*rowB
= (const GLuint
*) srcRowB
;
745 GLuint
*dst
= (GLuint
*) dstRow
;
746 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
747 i
++, j
+= colStride
, k
+= colStride
) {
748 GLuint z
= ((rowA
[j
] & 0xffffff) + (rowA
[k
] & 0xffffff) +
749 (rowB
[j
] & 0xffffff) + (rowB
[k
] & 0xffffff)) / 4;
750 GLuint s
= (((rowA
[j
] >> 24) + (rowA
[k
] >> 24) +
751 (rowB
[j
] >> 24) + (rowB
[k
] >> 24)) / 4) << 24;
757 _mesa_problem(NULL
, "bad format in do_row()");
763 * Average together four rows of a source image to produce a single new
764 * row in the dest image. It's legal for the two source rows to point
765 * to the same data. The source width must be equal to either the
766 * dest width or two times the dest width.
768 * \param datatype GL pixel type \c GL_UNSIGNED_BYTE, \c GL_UNSIGNED_SHORT,
770 * \param comps number of components per pixel (1..4)
771 * \param srcWidth Width of a row in the source data
772 * \param srcRowA Pointer to one of the rows of source data
773 * \param srcRowB Pointer to one of the rows of source data
774 * \param srcRowC Pointer to one of the rows of source data
775 * \param srcRowD Pointer to one of the rows of source data
776 * \param dstWidth Width of a row in the destination data
777 * \param srcRowA Pointer to the row of destination data
780 do_row_3D(GLenum datatype
, GLuint comps
, GLint srcWidth
,
781 const GLvoid
*srcRowA
, const GLvoid
*srcRowB
,
782 const GLvoid
*srcRowC
, const GLvoid
*srcRowD
,
783 GLint dstWidth
, GLvoid
*dstRow
)
785 const GLuint k0
= (srcWidth
== dstWidth
) ? 0 : 1;
786 const GLuint colStride
= (srcWidth
== dstWidth
) ? 1 : 2;
792 if ((datatype
== GL_UNSIGNED_BYTE
) && (comps
== 4)) {
793 DECLARE_ROW_POINTERS(GLubyte
, 4);
795 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
796 i
++, j
+= colStride
, k
+= colStride
) {
803 else if ((datatype
== GL_UNSIGNED_BYTE
) && (comps
== 3)) {
804 DECLARE_ROW_POINTERS(GLubyte
, 3);
806 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
807 i
++, j
+= colStride
, k
+= colStride
) {
813 else if ((datatype
== GL_UNSIGNED_BYTE
) && (comps
== 2)) {
814 DECLARE_ROW_POINTERS(GLubyte
, 2);
816 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
817 i
++, j
+= colStride
, k
+= colStride
) {
822 else if ((datatype
== GL_UNSIGNED_BYTE
) && (comps
== 1)) {
823 DECLARE_ROW_POINTERS(GLubyte
, 1);
825 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
826 i
++, j
+= colStride
, k
+= colStride
) {
830 else if ((datatype
== GL_BYTE
) && (comps
== 4)) {
831 DECLARE_ROW_POINTERS(GLbyte
, 4);
833 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
834 i
++, j
+= colStride
, k
+= colStride
) {
841 else if ((datatype
== GL_BYTE
) && (comps
== 3)) {
842 DECLARE_ROW_POINTERS(GLbyte
, 3);
844 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
845 i
++, j
+= colStride
, k
+= colStride
) {
851 else if ((datatype
== GL_BYTE
) && (comps
== 2)) {
852 DECLARE_ROW_POINTERS(GLbyte
, 2);
854 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
855 i
++, j
+= colStride
, k
+= colStride
) {
860 else if ((datatype
== GL_BYTE
) && (comps
== 1)) {
861 DECLARE_ROW_POINTERS(GLbyte
, 1);
863 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
864 i
++, j
+= colStride
, k
+= colStride
) {
868 else if ((datatype
== GL_UNSIGNED_SHORT
) && (comps
== 4)) {
869 DECLARE_ROW_POINTERS(GLushort
, 4);
871 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
872 i
++, j
+= colStride
, k
+= colStride
) {
879 else if ((datatype
== GL_UNSIGNED_SHORT
) && (comps
== 3)) {
880 DECLARE_ROW_POINTERS(GLushort
, 3);
882 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
883 i
++, j
+= colStride
, k
+= colStride
) {
889 else if ((datatype
== GL_UNSIGNED_SHORT
) && (comps
== 2)) {
890 DECLARE_ROW_POINTERS(GLushort
, 2);
892 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
893 i
++, j
+= colStride
, k
+= colStride
) {
898 else if ((datatype
== GL_UNSIGNED_SHORT
) && (comps
== 1)) {
899 DECLARE_ROW_POINTERS(GLushort
, 1);
901 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
902 i
++, j
+= colStride
, k
+= colStride
) {
906 else if ((datatype
== GL_SHORT
) && (comps
== 4)) {
907 DECLARE_ROW_POINTERS(GLshort
, 4);
909 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
910 i
++, j
+= colStride
, k
+= colStride
) {
917 else if ((datatype
== GL_SHORT
) && (comps
== 3)) {
918 DECLARE_ROW_POINTERS(GLshort
, 3);
920 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
921 i
++, j
+= colStride
, k
+= colStride
) {
927 else if ((datatype
== GL_SHORT
) && (comps
== 2)) {
928 DECLARE_ROW_POINTERS(GLshort
, 2);
930 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
931 i
++, j
+= colStride
, k
+= colStride
) {
936 else if ((datatype
== GL_SHORT
) && (comps
== 1)) {
937 DECLARE_ROW_POINTERS(GLshort
, 1);
939 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
940 i
++, j
+= colStride
, k
+= colStride
) {
944 else if ((datatype
== GL_FLOAT
) && (comps
== 4)) {
945 DECLARE_ROW_POINTERS(GLfloat
, 4);
947 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
948 i
++, j
+= colStride
, k
+= colStride
) {
955 else if ((datatype
== GL_FLOAT
) && (comps
== 3)) {
956 DECLARE_ROW_POINTERS(GLfloat
, 3);
958 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
959 i
++, j
+= colStride
, k
+= colStride
) {
965 else if ((datatype
== GL_FLOAT
) && (comps
== 2)) {
966 DECLARE_ROW_POINTERS(GLfloat
, 2);
968 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
969 i
++, j
+= colStride
, k
+= colStride
) {
974 else if ((datatype
== GL_FLOAT
) && (comps
== 1)) {
975 DECLARE_ROW_POINTERS(GLfloat
, 1);
977 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
978 i
++, j
+= colStride
, k
+= colStride
) {
982 else if ((datatype
== GL_HALF_FLOAT_ARB
) && (comps
== 4)) {
983 DECLARE_ROW_POINTERS(GLhalfARB
, 4);
985 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
986 i
++, j
+= colStride
, k
+= colStride
) {
993 else if ((datatype
== GL_HALF_FLOAT_ARB
) && (comps
== 3)) {
994 DECLARE_ROW_POINTERS(GLhalfARB
, 4);
996 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
997 i
++, j
+= colStride
, k
+= colStride
) {
1003 else if ((datatype
== GL_HALF_FLOAT_ARB
) && (comps
== 2)) {
1004 DECLARE_ROW_POINTERS(GLhalfARB
, 4);
1006 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
1007 i
++, j
+= colStride
, k
+= colStride
) {
1012 else if ((datatype
== GL_HALF_FLOAT_ARB
) && (comps
== 1)) {
1013 DECLARE_ROW_POINTERS(GLhalfARB
, 4);
1015 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
1016 i
++, j
+= colStride
, k
+= colStride
) {
1020 else if ((datatype
== GL_UNSIGNED_INT
) && (comps
== 1)) {
1021 const GLuint
*rowA
= (const GLuint
*) srcRowA
;
1022 const GLuint
*rowB
= (const GLuint
*) srcRowB
;
1023 const GLuint
*rowC
= (const GLuint
*) srcRowC
;
1024 const GLuint
*rowD
= (const GLuint
*) srcRowD
;
1025 GLfloat
*dst
= (GLfloat
*) dstRow
;
1027 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
1028 i
++, j
+= colStride
, k
+= colStride
) {
1029 const uint64_t tmp
= (((uint64_t) rowA
[j
] + (uint64_t) rowA
[k
])
1030 + ((uint64_t) rowB
[j
] + (uint64_t) rowB
[k
])
1031 + ((uint64_t) rowC
[j
] + (uint64_t) rowC
[k
])
1032 + ((uint64_t) rowD
[j
] + (uint64_t) rowD
[k
]));
1033 dst
[i
] = (GLfloat
)((double) tmp
* 0.125);
1036 else if ((datatype
== GL_UNSIGNED_SHORT_5_6_5
) && (comps
== 3)) {
1037 DECLARE_ROW_POINTERS0(GLushort
);
1039 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
1040 i
++, j
+= colStride
, k
+= colStride
) {
1041 const GLint rowAr0
= rowA
[j
] & 0x1f;
1042 const GLint rowAr1
= rowA
[k
] & 0x1f;
1043 const GLint rowBr0
= rowB
[j
] & 0x1f;
1044 const GLint rowBr1
= rowB
[k
] & 0x1f;
1045 const GLint rowCr0
= rowC
[j
] & 0x1f;
1046 const GLint rowCr1
= rowC
[k
] & 0x1f;
1047 const GLint rowDr0
= rowD
[j
] & 0x1f;
1048 const GLint rowDr1
= rowD
[k
] & 0x1f;
1049 const GLint rowAg0
= (rowA
[j
] >> 5) & 0x3f;
1050 const GLint rowAg1
= (rowA
[k
] >> 5) & 0x3f;
1051 const GLint rowBg0
= (rowB
[j
] >> 5) & 0x3f;
1052 const GLint rowBg1
= (rowB
[k
] >> 5) & 0x3f;
1053 const GLint rowCg0
= (rowC
[j
] >> 5) & 0x3f;
1054 const GLint rowCg1
= (rowC
[k
] >> 5) & 0x3f;
1055 const GLint rowDg0
= (rowD
[j
] >> 5) & 0x3f;
1056 const GLint rowDg1
= (rowD
[k
] >> 5) & 0x3f;
1057 const GLint rowAb0
= (rowA
[j
] >> 11) & 0x1f;
1058 const GLint rowAb1
= (rowA
[k
] >> 11) & 0x1f;
1059 const GLint rowBb0
= (rowB
[j
] >> 11) & 0x1f;
1060 const GLint rowBb1
= (rowB
[k
] >> 11) & 0x1f;
1061 const GLint rowCb0
= (rowC
[j
] >> 11) & 0x1f;
1062 const GLint rowCb1
= (rowC
[k
] >> 11) & 0x1f;
1063 const GLint rowDb0
= (rowD
[j
] >> 11) & 0x1f;
1064 const GLint rowDb1
= (rowD
[k
] >> 11) & 0x1f;
1065 const GLint r
= FILTER_SUM_3D(rowAr0
, rowAr1
, rowBr0
, rowBr1
,
1066 rowCr0
, rowCr1
, rowDr0
, rowDr1
);
1067 const GLint g
= FILTER_SUM_3D(rowAg0
, rowAg1
, rowBg0
, rowBg1
,
1068 rowCg0
, rowCg1
, rowDg0
, rowDg1
);
1069 const GLint b
= FILTER_SUM_3D(rowAb0
, rowAb1
, rowBb0
, rowBb1
,
1070 rowCb0
, rowCb1
, rowDb0
, rowDb1
);
1071 dst
[i
] = (b
<< 11) | (g
<< 5) | r
;
1074 else if ((datatype
== GL_UNSIGNED_SHORT_4_4_4_4
) && (comps
== 4)) {
1075 DECLARE_ROW_POINTERS0(GLushort
);
1077 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
1078 i
++, j
+= colStride
, k
+= colStride
) {
1079 const GLint rowAr0
= rowA
[j
] & 0xf;
1080 const GLint rowAr1
= rowA
[k
] & 0xf;
1081 const GLint rowBr0
= rowB
[j
] & 0xf;
1082 const GLint rowBr1
= rowB
[k
] & 0xf;
1083 const GLint rowCr0
= rowC
[j
] & 0xf;
1084 const GLint rowCr1
= rowC
[k
] & 0xf;
1085 const GLint rowDr0
= rowD
[j
] & 0xf;
1086 const GLint rowDr1
= rowD
[k
] & 0xf;
1087 const GLint rowAg0
= (rowA
[j
] >> 4) & 0xf;
1088 const GLint rowAg1
= (rowA
[k
] >> 4) & 0xf;
1089 const GLint rowBg0
= (rowB
[j
] >> 4) & 0xf;
1090 const GLint rowBg1
= (rowB
[k
] >> 4) & 0xf;
1091 const GLint rowCg0
= (rowC
[j
] >> 4) & 0xf;
1092 const GLint rowCg1
= (rowC
[k
] >> 4) & 0xf;
1093 const GLint rowDg0
= (rowD
[j
] >> 4) & 0xf;
1094 const GLint rowDg1
= (rowD
[k
] >> 4) & 0xf;
1095 const GLint rowAb0
= (rowA
[j
] >> 8) & 0xf;
1096 const GLint rowAb1
= (rowA
[k
] >> 8) & 0xf;
1097 const GLint rowBb0
= (rowB
[j
] >> 8) & 0xf;
1098 const GLint rowBb1
= (rowB
[k
] >> 8) & 0xf;
1099 const GLint rowCb0
= (rowC
[j
] >> 8) & 0xf;
1100 const GLint rowCb1
= (rowC
[k
] >> 8) & 0xf;
1101 const GLint rowDb0
= (rowD
[j
] >> 8) & 0xf;
1102 const GLint rowDb1
= (rowD
[k
] >> 8) & 0xf;
1103 const GLint rowAa0
= (rowA
[j
] >> 12) & 0xf;
1104 const GLint rowAa1
= (rowA
[k
] >> 12) & 0xf;
1105 const GLint rowBa0
= (rowB
[j
] >> 12) & 0xf;
1106 const GLint rowBa1
= (rowB
[k
] >> 12) & 0xf;
1107 const GLint rowCa0
= (rowC
[j
] >> 12) & 0xf;
1108 const GLint rowCa1
= (rowC
[k
] >> 12) & 0xf;
1109 const GLint rowDa0
= (rowD
[j
] >> 12) & 0xf;
1110 const GLint rowDa1
= (rowD
[k
] >> 12) & 0xf;
1111 const GLint r
= FILTER_SUM_3D(rowAr0
, rowAr1
, rowBr0
, rowBr1
,
1112 rowCr0
, rowCr1
, rowDr0
, rowDr1
);
1113 const GLint g
= FILTER_SUM_3D(rowAg0
, rowAg1
, rowBg0
, rowBg1
,
1114 rowCg0
, rowCg1
, rowDg0
, rowDg1
);
1115 const GLint b
= FILTER_SUM_3D(rowAb0
, rowAb1
, rowBb0
, rowBb1
,
1116 rowCb0
, rowCb1
, rowDb0
, rowDb1
);
1117 const GLint a
= FILTER_SUM_3D(rowAa0
, rowAa1
, rowBa0
, rowBa1
,
1118 rowCa0
, rowCa1
, rowDa0
, rowDa1
);
1120 dst
[i
] = (a
<< 12) | (b
<< 8) | (g
<< 4) | r
;
1123 else if ((datatype
== GL_UNSIGNED_SHORT_1_5_5_5_REV
) && (comps
== 4)) {
1124 DECLARE_ROW_POINTERS0(GLushort
);
1126 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
1127 i
++, j
+= colStride
, k
+= colStride
) {
1128 const GLint rowAr0
= rowA
[j
] & 0x1f;
1129 const GLint rowAr1
= rowA
[k
] & 0x1f;
1130 const GLint rowBr0
= rowB
[j
] & 0x1f;
1131 const GLint rowBr1
= rowB
[k
] & 0x1f;
1132 const GLint rowCr0
= rowC
[j
] & 0x1f;
1133 const GLint rowCr1
= rowC
[k
] & 0x1f;
1134 const GLint rowDr0
= rowD
[j
] & 0x1f;
1135 const GLint rowDr1
= rowD
[k
] & 0x1f;
1136 const GLint rowAg0
= (rowA
[j
] >> 5) & 0x1f;
1137 const GLint rowAg1
= (rowA
[k
] >> 5) & 0x1f;
1138 const GLint rowBg0
= (rowB
[j
] >> 5) & 0x1f;
1139 const GLint rowBg1
= (rowB
[k
] >> 5) & 0x1f;
1140 const GLint rowCg0
= (rowC
[j
] >> 5) & 0x1f;
1141 const GLint rowCg1
= (rowC
[k
] >> 5) & 0x1f;
1142 const GLint rowDg0
= (rowD
[j
] >> 5) & 0x1f;
1143 const GLint rowDg1
= (rowD
[k
] >> 5) & 0x1f;
1144 const GLint rowAb0
= (rowA
[j
] >> 10) & 0x1f;
1145 const GLint rowAb1
= (rowA
[k
] >> 10) & 0x1f;
1146 const GLint rowBb0
= (rowB
[j
] >> 10) & 0x1f;
1147 const GLint rowBb1
= (rowB
[k
] >> 10) & 0x1f;
1148 const GLint rowCb0
= (rowC
[j
] >> 10) & 0x1f;
1149 const GLint rowCb1
= (rowC
[k
] >> 10) & 0x1f;
1150 const GLint rowDb0
= (rowD
[j
] >> 10) & 0x1f;
1151 const GLint rowDb1
= (rowD
[k
] >> 10) & 0x1f;
1152 const GLint rowAa0
= (rowA
[j
] >> 15) & 0x1;
1153 const GLint rowAa1
= (rowA
[k
] >> 15) & 0x1;
1154 const GLint rowBa0
= (rowB
[j
] >> 15) & 0x1;
1155 const GLint rowBa1
= (rowB
[k
] >> 15) & 0x1;
1156 const GLint rowCa0
= (rowC
[j
] >> 15) & 0x1;
1157 const GLint rowCa1
= (rowC
[k
] >> 15) & 0x1;
1158 const GLint rowDa0
= (rowD
[j
] >> 15) & 0x1;
1159 const GLint rowDa1
= (rowD
[k
] >> 15) & 0x1;
1160 const GLint r
= FILTER_SUM_3D(rowAr0
, rowAr1
, rowBr0
, rowBr1
,
1161 rowCr0
, rowCr1
, rowDr0
, rowDr1
);
1162 const GLint g
= FILTER_SUM_3D(rowAg0
, rowAg1
, rowBg0
, rowBg1
,
1163 rowCg0
, rowCg1
, rowDg0
, rowDg1
);
1164 const GLint b
= FILTER_SUM_3D(rowAb0
, rowAb1
, rowBb0
, rowBb1
,
1165 rowCb0
, rowCb1
, rowDb0
, rowDb1
);
1166 const GLint a
= FILTER_SUM_3D(rowAa0
, rowAa1
, rowBa0
, rowBa1
,
1167 rowCa0
, rowCa1
, rowDa0
, rowDa1
);
1169 dst
[i
] = (a
<< 15) | (b
<< 10) | (g
<< 5) | r
;
1172 else if ((datatype
== GL_UNSIGNED_SHORT_5_5_5_1
) && (comps
== 4)) {
1173 DECLARE_ROW_POINTERS0(GLushort
);
1175 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
1176 i
++, j
+= colStride
, k
+= colStride
) {
1177 const GLint rowAr0
= (rowA
[j
] >> 11) & 0x1f;
1178 const GLint rowAr1
= (rowA
[k
] >> 11) & 0x1f;
1179 const GLint rowBr0
= (rowB
[j
] >> 11) & 0x1f;
1180 const GLint rowBr1
= (rowB
[k
] >> 11) & 0x1f;
1181 const GLint rowCr0
= (rowC
[j
] >> 11) & 0x1f;
1182 const GLint rowCr1
= (rowC
[k
] >> 11) & 0x1f;
1183 const GLint rowDr0
= (rowD
[j
] >> 11) & 0x1f;
1184 const GLint rowDr1
= (rowD
[k
] >> 11) & 0x1f;
1185 const GLint rowAg0
= (rowA
[j
] >> 6) & 0x1f;
1186 const GLint rowAg1
= (rowA
[k
] >> 6) & 0x1f;
1187 const GLint rowBg0
= (rowB
[j
] >> 6) & 0x1f;
1188 const GLint rowBg1
= (rowB
[k
] >> 6) & 0x1f;
1189 const GLint rowCg0
= (rowC
[j
] >> 6) & 0x1f;
1190 const GLint rowCg1
= (rowC
[k
] >> 6) & 0x1f;
1191 const GLint rowDg0
= (rowD
[j
] >> 6) & 0x1f;
1192 const GLint rowDg1
= (rowD
[k
] >> 6) & 0x1f;
1193 const GLint rowAb0
= (rowA
[j
] >> 1) & 0x1f;
1194 const GLint rowAb1
= (rowA
[k
] >> 1) & 0x1f;
1195 const GLint rowBb0
= (rowB
[j
] >> 1) & 0x1f;
1196 const GLint rowBb1
= (rowB
[k
] >> 1) & 0x1f;
1197 const GLint rowCb0
= (rowC
[j
] >> 1) & 0x1f;
1198 const GLint rowCb1
= (rowC
[k
] >> 1) & 0x1f;
1199 const GLint rowDb0
= (rowD
[j
] >> 1) & 0x1f;
1200 const GLint rowDb1
= (rowD
[k
] >> 1) & 0x1f;
1201 const GLint rowAa0
= (rowA
[j
] & 0x1);
1202 const GLint rowAa1
= (rowA
[k
] & 0x1);
1203 const GLint rowBa0
= (rowB
[j
] & 0x1);
1204 const GLint rowBa1
= (rowB
[k
] & 0x1);
1205 const GLint rowCa0
= (rowC
[j
] & 0x1);
1206 const GLint rowCa1
= (rowC
[k
] & 0x1);
1207 const GLint rowDa0
= (rowD
[j
] & 0x1);
1208 const GLint rowDa1
= (rowD
[k
] & 0x1);
1209 const GLint r
= FILTER_SUM_3D(rowAr0
, rowAr1
, rowBr0
, rowBr1
,
1210 rowCr0
, rowCr1
, rowDr0
, rowDr1
);
1211 const GLint g
= FILTER_SUM_3D(rowAg0
, rowAg1
, rowBg0
, rowBg1
,
1212 rowCg0
, rowCg1
, rowDg0
, rowDg1
);
1213 const GLint b
= FILTER_SUM_3D(rowAb0
, rowAb1
, rowBb0
, rowBb1
,
1214 rowCb0
, rowCb1
, rowDb0
, rowDb1
);
1215 const GLint a
= FILTER_SUM_3D(rowAa0
, rowAa1
, rowBa0
, rowBa1
,
1216 rowCa0
, rowCa1
, rowDa0
, rowDa1
);
1218 dst
[i
] = (r
<< 11) | (g
<< 6) | (b
<< 1) | a
;
1221 else if ((datatype
== GL_UNSIGNED_BYTE_3_3_2
) && (comps
== 3)) {
1222 DECLARE_ROW_POINTERS0(GLubyte
);
1224 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
1225 i
++, j
+= colStride
, k
+= colStride
) {
1226 const GLint rowAr0
= rowA
[j
] & 0x3;
1227 const GLint rowAr1
= rowA
[k
] & 0x3;
1228 const GLint rowBr0
= rowB
[j
] & 0x3;
1229 const GLint rowBr1
= rowB
[k
] & 0x3;
1230 const GLint rowCr0
= rowC
[j
] & 0x3;
1231 const GLint rowCr1
= rowC
[k
] & 0x3;
1232 const GLint rowDr0
= rowD
[j
] & 0x3;
1233 const GLint rowDr1
= rowD
[k
] & 0x3;
1234 const GLint rowAg0
= (rowA
[j
] >> 2) & 0x7;
1235 const GLint rowAg1
= (rowA
[k
] >> 2) & 0x7;
1236 const GLint rowBg0
= (rowB
[j
] >> 2) & 0x7;
1237 const GLint rowBg1
= (rowB
[k
] >> 2) & 0x7;
1238 const GLint rowCg0
= (rowC
[j
] >> 2) & 0x7;
1239 const GLint rowCg1
= (rowC
[k
] >> 2) & 0x7;
1240 const GLint rowDg0
= (rowD
[j
] >> 2) & 0x7;
1241 const GLint rowDg1
= (rowD
[k
] >> 2) & 0x7;
1242 const GLint rowAb0
= (rowA
[j
] >> 5) & 0x7;
1243 const GLint rowAb1
= (rowA
[k
] >> 5) & 0x7;
1244 const GLint rowBb0
= (rowB
[j
] >> 5) & 0x7;
1245 const GLint rowBb1
= (rowB
[k
] >> 5) & 0x7;
1246 const GLint rowCb0
= (rowC
[j
] >> 5) & 0x7;
1247 const GLint rowCb1
= (rowC
[k
] >> 5) & 0x7;
1248 const GLint rowDb0
= (rowD
[j
] >> 5) & 0x7;
1249 const GLint rowDb1
= (rowD
[k
] >> 5) & 0x7;
1250 const GLint r
= FILTER_SUM_3D(rowAr0
, rowAr1
, rowBr0
, rowBr1
,
1251 rowCr0
, rowCr1
, rowDr0
, rowDr1
);
1252 const GLint g
= FILTER_SUM_3D(rowAg0
, rowAg1
, rowBg0
, rowBg1
,
1253 rowCg0
, rowCg1
, rowDg0
, rowDg1
);
1254 const GLint b
= FILTER_SUM_3D(rowAb0
, rowAb1
, rowBb0
, rowBb1
,
1255 rowCb0
, rowCb1
, rowDb0
, rowDb1
);
1256 dst
[i
] = (b
<< 5) | (g
<< 2) | r
;
1259 else if (datatype
== MESA_UNSIGNED_BYTE_4_4
&& comps
== 2) {
1260 DECLARE_ROW_POINTERS0(GLubyte
);
1262 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
1263 i
++, j
+= colStride
, k
+= colStride
) {
1264 const GLint rowAr0
= rowA
[j
] & 0xf;
1265 const GLint rowAr1
= rowA
[k
] & 0xf;
1266 const GLint rowBr0
= rowB
[j
] & 0xf;
1267 const GLint rowBr1
= rowB
[k
] & 0xf;
1268 const GLint rowCr0
= rowC
[j
] & 0xf;
1269 const GLint rowCr1
= rowC
[k
] & 0xf;
1270 const GLint rowDr0
= rowD
[j
] & 0xf;
1271 const GLint rowDr1
= rowD
[k
] & 0xf;
1272 const GLint rowAg0
= (rowA
[j
] >> 4) & 0xf;
1273 const GLint rowAg1
= (rowA
[k
] >> 4) & 0xf;
1274 const GLint rowBg0
= (rowB
[j
] >> 4) & 0xf;
1275 const GLint rowBg1
= (rowB
[k
] >> 4) & 0xf;
1276 const GLint rowCg0
= (rowC
[j
] >> 4) & 0xf;
1277 const GLint rowCg1
= (rowC
[k
] >> 4) & 0xf;
1278 const GLint rowDg0
= (rowD
[j
] >> 4) & 0xf;
1279 const GLint rowDg1
= (rowD
[k
] >> 4) & 0xf;
1280 const GLint r
= FILTER_SUM_3D(rowAr0
, rowAr1
, rowBr0
, rowBr1
,
1281 rowCr0
, rowCr1
, rowDr0
, rowDr1
);
1282 const GLint g
= FILTER_SUM_3D(rowAg0
, rowAg1
, rowBg0
, rowBg1
,
1283 rowCg0
, rowCg1
, rowDg0
, rowDg1
);
1284 dst
[i
] = (g
<< 4) | r
;
1287 else if ((datatype
== GL_UNSIGNED_INT_2_10_10_10_REV
) && (comps
== 4)) {
1288 DECLARE_ROW_POINTERS0(GLuint
);
1290 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
1291 i
++, j
+= colStride
, k
+= colStride
) {
1292 const GLint rowAr0
= rowA
[j
] & 0x3ff;
1293 const GLint rowAr1
= rowA
[k
] & 0x3ff;
1294 const GLint rowBr0
= rowB
[j
] & 0x3ff;
1295 const GLint rowBr1
= rowB
[k
] & 0x3ff;
1296 const GLint rowCr0
= rowC
[j
] & 0x3ff;
1297 const GLint rowCr1
= rowC
[k
] & 0x3ff;
1298 const GLint rowDr0
= rowD
[j
] & 0x3ff;
1299 const GLint rowDr1
= rowD
[k
] & 0x3ff;
1300 const GLint rowAg0
= (rowA
[j
] >> 10) & 0x3ff;
1301 const GLint rowAg1
= (rowA
[k
] >> 10) & 0x3ff;
1302 const GLint rowBg0
= (rowB
[j
] >> 10) & 0x3ff;
1303 const GLint rowBg1
= (rowB
[k
] >> 10) & 0x3ff;
1304 const GLint rowCg0
= (rowC
[j
] >> 10) & 0x3ff;
1305 const GLint rowCg1
= (rowC
[k
] >> 10) & 0x3ff;
1306 const GLint rowDg0
= (rowD
[j
] >> 10) & 0x3ff;
1307 const GLint rowDg1
= (rowD
[k
] >> 10) & 0x3ff;
1308 const GLint rowAb0
= (rowA
[j
] >> 20) & 0x3ff;
1309 const GLint rowAb1
= (rowA
[k
] >> 20) & 0x3ff;
1310 const GLint rowBb0
= (rowB
[j
] >> 20) & 0x3ff;
1311 const GLint rowBb1
= (rowB
[k
] >> 20) & 0x3ff;
1312 const GLint rowCb0
= (rowC
[j
] >> 20) & 0x3ff;
1313 const GLint rowCb1
= (rowC
[k
] >> 20) & 0x3ff;
1314 const GLint rowDb0
= (rowD
[j
] >> 20) & 0x3ff;
1315 const GLint rowDb1
= (rowD
[k
] >> 20) & 0x3ff;
1316 const GLint rowAa0
= (rowA
[j
] >> 30) & 0x3;
1317 const GLint rowAa1
= (rowA
[k
] >> 30) & 0x3;
1318 const GLint rowBa0
= (rowB
[j
] >> 30) & 0x3;
1319 const GLint rowBa1
= (rowB
[k
] >> 30) & 0x3;
1320 const GLint rowCa0
= (rowC
[j
] >> 30) & 0x3;
1321 const GLint rowCa1
= (rowC
[k
] >> 30) & 0x3;
1322 const GLint rowDa0
= (rowD
[j
] >> 30) & 0x3;
1323 const GLint rowDa1
= (rowD
[k
] >> 30) & 0x3;
1324 const GLint r
= FILTER_SUM_3D(rowAr0
, rowAr1
, rowBr0
, rowBr1
,
1325 rowCr0
, rowCr1
, rowDr0
, rowDr1
);
1326 const GLint g
= FILTER_SUM_3D(rowAg0
, rowAg1
, rowBg0
, rowBg1
,
1327 rowCg0
, rowCg1
, rowDg0
, rowDg1
);
1328 const GLint b
= FILTER_SUM_3D(rowAb0
, rowAb1
, rowBb0
, rowBb1
,
1329 rowCb0
, rowCb1
, rowDb0
, rowDb1
);
1330 const GLint a
= FILTER_SUM_3D(rowAa0
, rowAa1
, rowBa0
, rowBa1
,
1331 rowCa0
, rowCa1
, rowDa0
, rowDa1
);
1333 dst
[i
] = (a
<< 30) | (b
<< 20) | (g
<< 10) | r
;
1337 else if (datatype
== GL_UNSIGNED_INT_5_9_9_9_REV
&& comps
== 3) {
1338 DECLARE_ROW_POINTERS0(GLuint
);
1341 GLfloat rowAj
[3], rowBj
[3], rowCj
[3], rowDj
[3];
1342 GLfloat rowAk
[3], rowBk
[3], rowCk
[3], rowDk
[3];
1344 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
1345 i
++, j
+= colStride
, k
+= colStride
) {
1346 rgb9e5_to_float3(rowA
[j
], rowAj
);
1347 rgb9e5_to_float3(rowB
[j
], rowBj
);
1348 rgb9e5_to_float3(rowC
[j
], rowCj
);
1349 rgb9e5_to_float3(rowD
[j
], rowDj
);
1350 rgb9e5_to_float3(rowA
[k
], rowAk
);
1351 rgb9e5_to_float3(rowB
[k
], rowBk
);
1352 rgb9e5_to_float3(rowC
[k
], rowCk
);
1353 rgb9e5_to_float3(rowD
[k
], rowDk
);
1354 res
[0] = (rowAj
[0] + rowAk
[0] + rowBj
[0] + rowBk
[0] +
1355 rowCj
[0] + rowCk
[0] + rowDj
[0] + rowDk
[0]) * 0.125F
;
1356 res
[1] = (rowAj
[1] + rowAk
[1] + rowBj
[1] + rowBk
[1] +
1357 rowCj
[1] + rowCk
[1] + rowDj
[1] + rowDk
[1]) * 0.125F
;
1358 res
[2] = (rowAj
[2] + rowAk
[2] + rowBj
[2] + rowBk
[2] +
1359 rowCj
[2] + rowCk
[2] + rowDj
[2] + rowDk
[2]) * 0.125F
;
1360 dst
[i
] = float3_to_rgb9e5(res
);
1364 else if (datatype
== GL_UNSIGNED_INT_10F_11F_11F_REV
&& comps
== 3) {
1365 DECLARE_ROW_POINTERS0(GLuint
);
1368 GLfloat rowAj
[3], rowBj
[3], rowCj
[3], rowDj
[3];
1369 GLfloat rowAk
[3], rowBk
[3], rowCk
[3], rowDk
[3];
1371 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
1372 i
++, j
+= colStride
, k
+= colStride
) {
1373 r11g11b10f_to_float3(rowA
[j
], rowAj
);
1374 r11g11b10f_to_float3(rowB
[j
], rowBj
);
1375 r11g11b10f_to_float3(rowC
[j
], rowCj
);
1376 r11g11b10f_to_float3(rowD
[j
], rowDj
);
1377 r11g11b10f_to_float3(rowA
[k
], rowAk
);
1378 r11g11b10f_to_float3(rowB
[k
], rowBk
);
1379 r11g11b10f_to_float3(rowC
[k
], rowCk
);
1380 r11g11b10f_to_float3(rowD
[k
], rowDk
);
1381 res
[0] = (rowAj
[0] + rowAk
[0] + rowBj
[0] + rowBk
[0] +
1382 rowCj
[0] + rowCk
[0] + rowDj
[0] + rowDk
[0]) * 0.125F
;
1383 res
[1] = (rowAj
[1] + rowAk
[1] + rowBj
[1] + rowBk
[1] +
1384 rowCj
[1] + rowCk
[1] + rowDj
[1] + rowDk
[1]) * 0.125F
;
1385 res
[2] = (rowAj
[2] + rowAk
[2] + rowBj
[2] + rowBk
[2] +
1386 rowCj
[2] + rowCk
[2] + rowDj
[2] + rowDk
[2]) * 0.125F
;
1387 dst
[i
] = float3_to_r11g11b10f(res
);
1391 else if (datatype
== GL_FLOAT_32_UNSIGNED_INT_24_8_REV
&& comps
== 1) {
1392 DECLARE_ROW_POINTERS(GLfloat
, 2);
1394 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
1395 i
++, j
+= colStride
, k
+= colStride
) {
1401 _mesa_problem(NULL
, "bad format in do_row()");
1407 * These functions generate a 1/2-size mipmap image from a source image.
1408 * Texture borders are handled by copying or averaging the source image's
1409 * border texels, depending on the scale-down factor.
1413 make_1d_mipmap(GLenum datatype
, GLuint comps
, GLint border
,
1414 GLint srcWidth
, const GLubyte
*srcPtr
,
1415 GLint dstWidth
, GLubyte
*dstPtr
)
1417 const GLint bpt
= bytes_per_pixel(datatype
, comps
);
1421 /* skip the border pixel, if any */
1422 src
= srcPtr
+ border
* bpt
;
1423 dst
= dstPtr
+ border
* bpt
;
1425 /* we just duplicate the input row, kind of hack, saves code */
1426 do_row(datatype
, comps
, srcWidth
- 2 * border
, src
, src
,
1427 dstWidth
- 2 * border
, dst
);
1430 /* copy left-most pixel from source */
1433 memcpy(dstPtr
, srcPtr
, bpt
);
1434 /* copy right-most pixel from source */
1435 memcpy(dstPtr
+ (dstWidth
- 1) * bpt
,
1436 srcPtr
+ (srcWidth
- 1) * bpt
,
1443 make_2d_mipmap(GLenum datatype
, GLuint comps
, GLint border
,
1444 GLint srcWidth
, GLint srcHeight
,
1445 const GLubyte
*srcPtr
, GLint srcRowStride
,
1446 GLint dstWidth
, GLint dstHeight
,
1447 GLubyte
*dstPtr
, GLint dstRowStride
)
1449 const GLint bpt
= bytes_per_pixel(datatype
, comps
);
1450 const GLint srcWidthNB
= srcWidth
- 2 * border
; /* sizes w/out border */
1451 const GLint dstWidthNB
= dstWidth
- 2 * border
;
1452 const GLint dstHeightNB
= dstHeight
- 2 * border
;
1453 const GLubyte
*srcA
, *srcB
;
1455 GLint row
, srcRowStep
;
1457 /* Compute src and dst pointers, skipping any border */
1458 srcA
= srcPtr
+ border
* ((srcWidth
+ 1) * bpt
);
1459 if (srcHeight
> 1 && srcHeight
> dstHeight
) {
1460 /* sample from two source rows */
1461 srcB
= srcA
+ srcRowStride
;
1465 /* sample from one source row */
1470 dst
= dstPtr
+ border
* ((dstWidth
+ 1) * bpt
);
1472 for (row
= 0; row
< dstHeightNB
; row
++) {
1473 do_row(datatype
, comps
, srcWidthNB
, srcA
, srcB
,
1475 srcA
+= srcRowStep
* srcRowStride
;
1476 srcB
+= srcRowStep
* srcRowStride
;
1477 dst
+= dstRowStride
;
1480 /* This is ugly but probably won't be used much */
1482 /* fill in dest border */
1483 /* lower-left border pixel */
1486 memcpy(dstPtr
, srcPtr
, bpt
);
1487 /* lower-right border pixel */
1488 memcpy(dstPtr
+ (dstWidth
- 1) * bpt
,
1489 srcPtr
+ (srcWidth
- 1) * bpt
, bpt
);
1490 /* upper-left border pixel */
1491 memcpy(dstPtr
+ dstWidth
* (dstHeight
- 1) * bpt
,
1492 srcPtr
+ srcWidth
* (srcHeight
- 1) * bpt
, bpt
);
1493 /* upper-right border pixel */
1494 memcpy(dstPtr
+ (dstWidth
* dstHeight
- 1) * bpt
,
1495 srcPtr
+ (srcWidth
* srcHeight
- 1) * bpt
, bpt
);
1497 do_row(datatype
, comps
, srcWidthNB
,
1500 dstWidthNB
, dstPtr
+ bpt
);
1502 do_row(datatype
, comps
, srcWidthNB
,
1503 srcPtr
+ (srcWidth
* (srcHeight
- 1) + 1) * bpt
,
1504 srcPtr
+ (srcWidth
* (srcHeight
- 1) + 1) * bpt
,
1506 dstPtr
+ (dstWidth
* (dstHeight
- 1) + 1) * bpt
);
1507 /* left and right borders */
1508 if (srcHeight
== dstHeight
) {
1509 /* copy border pixel from src to dst */
1510 for (row
= 1; row
< srcHeight
; row
++) {
1511 memcpy(dstPtr
+ dstWidth
* row
* bpt
,
1512 srcPtr
+ srcWidth
* row
* bpt
, bpt
);
1513 memcpy(dstPtr
+ (dstWidth
* row
+ dstWidth
- 1) * bpt
,
1514 srcPtr
+ (srcWidth
* row
+ srcWidth
- 1) * bpt
, bpt
);
1518 /* average two src pixels each dest pixel */
1519 for (row
= 0; row
< dstHeightNB
; row
+= 2) {
1520 do_row(datatype
, comps
, 1,
1521 srcPtr
+ (srcWidth
* (row
* 2 + 1)) * bpt
,
1522 srcPtr
+ (srcWidth
* (row
* 2 + 2)) * bpt
,
1523 1, dstPtr
+ (dstWidth
* row
+ 1) * bpt
);
1524 do_row(datatype
, comps
, 1,
1525 srcPtr
+ (srcWidth
* (row
* 2 + 1) + srcWidth
- 1) * bpt
,
1526 srcPtr
+ (srcWidth
* (row
* 2 + 2) + srcWidth
- 1) * bpt
,
1527 1, dstPtr
+ (dstWidth
* row
+ 1 + dstWidth
- 1) * bpt
);
1535 make_3d_mipmap(GLenum datatype
, GLuint comps
, GLint border
,
1536 GLint srcWidth
, GLint srcHeight
, GLint srcDepth
,
1537 const GLubyte
**srcPtr
, GLint srcRowStride
,
1538 GLint dstWidth
, GLint dstHeight
, GLint dstDepth
,
1539 GLubyte
**dstPtr
, GLint dstRowStride
)
1541 const GLint bpt
= bytes_per_pixel(datatype
, comps
);
1542 const GLint srcWidthNB
= srcWidth
- 2 * border
; /* sizes w/out border */
1543 const GLint srcDepthNB
= srcDepth
- 2 * border
;
1544 const GLint dstWidthNB
= dstWidth
- 2 * border
;
1545 const GLint dstHeightNB
= dstHeight
- 2 * border
;
1546 const GLint dstDepthNB
= dstDepth
- 2 * border
;
1548 GLint bytesPerSrcImage
, bytesPerDstImage
;
1549 GLint bytesPerSrcRow
, bytesPerDstRow
;
1550 GLint srcImageOffset
, srcRowOffset
;
1552 (void) srcDepthNB
; /* silence warnings */
1555 bytesPerSrcImage
= srcWidth
* srcHeight
* bpt
;
1556 bytesPerDstImage
= dstWidth
* dstHeight
* bpt
;
1558 bytesPerSrcRow
= srcWidth
* bpt
;
1559 bytesPerDstRow
= dstWidth
* bpt
;
1561 /* Offset between adjacent src images to be averaged together */
1562 srcImageOffset
= (srcDepth
== dstDepth
) ? 0 : 1;
1564 /* Offset between adjacent src rows to be averaged together */
1565 srcRowOffset
= (srcHeight
== dstHeight
) ? 0 : srcWidth
* bpt
;
1568 * Need to average together up to 8 src pixels for each dest pixel.
1569 * Break that down into 3 operations:
1570 * 1. take two rows from source image and average them together.
1571 * 2. take two rows from next source image and average them together.
1572 * 3. take the two averaged rows and average them for the final dst row.
1576 printf("mip3d %d x %d x %d -> %d x %d x %d\n",
1577 srcWidth, srcHeight, srcDepth, dstWidth, dstHeight, dstDepth);
1580 for (img
= 0; img
< dstDepthNB
; img
++) {
1581 /* first source image pointer, skipping border */
1582 const GLubyte
*imgSrcA
= srcPtr
[img
* 2 + border
]
1583 + bytesPerSrcRow
* border
+ bpt
* border
;
1584 /* second source image pointer, skipping border */
1585 const GLubyte
*imgSrcB
= srcPtr
[img
* 2 + srcImageOffset
+ border
]
1586 + bytesPerSrcRow
* border
+ bpt
* border
;
1588 /* address of the dest image, skipping border */
1589 GLubyte
*imgDst
= dstPtr
[img
+ border
]
1590 + bytesPerDstRow
* border
+ bpt
* border
;
1592 /* setup the four source row pointers and the dest row pointer */
1593 const GLubyte
*srcImgARowA
= imgSrcA
;
1594 const GLubyte
*srcImgARowB
= imgSrcA
+ srcRowOffset
;
1595 const GLubyte
*srcImgBRowA
= imgSrcB
;
1596 const GLubyte
*srcImgBRowB
= imgSrcB
+ srcRowOffset
;
1597 GLubyte
*dstImgRow
= imgDst
;
1599 for (row
= 0; row
< dstHeightNB
; row
++) {
1600 do_row_3D(datatype
, comps
, srcWidthNB
,
1601 srcImgARowA
, srcImgARowB
,
1602 srcImgBRowA
, srcImgBRowB
,
1603 dstWidthNB
, dstImgRow
);
1605 /* advance to next rows */
1606 srcImgARowA
+= bytesPerSrcRow
+ srcRowOffset
;
1607 srcImgARowB
+= bytesPerSrcRow
+ srcRowOffset
;
1608 srcImgBRowA
+= bytesPerSrcRow
+ srcRowOffset
;
1609 srcImgBRowB
+= bytesPerSrcRow
+ srcRowOffset
;
1610 dstImgRow
+= bytesPerDstRow
;
1615 /* Luckily we can leverage the make_2d_mipmap() function here! */
1617 /* do front border image */
1618 make_2d_mipmap(datatype
, comps
, 1,
1619 srcWidth
, srcHeight
, srcPtr
[0], srcRowStride
,
1620 dstWidth
, dstHeight
, dstPtr
[0], dstRowStride
);
1621 /* do back border image */
1622 make_2d_mipmap(datatype
, comps
, 1,
1623 srcWidth
, srcHeight
, srcPtr
[srcDepth
- 1], srcRowStride
,
1624 dstWidth
, dstHeight
, dstPtr
[dstDepth
- 1], dstRowStride
);
1626 /* do four remaining border edges that span the image slices */
1627 if (srcDepth
== dstDepth
) {
1628 /* just copy border pixels from src to dst */
1629 for (img
= 0; img
< dstDepthNB
; img
++) {
1633 /* do border along [img][row=0][col=0] */
1634 src
= srcPtr
[img
* 2];
1636 memcpy(dst
, src
, bpt
);
1638 /* do border along [img][row=dstHeight-1][col=0] */
1639 src
= srcPtr
[img
* 2] + (srcHeight
- 1) * bytesPerSrcRow
;
1640 dst
= dstPtr
[img
] + (dstHeight
- 1) * bytesPerDstRow
;
1641 memcpy(dst
, src
, bpt
);
1643 /* do border along [img][row=0][col=dstWidth-1] */
1644 src
= srcPtr
[img
* 2] + (srcWidth
- 1) * bpt
;
1645 dst
= dstPtr
[img
] + (dstWidth
- 1) * bpt
;
1646 memcpy(dst
, src
, bpt
);
1648 /* do border along [img][row=dstHeight-1][col=dstWidth-1] */
1649 src
= srcPtr
[img
* 2] + (bytesPerSrcImage
- bpt
);
1650 dst
= dstPtr
[img
] + (bytesPerDstImage
- bpt
);
1651 memcpy(dst
, src
, bpt
);
1655 /* average border pixels from adjacent src image pairs */
1656 ASSERT(srcDepthNB
== 2 * dstDepthNB
);
1657 for (img
= 0; img
< dstDepthNB
; img
++) {
1658 const GLubyte
*srcA
, *srcB
;
1661 /* do border along [img][row=0][col=0] */
1662 srcA
= srcPtr
[img
* 2 + 0];
1663 srcB
= srcPtr
[img
* 2 + srcImageOffset
];
1665 do_row(datatype
, comps
, 1, srcA
, srcB
, 1, dst
);
1667 /* do border along [img][row=dstHeight-1][col=0] */
1668 srcA
= srcPtr
[img
* 2 + 0]
1669 + (srcHeight
- 1) * bytesPerSrcRow
;
1670 srcB
= srcPtr
[img
* 2 + srcImageOffset
]
1671 + (srcHeight
- 1) * bytesPerSrcRow
;
1672 dst
= dstPtr
[img
] + (dstHeight
- 1) * bytesPerDstRow
;
1673 do_row(datatype
, comps
, 1, srcA
, srcB
, 1, dst
);
1675 /* do border along [img][row=0][col=dstWidth-1] */
1676 srcA
= srcPtr
[img
* 2 + 0] + (srcWidth
- 1) * bpt
;
1677 srcB
= srcPtr
[img
* 2 + srcImageOffset
] + (srcWidth
- 1) * bpt
;
1678 dst
= dstPtr
[img
] + (dstWidth
- 1) * bpt
;
1679 do_row(datatype
, comps
, 1, srcA
, srcB
, 1, dst
);
1681 /* do border along [img][row=dstHeight-1][col=dstWidth-1] */
1682 srcA
= srcPtr
[img
* 2 + 0] + (bytesPerSrcImage
- bpt
);
1683 srcB
= srcPtr
[img
* 2 + srcImageOffset
] + (bytesPerSrcImage
- bpt
);
1684 dst
= dstPtr
[img
] + (bytesPerDstImage
- bpt
);
1685 do_row(datatype
, comps
, 1, srcA
, srcB
, 1, dst
);
1693 * Down-sample a texture image to produce the next lower mipmap level.
1694 * \param comps components per texel (1, 2, 3 or 4)
1695 * \param srcData array[slice] of pointers to source image slices
1696 * \param dstData array[slice] of pointers to dest image slices
1697 * \param srcRowStride stride between source rows, in bytes
1698 * \param dstRowStride stride between destination rows, in bytes
1701 _mesa_generate_mipmap_level(GLenum target
,
1702 GLenum datatype
, GLuint comps
,
1704 GLint srcWidth
, GLint srcHeight
, GLint srcDepth
,
1705 const GLubyte
**srcData
,
1707 GLint dstWidth
, GLint dstHeight
, GLint dstDepth
,
1715 make_1d_mipmap(datatype
, comps
, border
,
1716 srcWidth
, srcData
[0],
1717 dstWidth
, dstData
[0]);
1720 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
1721 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
1722 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
1723 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
1724 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
1725 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
1726 make_2d_mipmap(datatype
, comps
, border
,
1727 srcWidth
, srcHeight
, srcData
[0], srcRowStride
,
1728 dstWidth
, dstHeight
, dstData
[0], dstRowStride
);
1731 make_3d_mipmap(datatype
, comps
, border
,
1732 srcWidth
, srcHeight
, srcDepth
,
1733 srcData
, srcRowStride
,
1734 dstWidth
, dstHeight
, dstDepth
,
1735 dstData
, dstRowStride
);
1737 case GL_TEXTURE_1D_ARRAY_EXT
:
1738 assert(srcHeight
== 1);
1739 assert(dstHeight
== 1);
1740 for (i
= 0; i
< dstDepth
; i
++) {
1741 make_1d_mipmap(datatype
, comps
, border
,
1742 srcWidth
, srcData
[i
],
1743 dstWidth
, dstData
[i
]);
1746 case GL_TEXTURE_2D_ARRAY_EXT
:
1747 for (i
= 0; i
< dstDepth
; i
++) {
1748 make_2d_mipmap(datatype
, comps
, border
,
1749 srcWidth
, srcHeight
, srcData
[i
], srcRowStride
,
1750 dstWidth
, dstHeight
, dstData
[i
], dstRowStride
);
1753 case GL_TEXTURE_RECTANGLE_NV
:
1754 case GL_TEXTURE_EXTERNAL_OES
:
1755 /* no mipmaps, do nothing */
1758 _mesa_problem(NULL
, "bad tex target in _mesa_generate_mipmaps");
1765 * compute next (level+1) image size
1766 * \return GL_FALSE if no smaller size can be generated (eg. src is 1x1x1 size)
1769 next_mipmap_level_size(GLenum target
, GLint border
,
1770 GLint srcWidth
, GLint srcHeight
, GLint srcDepth
,
1771 GLint
*dstWidth
, GLint
*dstHeight
, GLint
*dstDepth
)
1773 if (srcWidth
- 2 * border
> 1) {
1774 *dstWidth
= (srcWidth
- 2 * border
) / 2 + 2 * border
;
1777 *dstWidth
= srcWidth
; /* can't go smaller */
1780 if ((srcHeight
- 2 * border
> 1) &&
1781 (target
!= GL_TEXTURE_1D_ARRAY_EXT
)) {
1782 *dstHeight
= (srcHeight
- 2 * border
) / 2 + 2 * border
;
1785 *dstHeight
= srcHeight
; /* can't go smaller */
1788 if ((srcDepth
- 2 * border
> 1) &&
1789 (target
!= GL_TEXTURE_2D_ARRAY_EXT
)) {
1790 *dstDepth
= (srcDepth
- 2 * border
) / 2 + 2 * border
;
1793 *dstDepth
= srcDepth
; /* can't go smaller */
1796 if (*dstWidth
== srcWidth
&&
1797 *dstHeight
== srcHeight
&&
1798 *dstDepth
== srcDepth
) {
1808 * Helper function for mipmap generation.
1809 * Make sure the specified destination mipmap level is the right size/format
1810 * for mipmap generation. If not, (re) allocate it.
1811 * \return GL_TRUE if successful, GL_FALSE if mipmap generation should stop
1814 _mesa_prepare_mipmap_level(struct gl_context
*ctx
,
1815 struct gl_texture_object
*texObj
, GLuint level
,
1816 GLsizei width
, GLsizei height
, GLsizei depth
,
1817 GLsizei border
, GLenum intFormat
, gl_format format
)
1819 const GLuint numFaces
= texObj
->Target
== GL_TEXTURE_CUBE_MAP
? 6 : 1;
1822 if (texObj
->Immutable
) {
1823 /* The texture was created with glTexStorage() so the number/size of
1824 * mipmap levels is fixed and the storage for all images is already
1827 if (!texObj
->Image
[0][level
]) {
1828 /* No more levels to create - we're done */
1832 /* Nothing to do - the texture memory must have already been
1833 * allocated to the right size so we're all set.
1839 for (face
= 0; face
< numFaces
; face
++) {
1840 struct gl_texture_image
*dstImage
;
1844 target
= texObj
->Target
;
1846 target
= GL_TEXTURE_CUBE_MAP_POSITIVE_X
+ face
;
1848 dstImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
1854 if (dstImage
->Width
!= width
||
1855 dstImage
->Height
!= height
||
1856 dstImage
->Depth
!= depth
||
1857 dstImage
->Border
!= border
||
1858 dstImage
->InternalFormat
!= intFormat
||
1859 dstImage
->TexFormat
!= format
) {
1860 /* need to (re)allocate image */
1861 ctx
->Driver
.FreeTextureImageBuffer(ctx
, dstImage
);
1863 _mesa_init_teximage_fields(ctx
, target
, dstImage
,
1864 width
, height
, depth
,
1865 border
, intFormat
, format
);
1867 ctx
->Driver
.AllocTextureImageBuffer(ctx
, dstImage
,
1868 format
, width
, height
, depth
);
1870 /* in case the mipmap level is part of an FBO: */
1871 _mesa_update_fbo_texture(ctx
, texObj
, face
, level
);
1873 ctx
->NewState
|= _NEW_TEXTURE
;
1882 generate_mipmap_uncompressed(struct gl_context
*ctx
, GLenum target
,
1883 struct gl_texture_object
*texObj
,
1884 const struct gl_texture_image
*srcImage
,
1891 _mesa_format_to_type_and_comps(srcImage
->TexFormat
, &datatype
, &comps
);
1893 for (level
= texObj
->BaseLevel
; level
< maxLevel
; level
++) {
1894 /* generate image[level+1] from image[level] */
1895 struct gl_texture_image
*srcImage
, *dstImage
;
1896 GLint srcRowStride
, dstRowStride
;
1897 GLint srcWidth
, srcHeight
, srcDepth
;
1898 GLint dstWidth
, dstHeight
, dstDepth
;
1901 GLboolean nextLevel
;
1902 GLubyte
**srcMaps
, **dstMaps
;
1903 GLboolean success
= GL_TRUE
;
1905 /* get src image parameters */
1906 srcImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
1908 srcWidth
= srcImage
->Width
;
1909 srcHeight
= srcImage
->Height
;
1910 srcDepth
= srcImage
->Depth
;
1911 border
= srcImage
->Border
;
1913 nextLevel
= next_mipmap_level_size(target
, border
,
1914 srcWidth
, srcHeight
, srcDepth
,
1915 &dstWidth
, &dstHeight
, &dstDepth
);
1919 if (!_mesa_prepare_mipmap_level(ctx
, texObj
, level
+ 1,
1920 dstWidth
, dstHeight
, dstDepth
,
1921 border
, srcImage
->InternalFormat
,
1922 srcImage
->TexFormat
)) {
1926 /* get dest gl_texture_image */
1927 dstImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
+ 1);
1929 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "generating mipmaps");
1933 if (target
== GL_TEXTURE_1D_ARRAY
) {
1934 srcDepth
= srcHeight
;
1935 dstDepth
= dstHeight
;
1940 /* Map src texture image slices */
1941 srcMaps
= (GLubyte
**) calloc(srcDepth
, sizeof(GLubyte
*));
1943 for (slice
= 0; slice
< srcDepth
; slice
++) {
1944 ctx
->Driver
.MapTextureImage(ctx
, srcImage
, slice
,
1945 0, 0, srcWidth
, srcHeight
,
1947 &srcMaps
[slice
], &srcRowStride
);
1948 if (!srcMaps
[slice
]) {
1958 /* Map dst texture image slices */
1959 dstMaps
= (GLubyte
**) calloc(dstDepth
, sizeof(GLubyte
*));
1961 for (slice
= 0; slice
< dstDepth
; slice
++) {
1962 ctx
->Driver
.MapTextureImage(ctx
, dstImage
, slice
,
1963 0, 0, dstWidth
, dstHeight
,
1965 &dstMaps
[slice
], &dstRowStride
);
1966 if (!dstMaps
[slice
]) {
1977 /* generate one mipmap level (for 1D/2D/3D/array/etc texture) */
1978 _mesa_generate_mipmap_level(target
, datatype
, comps
, border
,
1979 srcWidth
, srcHeight
, srcDepth
,
1980 (const GLubyte
**) srcMaps
, srcRowStride
,
1981 dstWidth
, dstHeight
, dstDepth
,
1982 dstMaps
, dstRowStride
);
1985 /* Unmap src image slices */
1987 for (slice
= 0; slice
< srcDepth
; slice
++) {
1988 if (srcMaps
[slice
]) {
1989 ctx
->Driver
.UnmapTextureImage(ctx
, srcImage
, slice
);
1995 /* Unmap dst image slices */
1997 for (slice
= 0; slice
< dstDepth
; slice
++) {
1998 if (dstMaps
[slice
]) {
1999 ctx
->Driver
.UnmapTextureImage(ctx
, dstImage
, slice
);
2006 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "mipmap generation");
2009 } /* loop over mipmap levels */
2014 generate_mipmap_compressed(struct gl_context
*ctx
, GLenum target
,
2015 struct gl_texture_object
*texObj
,
2016 struct gl_texture_image
*srcImage
,
2020 gl_format temp_format
;
2022 GLuint temp_src_stride
; /* in bytes */
2023 GLubyte
*temp_src
= NULL
, *temp_dst
= NULL
;
2024 GLenum temp_datatype
;
2025 GLenum temp_base_format
;
2027 /* only two types of compressed textures at this time */
2028 assert(texObj
->Target
== GL_TEXTURE_2D
||
2029 texObj
->Target
== GL_TEXTURE_CUBE_MAP_ARB
);
2032 * Choose a format for the temporary, uncompressed base image.
2033 * Then, get number of components, choose temporary image datatype,
2034 * and get base format.
2036 temp_format
= _mesa_get_uncompressed_format(srcImage
->TexFormat
);
2038 components
= _mesa_format_num_components(temp_format
);
2040 /* Revisit this if we get compressed formats with >8 bits per component */
2041 if (_mesa_get_format_datatype(srcImage
->TexFormat
)
2042 == GL_SIGNED_NORMALIZED
) {
2043 temp_datatype
= GL_BYTE
;
2046 temp_datatype
= GL_UNSIGNED_BYTE
;
2049 temp_base_format
= _mesa_get_format_base_format(temp_format
);
2052 /* allocate storage for the temporary, uncompressed image */
2053 /* 20 extra bytes, just be safe when calling last FetchTexel */
2054 temp_src_stride
= _mesa_format_row_stride(temp_format
, srcImage
->Width
);
2055 temp_src
= (GLubyte
*) malloc(temp_src_stride
* srcImage
->Height
+ 20);
2057 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "generate mipmaps");
2061 /* decompress base image to the temporary */
2063 /* save pixel packing mode */
2064 struct gl_pixelstore_attrib save
= ctx
->Pack
;
2065 /* use default/tight packing parameters */
2066 ctx
->Pack
= ctx
->DefaultPacking
;
2068 /* Get the uncompressed image */
2069 assert(srcImage
->Level
== texObj
->BaseLevel
);
2070 ctx
->Driver
.GetTexImage(ctx
,
2071 temp_base_format
, temp_datatype
,
2072 temp_src
, srcImage
);
2073 /* restore packing mode */
2078 for (level
= texObj
->BaseLevel
; level
< maxLevel
; level
++) {
2079 /* generate image[level+1] from image[level] */
2080 const struct gl_texture_image
*srcImage
;
2081 struct gl_texture_image
*dstImage
;
2082 GLint srcWidth
, srcHeight
, srcDepth
;
2083 GLint dstWidth
, dstHeight
, dstDepth
;
2085 GLboolean nextLevel
;
2086 GLuint temp_dst_stride
; /* in bytes */
2088 /* get src image parameters */
2089 srcImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2091 srcWidth
= srcImage
->Width
;
2092 srcHeight
= srcImage
->Height
;
2093 srcDepth
= srcImage
->Depth
;
2094 border
= srcImage
->Border
;
2096 nextLevel
= next_mipmap_level_size(target
, border
,
2097 srcWidth
, srcHeight
, srcDepth
,
2098 &dstWidth
, &dstHeight
, &dstDepth
);
2102 temp_dst_stride
= _mesa_format_row_stride(temp_format
, dstWidth
);
2104 temp_dst
= (GLubyte
*) malloc(temp_dst_stride
* dstHeight
);
2106 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "generate mipmaps");
2111 /* get dest gl_texture_image */
2112 dstImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
+ 1);
2114 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "generating mipmaps");
2119 /* rescale src image to dest image */
2120 _mesa_generate_mipmap_level(target
, temp_datatype
, components
, border
,
2121 srcWidth
, srcHeight
, srcDepth
,
2122 (const GLubyte
**) &temp_src
,
2124 dstWidth
, dstHeight
, dstDepth
,
2125 &temp_dst
, temp_dst_stride
);
2127 if (!_mesa_prepare_mipmap_level(ctx
, texObj
, level
+ 1,
2128 dstWidth
, dstHeight
, dstDepth
,
2129 border
, srcImage
->InternalFormat
,
2130 srcImage
->TexFormat
)) {
2134 /* The image space was allocated above so use glTexSubImage now */
2135 ctx
->Driver
.TexSubImage2D(ctx
, dstImage
,
2136 0, 0, dstWidth
, dstHeight
,
2137 temp_base_format
, temp_datatype
,
2138 temp_dst
, &ctx
->DefaultPacking
);
2140 /* swap src and dest pointers */
2142 GLubyte
*temp
= temp_src
;
2143 temp_src
= temp_dst
;
2145 temp_src_stride
= temp_dst_stride
;
2147 } /* loop over mipmap levels */
2154 * Automatic mipmap generation.
2155 * This is the fallback/default function for ctx->Driver.GenerateMipmap().
2156 * Generate a complete set of mipmaps from texObj's BaseLevel image.
2157 * Stop at texObj's MaxLevel or when we get to the 1x1 texture.
2158 * For cube maps, target will be one of
2159 * GL_TEXTURE_CUBE_MAP_POSITIVE/NEGATIVE_X/Y/Z; never GL_TEXTURE_CUBE_MAP.
2162 _mesa_generate_mipmap(struct gl_context
*ctx
, GLenum target
,
2163 struct gl_texture_object
*texObj
)
2165 struct gl_texture_image
*srcImage
;
2169 srcImage
= _mesa_select_tex_image(ctx
, texObj
, target
, texObj
->BaseLevel
);
2172 maxLevel
= _mesa_max_texture_levels(ctx
, texObj
->Target
) - 1;
2173 ASSERT(maxLevel
>= 0); /* bad target */
2175 maxLevel
= MIN2(maxLevel
, texObj
->MaxLevel
);
2177 if (_mesa_is_format_compressed(srcImage
->TexFormat
)) {
2178 generate_mipmap_compressed(ctx
, target
, texObj
, srcImage
, maxLevel
);
2180 generate_mipmap_uncompressed(ctx
, target
, texObj
, srcImage
, maxLevel
);