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"
43 bytes_per_pixel(GLenum datatype
, GLuint comps
)
45 GLint b
= _mesa_sizeof_packed_type(datatype
);
48 if (_mesa_type_is_packed(datatype
))
56 * \name Support macros for do_row and do_row_3d
58 * The macro madness is here for two reasons. First, it compacts the code
59 * slightly. Second, it makes it much easier to adjust the specifics of the
60 * filter to tune the rounding characteristics.
63 #define DECLARE_ROW_POINTERS(t, e) \
64 const t(*rowA)[e] = (const t(*)[e]) srcRowA; \
65 const t(*rowB)[e] = (const t(*)[e]) srcRowB; \
66 const t(*rowC)[e] = (const t(*)[e]) srcRowC; \
67 const t(*rowD)[e] = (const t(*)[e]) srcRowD; \
68 t(*dst)[e] = (t(*)[e]) dstRow
70 #define DECLARE_ROW_POINTERS0(t) \
71 const t *rowA = (const t *) srcRowA; \
72 const t *rowB = (const t *) srcRowB; \
73 const t *rowC = (const t *) srcRowC; \
74 const t *rowD = (const t *) srcRowD; \
77 #define FILTER_SUM_3D(Aj, Ak, Bj, Bk, Cj, Ck, Dj, Dk) \
78 ((unsigned) Aj + (unsigned) Ak \
79 + (unsigned) Bj + (unsigned) Bk \
80 + (unsigned) Cj + (unsigned) Ck \
81 + (unsigned) Dj + (unsigned) Dk \
84 #define FILTER_3D(e) \
86 dst[i][e] = FILTER_SUM_3D(rowA[j][e], rowA[k][e], \
87 rowB[j][e], rowB[k][e], \
88 rowC[j][e], rowC[k][e], \
89 rowD[j][e], rowD[k][e]); \
92 #define FILTER_SUM_3D_SIGNED(Aj, Ak, Bj, Bk, Cj, Ck, Dj, Dk) \
99 #define FILTER_3D_SIGNED(e) \
101 dst[i][e] = FILTER_SUM_3D_SIGNED(rowA[j][e], rowA[k][e], \
102 rowB[j][e], rowB[k][e], \
103 rowC[j][e], rowC[k][e], \
104 rowD[j][e], rowD[k][e]); \
107 #define FILTER_F_3D(e) \
109 dst[i][e] = (rowA[j][e] + rowA[k][e] \
110 + rowB[j][e] + rowB[k][e] \
111 + rowC[j][e] + rowC[k][e] \
112 + rowD[j][e] + rowD[k][e]) * 0.125F; \
115 #define FILTER_HF_3D(e) \
117 const GLfloat aj = _mesa_half_to_float(rowA[j][e]); \
118 const GLfloat ak = _mesa_half_to_float(rowA[k][e]); \
119 const GLfloat bj = _mesa_half_to_float(rowB[j][e]); \
120 const GLfloat bk = _mesa_half_to_float(rowB[k][e]); \
121 const GLfloat cj = _mesa_half_to_float(rowC[j][e]); \
122 const GLfloat ck = _mesa_half_to_float(rowC[k][e]); \
123 const GLfloat dj = _mesa_half_to_float(rowD[j][e]); \
124 const GLfloat dk = _mesa_half_to_float(rowD[k][e]); \
125 dst[i][e] = _mesa_float_to_half((aj + ak + bj + bk + cj + ck + dj + dk) \
132 * Average together two rows of a source image to produce a single new
133 * row in the dest image. It's legal for the two source rows to point
134 * to the same data. The source width must be equal to either the
135 * dest width or two times the dest width.
136 * \param datatype GL_UNSIGNED_BYTE, GL_UNSIGNED_SHORT, GL_FLOAT, etc.
137 * \param comps number of components per pixel (1..4)
140 do_row(GLenum datatype
, GLuint comps
, GLint srcWidth
,
141 const GLvoid
*srcRowA
, const GLvoid
*srcRowB
,
142 GLint dstWidth
, GLvoid
*dstRow
)
144 const GLuint k0
= (srcWidth
== dstWidth
) ? 0 : 1;
145 const GLuint colStride
= (srcWidth
== dstWidth
) ? 1 : 2;
150 /* This assertion is no longer valid with non-power-of-2 textures
151 assert(srcWidth == dstWidth || srcWidth == 2 * dstWidth);
154 if (datatype
== GL_UNSIGNED_BYTE
&& comps
== 4) {
156 const GLubyte(*rowA
)[4] = (const GLubyte(*)[4]) srcRowA
;
157 const GLubyte(*rowB
)[4] = (const GLubyte(*)[4]) srcRowB
;
158 GLubyte(*dst
)[4] = (GLubyte(*)[4]) dstRow
;
159 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
160 i
++, j
+= colStride
, k
+= colStride
) {
161 dst
[i
][0] = (rowA
[j
][0] + rowA
[k
][0] + rowB
[j
][0] + rowB
[k
][0]) / 4;
162 dst
[i
][1] = (rowA
[j
][1] + rowA
[k
][1] + rowB
[j
][1] + rowB
[k
][1]) / 4;
163 dst
[i
][2] = (rowA
[j
][2] + rowA
[k
][2] + rowB
[j
][2] + rowB
[k
][2]) / 4;
164 dst
[i
][3] = (rowA
[j
][3] + rowA
[k
][3] + rowB
[j
][3] + rowB
[k
][3]) / 4;
167 else if (datatype
== GL_UNSIGNED_BYTE
&& comps
== 3) {
169 const GLubyte(*rowA
)[3] = (const GLubyte(*)[3]) srcRowA
;
170 const GLubyte(*rowB
)[3] = (const GLubyte(*)[3]) srcRowB
;
171 GLubyte(*dst
)[3] = (GLubyte(*)[3]) dstRow
;
172 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
173 i
++, j
+= colStride
, k
+= colStride
) {
174 dst
[i
][0] = (rowA
[j
][0] + rowA
[k
][0] + rowB
[j
][0] + rowB
[k
][0]) / 4;
175 dst
[i
][1] = (rowA
[j
][1] + rowA
[k
][1] + rowB
[j
][1] + rowB
[k
][1]) / 4;
176 dst
[i
][2] = (rowA
[j
][2] + rowA
[k
][2] + rowB
[j
][2] + rowB
[k
][2]) / 4;
179 else if (datatype
== GL_UNSIGNED_BYTE
&& comps
== 2) {
181 const GLubyte(*rowA
)[2] = (const GLubyte(*)[2]) srcRowA
;
182 const GLubyte(*rowB
)[2] = (const GLubyte(*)[2]) srcRowB
;
183 GLubyte(*dst
)[2] = (GLubyte(*)[2]) dstRow
;
184 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
185 i
++, j
+= colStride
, k
+= colStride
) {
186 dst
[i
][0] = (rowA
[j
][0] + rowA
[k
][0] + rowB
[j
][0] + rowB
[k
][0]) >> 2;
187 dst
[i
][1] = (rowA
[j
][1] + rowA
[k
][1] + rowB
[j
][1] + rowB
[k
][1]) >> 2;
190 else if (datatype
== GL_UNSIGNED_BYTE
&& comps
== 1) {
192 const GLubyte
*rowA
= (const GLubyte
*) srcRowA
;
193 const GLubyte
*rowB
= (const GLubyte
*) srcRowB
;
194 GLubyte
*dst
= (GLubyte
*) dstRow
;
195 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
196 i
++, j
+= colStride
, k
+= colStride
) {
197 dst
[i
] = (rowA
[j
] + rowA
[k
] + rowB
[j
] + rowB
[k
]) >> 2;
201 else if (datatype
== GL_BYTE
&& comps
== 4) {
203 const GLbyte(*rowA
)[4] = (const GLbyte(*)[4]) srcRowA
;
204 const GLbyte(*rowB
)[4] = (const GLbyte(*)[4]) srcRowB
;
205 GLbyte(*dst
)[4] = (GLbyte(*)[4]) dstRow
;
206 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
207 i
++, j
+= colStride
, k
+= colStride
) {
208 dst
[i
][0] = (rowA
[j
][0] + rowA
[k
][0] + rowB
[j
][0] + rowB
[k
][0]) / 4;
209 dst
[i
][1] = (rowA
[j
][1] + rowA
[k
][1] + rowB
[j
][1] + rowB
[k
][1]) / 4;
210 dst
[i
][2] = (rowA
[j
][2] + rowA
[k
][2] + rowB
[j
][2] + rowB
[k
][2]) / 4;
211 dst
[i
][3] = (rowA
[j
][3] + rowA
[k
][3] + rowB
[j
][3] + rowB
[k
][3]) / 4;
214 else if (datatype
== GL_BYTE
&& comps
== 3) {
216 const GLbyte(*rowA
)[3] = (const GLbyte(*)[3]) srcRowA
;
217 const GLbyte(*rowB
)[3] = (const GLbyte(*)[3]) srcRowB
;
218 GLbyte(*dst
)[3] = (GLbyte(*)[3]) dstRow
;
219 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
220 i
++, j
+= colStride
, k
+= colStride
) {
221 dst
[i
][0] = (rowA
[j
][0] + rowA
[k
][0] + rowB
[j
][0] + rowB
[k
][0]) / 4;
222 dst
[i
][1] = (rowA
[j
][1] + rowA
[k
][1] + rowB
[j
][1] + rowB
[k
][1]) / 4;
223 dst
[i
][2] = (rowA
[j
][2] + rowA
[k
][2] + rowB
[j
][2] + rowB
[k
][2]) / 4;
226 else if (datatype
== GL_BYTE
&& comps
== 2) {
228 const GLbyte(*rowA
)[2] = (const GLbyte(*)[2]) srcRowA
;
229 const GLbyte(*rowB
)[2] = (const GLbyte(*)[2]) srcRowB
;
230 GLbyte(*dst
)[2] = (GLbyte(*)[2]) dstRow
;
231 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
232 i
++, j
+= colStride
, k
+= colStride
) {
233 dst
[i
][0] = (rowA
[j
][0] + rowA
[k
][0] + rowB
[j
][0] + rowB
[k
][0]) / 4;
234 dst
[i
][1] = (rowA
[j
][1] + rowA
[k
][1] + rowB
[j
][1] + rowB
[k
][1]) / 4;
237 else if (datatype
== GL_BYTE
&& comps
== 1) {
239 const GLbyte
*rowA
= (const GLbyte
*) srcRowA
;
240 const GLbyte
*rowB
= (const GLbyte
*) srcRowB
;
241 GLbyte
*dst
= (GLbyte
*) dstRow
;
242 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
243 i
++, j
+= colStride
, k
+= colStride
) {
244 dst
[i
] = (rowA
[j
] + rowA
[k
] + rowB
[j
] + rowB
[k
]) / 4;
248 else if (datatype
== GL_UNSIGNED_SHORT
&& comps
== 4) {
250 const GLushort(*rowA
)[4] = (const GLushort(*)[4]) srcRowA
;
251 const GLushort(*rowB
)[4] = (const GLushort(*)[4]) srcRowB
;
252 GLushort(*dst
)[4] = (GLushort(*)[4]) dstRow
;
253 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
254 i
++, j
+= colStride
, k
+= colStride
) {
255 dst
[i
][0] = (rowA
[j
][0] + rowA
[k
][0] + rowB
[j
][0] + rowB
[k
][0]) / 4;
256 dst
[i
][1] = (rowA
[j
][1] + rowA
[k
][1] + rowB
[j
][1] + rowB
[k
][1]) / 4;
257 dst
[i
][2] = (rowA
[j
][2] + rowA
[k
][2] + rowB
[j
][2] + rowB
[k
][2]) / 4;
258 dst
[i
][3] = (rowA
[j
][3] + rowA
[k
][3] + rowB
[j
][3] + rowB
[k
][3]) / 4;
261 else if (datatype
== GL_UNSIGNED_SHORT
&& comps
== 3) {
263 const GLushort(*rowA
)[3] = (const GLushort(*)[3]) srcRowA
;
264 const GLushort(*rowB
)[3] = (const GLushort(*)[3]) srcRowB
;
265 GLushort(*dst
)[3] = (GLushort(*)[3]) dstRow
;
266 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
267 i
++, j
+= colStride
, k
+= colStride
) {
268 dst
[i
][0] = (rowA
[j
][0] + rowA
[k
][0] + rowB
[j
][0] + rowB
[k
][0]) / 4;
269 dst
[i
][1] = (rowA
[j
][1] + rowA
[k
][1] + rowB
[j
][1] + rowB
[k
][1]) / 4;
270 dst
[i
][2] = (rowA
[j
][2] + rowA
[k
][2] + rowB
[j
][2] + rowB
[k
][2]) / 4;
273 else if (datatype
== GL_UNSIGNED_SHORT
&& comps
== 2) {
275 const GLushort(*rowA
)[2] = (const GLushort(*)[2]) srcRowA
;
276 const GLushort(*rowB
)[2] = (const GLushort(*)[2]) srcRowB
;
277 GLushort(*dst
)[2] = (GLushort(*)[2]) dstRow
;
278 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
279 i
++, j
+= colStride
, k
+= colStride
) {
280 dst
[i
][0] = (rowA
[j
][0] + rowA
[k
][0] + rowB
[j
][0] + rowB
[k
][0]) / 4;
281 dst
[i
][1] = (rowA
[j
][1] + rowA
[k
][1] + rowB
[j
][1] + rowB
[k
][1]) / 4;
284 else if (datatype
== GL_UNSIGNED_SHORT
&& comps
== 1) {
286 const GLushort
*rowA
= (const GLushort
*) srcRowA
;
287 const GLushort
*rowB
= (const GLushort
*) srcRowB
;
288 GLushort
*dst
= (GLushort
*) dstRow
;
289 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
290 i
++, j
+= colStride
, k
+= colStride
) {
291 dst
[i
] = (rowA
[j
] + rowA
[k
] + rowB
[j
] + rowB
[k
]) / 4;
295 else if (datatype
== GL_SHORT
&& comps
== 4) {
297 const GLshort(*rowA
)[4] = (const GLshort(*)[4]) srcRowA
;
298 const GLshort(*rowB
)[4] = (const GLshort(*)[4]) srcRowB
;
299 GLshort(*dst
)[4] = (GLshort(*)[4]) dstRow
;
300 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
301 i
++, j
+= colStride
, k
+= colStride
) {
302 dst
[i
][0] = (rowA
[j
][0] + rowA
[k
][0] + rowB
[j
][0] + rowB
[k
][0]) / 4;
303 dst
[i
][1] = (rowA
[j
][1] + rowA
[k
][1] + rowB
[j
][1] + rowB
[k
][1]) / 4;
304 dst
[i
][2] = (rowA
[j
][2] + rowA
[k
][2] + rowB
[j
][2] + rowB
[k
][2]) / 4;
305 dst
[i
][3] = (rowA
[j
][3] + rowA
[k
][3] + rowB
[j
][3] + rowB
[k
][3]) / 4;
308 else if (datatype
== GL_SHORT
&& comps
== 3) {
310 const GLshort(*rowA
)[3] = (const GLshort(*)[3]) srcRowA
;
311 const GLshort(*rowB
)[3] = (const GLshort(*)[3]) srcRowB
;
312 GLshort(*dst
)[3] = (GLshort(*)[3]) dstRow
;
313 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
314 i
++, j
+= colStride
, k
+= colStride
) {
315 dst
[i
][0] = (rowA
[j
][0] + rowA
[k
][0] + rowB
[j
][0] + rowB
[k
][0]) / 4;
316 dst
[i
][1] = (rowA
[j
][1] + rowA
[k
][1] + rowB
[j
][1] + rowB
[k
][1]) / 4;
317 dst
[i
][2] = (rowA
[j
][2] + rowA
[k
][2] + rowB
[j
][2] + rowB
[k
][2]) / 4;
320 else if (datatype
== GL_SHORT
&& comps
== 2) {
322 const GLshort(*rowA
)[2] = (const GLshort(*)[2]) srcRowA
;
323 const GLshort(*rowB
)[2] = (const GLshort(*)[2]) srcRowB
;
324 GLshort(*dst
)[2] = (GLshort(*)[2]) dstRow
;
325 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
326 i
++, j
+= colStride
, k
+= colStride
) {
327 dst
[i
][0] = (rowA
[j
][0] + rowA
[k
][0] + rowB
[j
][0] + rowB
[k
][0]) / 4;
328 dst
[i
][1] = (rowA
[j
][1] + rowA
[k
][1] + rowB
[j
][1] + rowB
[k
][1]) / 4;
331 else if (datatype
== GL_SHORT
&& comps
== 1) {
333 const GLshort
*rowA
= (const GLshort
*) srcRowA
;
334 const GLshort
*rowB
= (const GLshort
*) srcRowB
;
335 GLshort
*dst
= (GLshort
*) dstRow
;
336 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
337 i
++, j
+= colStride
, k
+= colStride
) {
338 dst
[i
] = (rowA
[j
] + rowA
[k
] + rowB
[j
] + rowB
[k
]) / 4;
342 else if (datatype
== GL_FLOAT
&& comps
== 4) {
344 const GLfloat(*rowA
)[4] = (const GLfloat(*)[4]) srcRowA
;
345 const GLfloat(*rowB
)[4] = (const GLfloat(*)[4]) srcRowB
;
346 GLfloat(*dst
)[4] = (GLfloat(*)[4]) dstRow
;
347 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
348 i
++, j
+= colStride
, k
+= colStride
) {
349 dst
[i
][0] = (rowA
[j
][0] + rowA
[k
][0] +
350 rowB
[j
][0] + rowB
[k
][0]) * 0.25F
;
351 dst
[i
][1] = (rowA
[j
][1] + rowA
[k
][1] +
352 rowB
[j
][1] + rowB
[k
][1]) * 0.25F
;
353 dst
[i
][2] = (rowA
[j
][2] + rowA
[k
][2] +
354 rowB
[j
][2] + rowB
[k
][2]) * 0.25F
;
355 dst
[i
][3] = (rowA
[j
][3] + rowA
[k
][3] +
356 rowB
[j
][3] + rowB
[k
][3]) * 0.25F
;
359 else if (datatype
== GL_FLOAT
&& comps
== 3) {
361 const GLfloat(*rowA
)[3] = (const GLfloat(*)[3]) srcRowA
;
362 const GLfloat(*rowB
)[3] = (const GLfloat(*)[3]) srcRowB
;
363 GLfloat(*dst
)[3] = (GLfloat(*)[3]) dstRow
;
364 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
365 i
++, j
+= colStride
, k
+= colStride
) {
366 dst
[i
][0] = (rowA
[j
][0] + rowA
[k
][0] +
367 rowB
[j
][0] + rowB
[k
][0]) * 0.25F
;
368 dst
[i
][1] = (rowA
[j
][1] + rowA
[k
][1] +
369 rowB
[j
][1] + rowB
[k
][1]) * 0.25F
;
370 dst
[i
][2] = (rowA
[j
][2] + rowA
[k
][2] +
371 rowB
[j
][2] + rowB
[k
][2]) * 0.25F
;
374 else if (datatype
== GL_FLOAT
&& comps
== 2) {
376 const GLfloat(*rowA
)[2] = (const GLfloat(*)[2]) srcRowA
;
377 const GLfloat(*rowB
)[2] = (const GLfloat(*)[2]) srcRowB
;
378 GLfloat(*dst
)[2] = (GLfloat(*)[2]) dstRow
;
379 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
380 i
++, j
+= colStride
, k
+= colStride
) {
381 dst
[i
][0] = (rowA
[j
][0] + rowA
[k
][0] +
382 rowB
[j
][0] + rowB
[k
][0]) * 0.25F
;
383 dst
[i
][1] = (rowA
[j
][1] + rowA
[k
][1] +
384 rowB
[j
][1] + rowB
[k
][1]) * 0.25F
;
387 else if (datatype
== GL_FLOAT
&& comps
== 1) {
389 const GLfloat
*rowA
= (const GLfloat
*) srcRowA
;
390 const GLfloat
*rowB
= (const GLfloat
*) srcRowB
;
391 GLfloat
*dst
= (GLfloat
*) dstRow
;
392 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
393 i
++, j
+= colStride
, k
+= colStride
) {
394 dst
[i
] = (rowA
[j
] + rowA
[k
] + rowB
[j
] + rowB
[k
]) * 0.25F
;
398 else if (datatype
== GL_HALF_FLOAT_ARB
&& comps
== 4) {
399 GLuint i
, j
, k
, comp
;
400 const GLhalfARB(*rowA
)[4] = (const GLhalfARB(*)[4]) srcRowA
;
401 const GLhalfARB(*rowB
)[4] = (const GLhalfARB(*)[4]) srcRowB
;
402 GLhalfARB(*dst
)[4] = (GLhalfARB(*)[4]) dstRow
;
403 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
404 i
++, j
+= colStride
, k
+= colStride
) {
405 for (comp
= 0; comp
< 4; comp
++) {
406 GLfloat aj
, ak
, bj
, bk
;
407 aj
= _mesa_half_to_float(rowA
[j
][comp
]);
408 ak
= _mesa_half_to_float(rowA
[k
][comp
]);
409 bj
= _mesa_half_to_float(rowB
[j
][comp
]);
410 bk
= _mesa_half_to_float(rowB
[k
][comp
]);
411 dst
[i
][comp
] = _mesa_float_to_half((aj
+ ak
+ bj
+ bk
) * 0.25F
);
415 else if (datatype
== GL_HALF_FLOAT_ARB
&& comps
== 3) {
416 GLuint i
, j
, k
, comp
;
417 const GLhalfARB(*rowA
)[3] = (const GLhalfARB(*)[3]) srcRowA
;
418 const GLhalfARB(*rowB
)[3] = (const GLhalfARB(*)[3]) srcRowB
;
419 GLhalfARB(*dst
)[3] = (GLhalfARB(*)[3]) dstRow
;
420 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
421 i
++, j
+= colStride
, k
+= colStride
) {
422 for (comp
= 0; comp
< 3; comp
++) {
423 GLfloat aj
, ak
, bj
, bk
;
424 aj
= _mesa_half_to_float(rowA
[j
][comp
]);
425 ak
= _mesa_half_to_float(rowA
[k
][comp
]);
426 bj
= _mesa_half_to_float(rowB
[j
][comp
]);
427 bk
= _mesa_half_to_float(rowB
[k
][comp
]);
428 dst
[i
][comp
] = _mesa_float_to_half((aj
+ ak
+ bj
+ bk
) * 0.25F
);
432 else if (datatype
== GL_HALF_FLOAT_ARB
&& comps
== 2) {
433 GLuint i
, j
, k
, comp
;
434 const GLhalfARB(*rowA
)[2] = (const GLhalfARB(*)[2]) srcRowA
;
435 const GLhalfARB(*rowB
)[2] = (const GLhalfARB(*)[2]) srcRowB
;
436 GLhalfARB(*dst
)[2] = (GLhalfARB(*)[2]) dstRow
;
437 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
438 i
++, j
+= colStride
, k
+= colStride
) {
439 for (comp
= 0; comp
< 2; comp
++) {
440 GLfloat aj
, ak
, bj
, bk
;
441 aj
= _mesa_half_to_float(rowA
[j
][comp
]);
442 ak
= _mesa_half_to_float(rowA
[k
][comp
]);
443 bj
= _mesa_half_to_float(rowB
[j
][comp
]);
444 bk
= _mesa_half_to_float(rowB
[k
][comp
]);
445 dst
[i
][comp
] = _mesa_float_to_half((aj
+ ak
+ bj
+ bk
) * 0.25F
);
449 else if (datatype
== GL_HALF_FLOAT_ARB
&& comps
== 1) {
451 const GLhalfARB
*rowA
= (const GLhalfARB
*) srcRowA
;
452 const GLhalfARB
*rowB
= (const GLhalfARB
*) srcRowB
;
453 GLhalfARB
*dst
= (GLhalfARB
*) dstRow
;
454 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
455 i
++, j
+= colStride
, k
+= colStride
) {
456 GLfloat aj
, ak
, bj
, bk
;
457 aj
= _mesa_half_to_float(rowA
[j
]);
458 ak
= _mesa_half_to_float(rowA
[k
]);
459 bj
= _mesa_half_to_float(rowB
[j
]);
460 bk
= _mesa_half_to_float(rowB
[k
]);
461 dst
[i
] = _mesa_float_to_half((aj
+ ak
+ bj
+ bk
) * 0.25F
);
465 else if (datatype
== GL_UNSIGNED_INT
&& comps
== 1) {
467 const GLuint
*rowA
= (const GLuint
*) srcRowA
;
468 const GLuint
*rowB
= (const GLuint
*) srcRowB
;
469 GLuint
*dst
= (GLuint
*) dstRow
;
470 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
471 i
++, j
+= colStride
, k
+= colStride
) {
472 dst
[i
] = (GLfloat
)(rowA
[j
] / 4 + rowA
[k
] / 4 + rowB
[j
] / 4 + rowB
[k
] / 4);
476 else if (datatype
== GL_UNSIGNED_SHORT_5_6_5
&& comps
== 3) {
478 const GLushort
*rowA
= (const GLushort
*) srcRowA
;
479 const GLushort
*rowB
= (const GLushort
*) srcRowB
;
480 GLushort
*dst
= (GLushort
*) dstRow
;
481 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
482 i
++, j
+= colStride
, k
+= colStride
) {
483 const GLint rowAr0
= rowA
[j
] & 0x1f;
484 const GLint rowAr1
= rowA
[k
] & 0x1f;
485 const GLint rowBr0
= rowB
[j
] & 0x1f;
486 const GLint rowBr1
= rowB
[k
] & 0x1f;
487 const GLint rowAg0
= (rowA
[j
] >> 5) & 0x3f;
488 const GLint rowAg1
= (rowA
[k
] >> 5) & 0x3f;
489 const GLint rowBg0
= (rowB
[j
] >> 5) & 0x3f;
490 const GLint rowBg1
= (rowB
[k
] >> 5) & 0x3f;
491 const GLint rowAb0
= (rowA
[j
] >> 11) & 0x1f;
492 const GLint rowAb1
= (rowA
[k
] >> 11) & 0x1f;
493 const GLint rowBb0
= (rowB
[j
] >> 11) & 0x1f;
494 const GLint rowBb1
= (rowB
[k
] >> 11) & 0x1f;
495 const GLint red
= (rowAr0
+ rowAr1
+ rowBr0
+ rowBr1
) >> 2;
496 const GLint green
= (rowAg0
+ rowAg1
+ rowBg0
+ rowBg1
) >> 2;
497 const GLint blue
= (rowAb0
+ rowAb1
+ rowBb0
+ rowBb1
) >> 2;
498 dst
[i
] = (blue
<< 11) | (green
<< 5) | red
;
501 else if (datatype
== GL_UNSIGNED_SHORT_4_4_4_4
&& comps
== 4) {
503 const GLushort
*rowA
= (const GLushort
*) srcRowA
;
504 const GLushort
*rowB
= (const GLushort
*) srcRowB
;
505 GLushort
*dst
= (GLushort
*) dstRow
;
506 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
507 i
++, j
+= colStride
, k
+= colStride
) {
508 const GLint rowAr0
= rowA
[j
] & 0xf;
509 const GLint rowAr1
= rowA
[k
] & 0xf;
510 const GLint rowBr0
= rowB
[j
] & 0xf;
511 const GLint rowBr1
= rowB
[k
] & 0xf;
512 const GLint rowAg0
= (rowA
[j
] >> 4) & 0xf;
513 const GLint rowAg1
= (rowA
[k
] >> 4) & 0xf;
514 const GLint rowBg0
= (rowB
[j
] >> 4) & 0xf;
515 const GLint rowBg1
= (rowB
[k
] >> 4) & 0xf;
516 const GLint rowAb0
= (rowA
[j
] >> 8) & 0xf;
517 const GLint rowAb1
= (rowA
[k
] >> 8) & 0xf;
518 const GLint rowBb0
= (rowB
[j
] >> 8) & 0xf;
519 const GLint rowBb1
= (rowB
[k
] >> 8) & 0xf;
520 const GLint rowAa0
= (rowA
[j
] >> 12) & 0xf;
521 const GLint rowAa1
= (rowA
[k
] >> 12) & 0xf;
522 const GLint rowBa0
= (rowB
[j
] >> 12) & 0xf;
523 const GLint rowBa1
= (rowB
[k
] >> 12) & 0xf;
524 const GLint red
= (rowAr0
+ rowAr1
+ rowBr0
+ rowBr1
) >> 2;
525 const GLint green
= (rowAg0
+ rowAg1
+ rowBg0
+ rowBg1
) >> 2;
526 const GLint blue
= (rowAb0
+ rowAb1
+ rowBb0
+ rowBb1
) >> 2;
527 const GLint alpha
= (rowAa0
+ rowAa1
+ rowBa0
+ rowBa1
) >> 2;
528 dst
[i
] = (alpha
<< 12) | (blue
<< 8) | (green
<< 4) | red
;
531 else if (datatype
== GL_UNSIGNED_SHORT_1_5_5_5_REV
&& comps
== 4) {
533 const GLushort
*rowA
= (const GLushort
*) srcRowA
;
534 const GLushort
*rowB
= (const GLushort
*) srcRowB
;
535 GLushort
*dst
= (GLushort
*) dstRow
;
536 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
537 i
++, j
+= colStride
, k
+= colStride
) {
538 const GLint rowAr0
= rowA
[j
] & 0x1f;
539 const GLint rowAr1
= rowA
[k
] & 0x1f;
540 const GLint rowBr0
= rowB
[j
] & 0x1f;
541 const GLint rowBr1
= rowB
[k
] & 0x1f;
542 const GLint rowAg0
= (rowA
[j
] >> 5) & 0x1f;
543 const GLint rowAg1
= (rowA
[k
] >> 5) & 0x1f;
544 const GLint rowBg0
= (rowB
[j
] >> 5) & 0x1f;
545 const GLint rowBg1
= (rowB
[k
] >> 5) & 0x1f;
546 const GLint rowAb0
= (rowA
[j
] >> 10) & 0x1f;
547 const GLint rowAb1
= (rowA
[k
] >> 10) & 0x1f;
548 const GLint rowBb0
= (rowB
[j
] >> 10) & 0x1f;
549 const GLint rowBb1
= (rowB
[k
] >> 10) & 0x1f;
550 const GLint rowAa0
= (rowA
[j
] >> 15) & 0x1;
551 const GLint rowAa1
= (rowA
[k
] >> 15) & 0x1;
552 const GLint rowBa0
= (rowB
[j
] >> 15) & 0x1;
553 const GLint rowBa1
= (rowB
[k
] >> 15) & 0x1;
554 const GLint red
= (rowAr0
+ rowAr1
+ rowBr0
+ rowBr1
) >> 2;
555 const GLint green
= (rowAg0
+ rowAg1
+ rowBg0
+ rowBg1
) >> 2;
556 const GLint blue
= (rowAb0
+ rowAb1
+ rowBb0
+ rowBb1
) >> 2;
557 const GLint alpha
= (rowAa0
+ rowAa1
+ rowBa0
+ rowBa1
) >> 2;
558 dst
[i
] = (alpha
<< 15) | (blue
<< 10) | (green
<< 5) | red
;
561 else if (datatype
== GL_UNSIGNED_SHORT_5_5_5_1
&& comps
== 4) {
563 const GLushort
*rowA
= (const GLushort
*) srcRowA
;
564 const GLushort
*rowB
= (const GLushort
*) srcRowB
;
565 GLushort
*dst
= (GLushort
*) dstRow
;
566 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
567 i
++, j
+= colStride
, k
+= colStride
) {
568 const GLint rowAr0
= (rowA
[j
] >> 11) & 0x1f;
569 const GLint rowAr1
= (rowA
[k
] >> 11) & 0x1f;
570 const GLint rowBr0
= (rowB
[j
] >> 11) & 0x1f;
571 const GLint rowBr1
= (rowB
[k
] >> 11) & 0x1f;
572 const GLint rowAg0
= (rowA
[j
] >> 6) & 0x1f;
573 const GLint rowAg1
= (rowA
[k
] >> 6) & 0x1f;
574 const GLint rowBg0
= (rowB
[j
] >> 6) & 0x1f;
575 const GLint rowBg1
= (rowB
[k
] >> 6) & 0x1f;
576 const GLint rowAb0
= (rowA
[j
] >> 1) & 0x1f;
577 const GLint rowAb1
= (rowA
[k
] >> 1) & 0x1f;
578 const GLint rowBb0
= (rowB
[j
] >> 1) & 0x1f;
579 const GLint rowBb1
= (rowB
[k
] >> 1) & 0x1f;
580 const GLint rowAa0
= (rowA
[j
] & 0x1);
581 const GLint rowAa1
= (rowA
[k
] & 0x1);
582 const GLint rowBa0
= (rowB
[j
] & 0x1);
583 const GLint rowBa1
= (rowB
[k
] & 0x1);
584 const GLint red
= (rowAr0
+ rowAr1
+ rowBr0
+ rowBr1
) >> 2;
585 const GLint green
= (rowAg0
+ rowAg1
+ rowBg0
+ rowBg1
) >> 2;
586 const GLint blue
= (rowAb0
+ rowAb1
+ rowBb0
+ rowBb1
) >> 2;
587 const GLint alpha
= (rowAa0
+ rowAa1
+ rowBa0
+ rowBa1
) >> 2;
588 dst
[i
] = (red
<< 11) | (green
<< 6) | (blue
<< 1) | alpha
;
592 else if (datatype
== GL_UNSIGNED_BYTE_3_3_2
&& comps
== 3) {
594 const GLubyte
*rowA
= (const GLubyte
*) srcRowA
;
595 const GLubyte
*rowB
= (const GLubyte
*) srcRowB
;
596 GLubyte
*dst
= (GLubyte
*) dstRow
;
597 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
598 i
++, j
+= colStride
, k
+= colStride
) {
599 const GLint rowAr0
= rowA
[j
] & 0x3;
600 const GLint rowAr1
= rowA
[k
] & 0x3;
601 const GLint rowBr0
= rowB
[j
] & 0x3;
602 const GLint rowBr1
= rowB
[k
] & 0x3;
603 const GLint rowAg0
= (rowA
[j
] >> 2) & 0x7;
604 const GLint rowAg1
= (rowA
[k
] >> 2) & 0x7;
605 const GLint rowBg0
= (rowB
[j
] >> 2) & 0x7;
606 const GLint rowBg1
= (rowB
[k
] >> 2) & 0x7;
607 const GLint rowAb0
= (rowA
[j
] >> 5) & 0x7;
608 const GLint rowAb1
= (rowA
[k
] >> 5) & 0x7;
609 const GLint rowBb0
= (rowB
[j
] >> 5) & 0x7;
610 const GLint rowBb1
= (rowB
[k
] >> 5) & 0x7;
611 const GLint red
= (rowAr0
+ rowAr1
+ rowBr0
+ rowBr1
) >> 2;
612 const GLint green
= (rowAg0
+ rowAg1
+ rowBg0
+ rowBg1
) >> 2;
613 const GLint blue
= (rowAb0
+ rowAb1
+ rowBb0
+ rowBb1
) >> 2;
614 dst
[i
] = (blue
<< 5) | (green
<< 2) | red
;
618 else if (datatype
== MESA_UNSIGNED_BYTE_4_4
&& comps
== 2) {
620 const GLubyte
*rowA
= (const GLubyte
*) srcRowA
;
621 const GLubyte
*rowB
= (const GLubyte
*) srcRowB
;
622 GLubyte
*dst
= (GLubyte
*) dstRow
;
623 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
624 i
++, j
+= colStride
, k
+= colStride
) {
625 const GLint rowAr0
= rowA
[j
] & 0xf;
626 const GLint rowAr1
= rowA
[k
] & 0xf;
627 const GLint rowBr0
= rowB
[j
] & 0xf;
628 const GLint rowBr1
= rowB
[k
] & 0xf;
629 const GLint rowAg0
= (rowA
[j
] >> 4) & 0xf;
630 const GLint rowAg1
= (rowA
[k
] >> 4) & 0xf;
631 const GLint rowBg0
= (rowB
[j
] >> 4) & 0xf;
632 const GLint rowBg1
= (rowB
[k
] >> 4) & 0xf;
633 const GLint r
= (rowAr0
+ rowAr1
+ rowBr0
+ rowBr1
) >> 2;
634 const GLint g
= (rowAg0
+ rowAg1
+ rowBg0
+ rowBg1
) >> 2;
635 dst
[i
] = (g
<< 4) | r
;
639 else if (datatype
== GL_UNSIGNED_INT_2_10_10_10_REV
&& comps
== 4) {
641 const GLuint
*rowA
= (const GLuint
*) srcRowA
;
642 const GLuint
*rowB
= (const GLuint
*) srcRowB
;
643 GLuint
*dst
= (GLuint
*) dstRow
;
644 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
645 i
++, j
+= colStride
, k
+= colStride
) {
646 const GLint rowAr0
= rowA
[j
] & 0x3ff;
647 const GLint rowAr1
= rowA
[k
] & 0x3ff;
648 const GLint rowBr0
= rowB
[j
] & 0x3ff;
649 const GLint rowBr1
= rowB
[k
] & 0x3ff;
650 const GLint rowAg0
= (rowA
[j
] >> 10) & 0x3ff;
651 const GLint rowAg1
= (rowA
[k
] >> 10) & 0x3ff;
652 const GLint rowBg0
= (rowB
[j
] >> 10) & 0x3ff;
653 const GLint rowBg1
= (rowB
[k
] >> 10) & 0x3ff;
654 const GLint rowAb0
= (rowA
[j
] >> 20) & 0x3ff;
655 const GLint rowAb1
= (rowA
[k
] >> 20) & 0x3ff;
656 const GLint rowBb0
= (rowB
[j
] >> 20) & 0x3ff;
657 const GLint rowBb1
= (rowB
[k
] >> 20) & 0x3ff;
658 const GLint rowAa0
= (rowA
[j
] >> 30) & 0x3;
659 const GLint rowAa1
= (rowA
[k
] >> 30) & 0x3;
660 const GLint rowBa0
= (rowB
[j
] >> 30) & 0x3;
661 const GLint rowBa1
= (rowB
[k
] >> 30) & 0x3;
662 const GLint red
= (rowAr0
+ rowAr1
+ rowBr0
+ rowBr1
) >> 2;
663 const GLint green
= (rowAg0
+ rowAg1
+ rowBg0
+ rowBg1
) >> 2;
664 const GLint blue
= (rowAb0
+ rowAb1
+ rowBb0
+ rowBb1
) >> 2;
665 const GLint alpha
= (rowAa0
+ rowAa1
+ rowBa0
+ rowBa1
) >> 2;
666 dst
[i
] = (alpha
<< 30) | (blue
<< 20) | (green
<< 10) | red
;
670 else if (datatype
== GL_UNSIGNED_INT_5_9_9_9_REV
&& comps
== 3) {
672 const GLuint
*rowA
= (const GLuint
*) srcRowA
;
673 const GLuint
*rowB
= (const GLuint
*) srcRowB
;
674 GLuint
*dst
= (GLuint
*)dstRow
;
675 GLfloat res
[3], rowAj
[3], rowBj
[3], rowAk
[3], rowBk
[3];
676 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
677 i
++, j
+= colStride
, k
+= colStride
) {
678 rgb9e5_to_float3(rowA
[j
], rowAj
);
679 rgb9e5_to_float3(rowB
[j
], rowBj
);
680 rgb9e5_to_float3(rowA
[k
], rowAk
);
681 rgb9e5_to_float3(rowB
[k
], rowBk
);
682 res
[0] = (rowAj
[0] + rowAk
[0] + rowBj
[0] + rowBk
[0]) * 0.25F
;
683 res
[1] = (rowAj
[1] + rowAk
[1] + rowBj
[1] + rowBk
[1]) * 0.25F
;
684 res
[2] = (rowAj
[2] + rowAk
[2] + rowBj
[2] + rowBk
[2]) * 0.25F
;
685 dst
[i
] = float3_to_rgb9e5(res
);
690 _mesa_problem(NULL
, "bad format in do_row()");
696 * Average together four rows of a source image to produce a single new
697 * row in the dest image. It's legal for the two source rows to point
698 * to the same data. The source width must be equal to either the
699 * dest width or two times the dest width.
701 * \param datatype GL pixel type \c GL_UNSIGNED_BYTE, \c GL_UNSIGNED_SHORT,
703 * \param comps number of components per pixel (1..4)
704 * \param srcWidth Width of a row in the source data
705 * \param srcRowA Pointer to one of the rows of source data
706 * \param srcRowB Pointer to one of the rows of source data
707 * \param srcRowC Pointer to one of the rows of source data
708 * \param srcRowD Pointer to one of the rows of source data
709 * \param dstWidth Width of a row in the destination data
710 * \param srcRowA Pointer to the row of destination data
713 do_row_3D(GLenum datatype
, GLuint comps
, GLint srcWidth
,
714 const GLvoid
*srcRowA
, const GLvoid
*srcRowB
,
715 const GLvoid
*srcRowC
, const GLvoid
*srcRowD
,
716 GLint dstWidth
, GLvoid
*dstRow
)
718 const GLuint k0
= (srcWidth
== dstWidth
) ? 0 : 1;
719 const GLuint colStride
= (srcWidth
== dstWidth
) ? 1 : 2;
725 if ((datatype
== GL_UNSIGNED_BYTE
) && (comps
== 4)) {
726 DECLARE_ROW_POINTERS(GLubyte
, 4);
728 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
729 i
++, j
+= colStride
, k
+= colStride
) {
736 else if ((datatype
== GL_UNSIGNED_BYTE
) && (comps
== 3)) {
737 DECLARE_ROW_POINTERS(GLubyte
, 3);
739 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
740 i
++, j
+= colStride
, k
+= colStride
) {
746 else if ((datatype
== GL_UNSIGNED_BYTE
) && (comps
== 2)) {
747 DECLARE_ROW_POINTERS(GLubyte
, 2);
749 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
750 i
++, j
+= colStride
, k
+= colStride
) {
755 else if ((datatype
== GL_UNSIGNED_BYTE
) && (comps
== 1)) {
756 DECLARE_ROW_POINTERS(GLubyte
, 1);
758 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
759 i
++, j
+= colStride
, k
+= colStride
) {
763 else if ((datatype
== GL_BYTE
) && (comps
== 4)) {
764 DECLARE_ROW_POINTERS(GLbyte
, 4);
766 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
767 i
++, j
+= colStride
, k
+= colStride
) {
774 else if ((datatype
== GL_BYTE
) && (comps
== 3)) {
775 DECLARE_ROW_POINTERS(GLbyte
, 3);
777 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
778 i
++, j
+= colStride
, k
+= colStride
) {
784 else if ((datatype
== GL_BYTE
) && (comps
== 2)) {
785 DECLARE_ROW_POINTERS(GLbyte
, 2);
787 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
788 i
++, j
+= colStride
, k
+= colStride
) {
793 else if ((datatype
== GL_BYTE
) && (comps
== 1)) {
794 DECLARE_ROW_POINTERS(GLbyte
, 1);
796 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
797 i
++, j
+= colStride
, k
+= colStride
) {
801 else if ((datatype
== GL_UNSIGNED_SHORT
) && (comps
== 4)) {
802 DECLARE_ROW_POINTERS(GLushort
, 4);
804 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
805 i
++, j
+= colStride
, k
+= colStride
) {
812 else if ((datatype
== GL_UNSIGNED_SHORT
) && (comps
== 3)) {
813 DECLARE_ROW_POINTERS(GLushort
, 3);
815 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
816 i
++, j
+= colStride
, k
+= colStride
) {
822 else if ((datatype
== GL_UNSIGNED_SHORT
) && (comps
== 2)) {
823 DECLARE_ROW_POINTERS(GLushort
, 2);
825 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
826 i
++, j
+= colStride
, k
+= colStride
) {
831 else if ((datatype
== GL_UNSIGNED_SHORT
) && (comps
== 1)) {
832 DECLARE_ROW_POINTERS(GLushort
, 1);
834 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
835 i
++, j
+= colStride
, k
+= colStride
) {
839 else if ((datatype
== GL_SHORT
) && (comps
== 4)) {
840 DECLARE_ROW_POINTERS(GLshort
, 4);
842 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
843 i
++, j
+= colStride
, k
+= colStride
) {
850 else if ((datatype
== GL_SHORT
) && (comps
== 3)) {
851 DECLARE_ROW_POINTERS(GLshort
, 3);
853 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
854 i
++, j
+= colStride
, k
+= colStride
) {
860 else if ((datatype
== GL_SHORT
) && (comps
== 2)) {
861 DECLARE_ROW_POINTERS(GLshort
, 2);
863 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
864 i
++, j
+= colStride
, k
+= colStride
) {
869 else if ((datatype
== GL_SHORT
) && (comps
== 1)) {
870 DECLARE_ROW_POINTERS(GLshort
, 1);
872 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
873 i
++, j
+= colStride
, k
+= colStride
) {
877 else if ((datatype
== GL_FLOAT
) && (comps
== 4)) {
878 DECLARE_ROW_POINTERS(GLfloat
, 4);
880 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
881 i
++, j
+= colStride
, k
+= colStride
) {
888 else if ((datatype
== GL_FLOAT
) && (comps
== 3)) {
889 DECLARE_ROW_POINTERS(GLfloat
, 3);
891 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
892 i
++, j
+= colStride
, k
+= colStride
) {
898 else if ((datatype
== GL_FLOAT
) && (comps
== 2)) {
899 DECLARE_ROW_POINTERS(GLfloat
, 2);
901 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
902 i
++, j
+= colStride
, k
+= colStride
) {
907 else if ((datatype
== GL_FLOAT
) && (comps
== 1)) {
908 DECLARE_ROW_POINTERS(GLfloat
, 1);
910 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
911 i
++, j
+= colStride
, k
+= colStride
) {
915 else if ((datatype
== GL_HALF_FLOAT_ARB
) && (comps
== 4)) {
916 DECLARE_ROW_POINTERS(GLhalfARB
, 4);
918 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
919 i
++, j
+= colStride
, k
+= colStride
) {
926 else if ((datatype
== GL_HALF_FLOAT_ARB
) && (comps
== 3)) {
927 DECLARE_ROW_POINTERS(GLhalfARB
, 4);
929 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
930 i
++, j
+= colStride
, k
+= colStride
) {
936 else if ((datatype
== GL_HALF_FLOAT_ARB
) && (comps
== 2)) {
937 DECLARE_ROW_POINTERS(GLhalfARB
, 4);
939 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
940 i
++, j
+= colStride
, k
+= colStride
) {
945 else if ((datatype
== GL_HALF_FLOAT_ARB
) && (comps
== 1)) {
946 DECLARE_ROW_POINTERS(GLhalfARB
, 4);
948 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
949 i
++, j
+= colStride
, k
+= colStride
) {
953 else if ((datatype
== GL_UNSIGNED_INT
) && (comps
== 1)) {
954 const GLuint
*rowA
= (const GLuint
*) srcRowA
;
955 const GLuint
*rowB
= (const GLuint
*) srcRowB
;
956 const GLuint
*rowC
= (const GLuint
*) srcRowC
;
957 const GLuint
*rowD
= (const GLuint
*) srcRowD
;
958 GLfloat
*dst
= (GLfloat
*) dstRow
;
960 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
961 i
++, j
+= colStride
, k
+= colStride
) {
962 const uint64_t tmp
= (((uint64_t) rowA
[j
] + (uint64_t) rowA
[k
])
963 + ((uint64_t) rowB
[j
] + (uint64_t) rowB
[k
])
964 + ((uint64_t) rowC
[j
] + (uint64_t) rowC
[k
])
965 + ((uint64_t) rowD
[j
] + (uint64_t) rowD
[k
]));
966 dst
[i
] = (GLfloat
)((double) tmp
* 0.125);
969 else if ((datatype
== GL_UNSIGNED_SHORT_5_6_5
) && (comps
== 3)) {
970 DECLARE_ROW_POINTERS0(GLushort
);
972 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
973 i
++, j
+= colStride
, k
+= colStride
) {
974 const GLint rowAr0
= rowA
[j
] & 0x1f;
975 const GLint rowAr1
= rowA
[k
] & 0x1f;
976 const GLint rowBr0
= rowB
[j
] & 0x1f;
977 const GLint rowBr1
= rowB
[k
] & 0x1f;
978 const GLint rowCr0
= rowC
[j
] & 0x1f;
979 const GLint rowCr1
= rowC
[k
] & 0x1f;
980 const GLint rowDr0
= rowD
[j
] & 0x1f;
981 const GLint rowDr1
= rowD
[k
] & 0x1f;
982 const GLint rowAg0
= (rowA
[j
] >> 5) & 0x3f;
983 const GLint rowAg1
= (rowA
[k
] >> 5) & 0x3f;
984 const GLint rowBg0
= (rowB
[j
] >> 5) & 0x3f;
985 const GLint rowBg1
= (rowB
[k
] >> 5) & 0x3f;
986 const GLint rowCg0
= (rowC
[j
] >> 5) & 0x3f;
987 const GLint rowCg1
= (rowC
[k
] >> 5) & 0x3f;
988 const GLint rowDg0
= (rowD
[j
] >> 5) & 0x3f;
989 const GLint rowDg1
= (rowD
[k
] >> 5) & 0x3f;
990 const GLint rowAb0
= (rowA
[j
] >> 11) & 0x1f;
991 const GLint rowAb1
= (rowA
[k
] >> 11) & 0x1f;
992 const GLint rowBb0
= (rowB
[j
] >> 11) & 0x1f;
993 const GLint rowBb1
= (rowB
[k
] >> 11) & 0x1f;
994 const GLint rowCb0
= (rowC
[j
] >> 11) & 0x1f;
995 const GLint rowCb1
= (rowC
[k
] >> 11) & 0x1f;
996 const GLint rowDb0
= (rowD
[j
] >> 11) & 0x1f;
997 const GLint rowDb1
= (rowD
[k
] >> 11) & 0x1f;
998 const GLint r
= FILTER_SUM_3D(rowAr0
, rowAr1
, rowBr0
, rowBr1
,
999 rowCr0
, rowCr1
, rowDr0
, rowDr1
);
1000 const GLint g
= FILTER_SUM_3D(rowAg0
, rowAg1
, rowBg0
, rowBg1
,
1001 rowCg0
, rowCg1
, rowDg0
, rowDg1
);
1002 const GLint b
= FILTER_SUM_3D(rowAb0
, rowAb1
, rowBb0
, rowBb1
,
1003 rowCb0
, rowCb1
, rowDb0
, rowDb1
);
1004 dst
[i
] = (b
<< 11) | (g
<< 5) | r
;
1007 else if ((datatype
== GL_UNSIGNED_SHORT_4_4_4_4
) && (comps
== 4)) {
1008 DECLARE_ROW_POINTERS0(GLushort
);
1010 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
1011 i
++, j
+= colStride
, k
+= colStride
) {
1012 const GLint rowAr0
= rowA
[j
] & 0xf;
1013 const GLint rowAr1
= rowA
[k
] & 0xf;
1014 const GLint rowBr0
= rowB
[j
] & 0xf;
1015 const GLint rowBr1
= rowB
[k
] & 0xf;
1016 const GLint rowCr0
= rowC
[j
] & 0xf;
1017 const GLint rowCr1
= rowC
[k
] & 0xf;
1018 const GLint rowDr0
= rowD
[j
] & 0xf;
1019 const GLint rowDr1
= rowD
[k
] & 0xf;
1020 const GLint rowAg0
= (rowA
[j
] >> 4) & 0xf;
1021 const GLint rowAg1
= (rowA
[k
] >> 4) & 0xf;
1022 const GLint rowBg0
= (rowB
[j
] >> 4) & 0xf;
1023 const GLint rowBg1
= (rowB
[k
] >> 4) & 0xf;
1024 const GLint rowCg0
= (rowC
[j
] >> 4) & 0xf;
1025 const GLint rowCg1
= (rowC
[k
] >> 4) & 0xf;
1026 const GLint rowDg0
= (rowD
[j
] >> 4) & 0xf;
1027 const GLint rowDg1
= (rowD
[k
] >> 4) & 0xf;
1028 const GLint rowAb0
= (rowA
[j
] >> 8) & 0xf;
1029 const GLint rowAb1
= (rowA
[k
] >> 8) & 0xf;
1030 const GLint rowBb0
= (rowB
[j
] >> 8) & 0xf;
1031 const GLint rowBb1
= (rowB
[k
] >> 8) & 0xf;
1032 const GLint rowCb0
= (rowC
[j
] >> 8) & 0xf;
1033 const GLint rowCb1
= (rowC
[k
] >> 8) & 0xf;
1034 const GLint rowDb0
= (rowD
[j
] >> 8) & 0xf;
1035 const GLint rowDb1
= (rowD
[k
] >> 8) & 0xf;
1036 const GLint rowAa0
= (rowA
[j
] >> 12) & 0xf;
1037 const GLint rowAa1
= (rowA
[k
] >> 12) & 0xf;
1038 const GLint rowBa0
= (rowB
[j
] >> 12) & 0xf;
1039 const GLint rowBa1
= (rowB
[k
] >> 12) & 0xf;
1040 const GLint rowCa0
= (rowC
[j
] >> 12) & 0xf;
1041 const GLint rowCa1
= (rowC
[k
] >> 12) & 0xf;
1042 const GLint rowDa0
= (rowD
[j
] >> 12) & 0xf;
1043 const GLint rowDa1
= (rowD
[k
] >> 12) & 0xf;
1044 const GLint r
= FILTER_SUM_3D(rowAr0
, rowAr1
, rowBr0
, rowBr1
,
1045 rowCr0
, rowCr1
, rowDr0
, rowDr1
);
1046 const GLint g
= FILTER_SUM_3D(rowAg0
, rowAg1
, rowBg0
, rowBg1
,
1047 rowCg0
, rowCg1
, rowDg0
, rowDg1
);
1048 const GLint b
= FILTER_SUM_3D(rowAb0
, rowAb1
, rowBb0
, rowBb1
,
1049 rowCb0
, rowCb1
, rowDb0
, rowDb1
);
1050 const GLint a
= FILTER_SUM_3D(rowAa0
, rowAa1
, rowBa0
, rowBa1
,
1051 rowCa0
, rowCa1
, rowDa0
, rowDa1
);
1053 dst
[i
] = (a
<< 12) | (b
<< 8) | (g
<< 4) | r
;
1056 else if ((datatype
== GL_UNSIGNED_SHORT_1_5_5_5_REV
) && (comps
== 4)) {
1057 DECLARE_ROW_POINTERS0(GLushort
);
1059 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
1060 i
++, j
+= colStride
, k
+= colStride
) {
1061 const GLint rowAr0
= rowA
[j
] & 0x1f;
1062 const GLint rowAr1
= rowA
[k
] & 0x1f;
1063 const GLint rowBr0
= rowB
[j
] & 0x1f;
1064 const GLint rowBr1
= rowB
[k
] & 0x1f;
1065 const GLint rowCr0
= rowC
[j
] & 0x1f;
1066 const GLint rowCr1
= rowC
[k
] & 0x1f;
1067 const GLint rowDr0
= rowD
[j
] & 0x1f;
1068 const GLint rowDr1
= rowD
[k
] & 0x1f;
1069 const GLint rowAg0
= (rowA
[j
] >> 5) & 0x1f;
1070 const GLint rowAg1
= (rowA
[k
] >> 5) & 0x1f;
1071 const GLint rowBg0
= (rowB
[j
] >> 5) & 0x1f;
1072 const GLint rowBg1
= (rowB
[k
] >> 5) & 0x1f;
1073 const GLint rowCg0
= (rowC
[j
] >> 5) & 0x1f;
1074 const GLint rowCg1
= (rowC
[k
] >> 5) & 0x1f;
1075 const GLint rowDg0
= (rowD
[j
] >> 5) & 0x1f;
1076 const GLint rowDg1
= (rowD
[k
] >> 5) & 0x1f;
1077 const GLint rowAb0
= (rowA
[j
] >> 10) & 0x1f;
1078 const GLint rowAb1
= (rowA
[k
] >> 10) & 0x1f;
1079 const GLint rowBb0
= (rowB
[j
] >> 10) & 0x1f;
1080 const GLint rowBb1
= (rowB
[k
] >> 10) & 0x1f;
1081 const GLint rowCb0
= (rowC
[j
] >> 10) & 0x1f;
1082 const GLint rowCb1
= (rowC
[k
] >> 10) & 0x1f;
1083 const GLint rowDb0
= (rowD
[j
] >> 10) & 0x1f;
1084 const GLint rowDb1
= (rowD
[k
] >> 10) & 0x1f;
1085 const GLint rowAa0
= (rowA
[j
] >> 15) & 0x1;
1086 const GLint rowAa1
= (rowA
[k
] >> 15) & 0x1;
1087 const GLint rowBa0
= (rowB
[j
] >> 15) & 0x1;
1088 const GLint rowBa1
= (rowB
[k
] >> 15) & 0x1;
1089 const GLint rowCa0
= (rowC
[j
] >> 15) & 0x1;
1090 const GLint rowCa1
= (rowC
[k
] >> 15) & 0x1;
1091 const GLint rowDa0
= (rowD
[j
] >> 15) & 0x1;
1092 const GLint rowDa1
= (rowD
[k
] >> 15) & 0x1;
1093 const GLint r
= FILTER_SUM_3D(rowAr0
, rowAr1
, rowBr0
, rowBr1
,
1094 rowCr0
, rowCr1
, rowDr0
, rowDr1
);
1095 const GLint g
= FILTER_SUM_3D(rowAg0
, rowAg1
, rowBg0
, rowBg1
,
1096 rowCg0
, rowCg1
, rowDg0
, rowDg1
);
1097 const GLint b
= FILTER_SUM_3D(rowAb0
, rowAb1
, rowBb0
, rowBb1
,
1098 rowCb0
, rowCb1
, rowDb0
, rowDb1
);
1099 const GLint a
= FILTER_SUM_3D(rowAa0
, rowAa1
, rowBa0
, rowBa1
,
1100 rowCa0
, rowCa1
, rowDa0
, rowDa1
);
1102 dst
[i
] = (a
<< 15) | (b
<< 10) | (g
<< 5) | r
;
1105 else if ((datatype
== GL_UNSIGNED_SHORT_5_5_5_1
) && (comps
== 4)) {
1106 DECLARE_ROW_POINTERS0(GLushort
);
1108 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
1109 i
++, j
+= colStride
, k
+= colStride
) {
1110 const GLint rowAr0
= (rowA
[j
] >> 11) & 0x1f;
1111 const GLint rowAr1
= (rowA
[k
] >> 11) & 0x1f;
1112 const GLint rowBr0
= (rowB
[j
] >> 11) & 0x1f;
1113 const GLint rowBr1
= (rowB
[k
] >> 11) & 0x1f;
1114 const GLint rowCr0
= (rowC
[j
] >> 11) & 0x1f;
1115 const GLint rowCr1
= (rowC
[k
] >> 11) & 0x1f;
1116 const GLint rowDr0
= (rowD
[j
] >> 11) & 0x1f;
1117 const GLint rowDr1
= (rowD
[k
] >> 11) & 0x1f;
1118 const GLint rowAg0
= (rowA
[j
] >> 6) & 0x1f;
1119 const GLint rowAg1
= (rowA
[k
] >> 6) & 0x1f;
1120 const GLint rowBg0
= (rowB
[j
] >> 6) & 0x1f;
1121 const GLint rowBg1
= (rowB
[k
] >> 6) & 0x1f;
1122 const GLint rowCg0
= (rowC
[j
] >> 6) & 0x1f;
1123 const GLint rowCg1
= (rowC
[k
] >> 6) & 0x1f;
1124 const GLint rowDg0
= (rowD
[j
] >> 6) & 0x1f;
1125 const GLint rowDg1
= (rowD
[k
] >> 6) & 0x1f;
1126 const GLint rowAb0
= (rowA
[j
] >> 1) & 0x1f;
1127 const GLint rowAb1
= (rowA
[k
] >> 1) & 0x1f;
1128 const GLint rowBb0
= (rowB
[j
] >> 1) & 0x1f;
1129 const GLint rowBb1
= (rowB
[k
] >> 1) & 0x1f;
1130 const GLint rowCb0
= (rowC
[j
] >> 1) & 0x1f;
1131 const GLint rowCb1
= (rowC
[k
] >> 1) & 0x1f;
1132 const GLint rowDb0
= (rowD
[j
] >> 1) & 0x1f;
1133 const GLint rowDb1
= (rowD
[k
] >> 1) & 0x1f;
1134 const GLint rowAa0
= (rowA
[j
] & 0x1);
1135 const GLint rowAa1
= (rowA
[k
] & 0x1);
1136 const GLint rowBa0
= (rowB
[j
] & 0x1);
1137 const GLint rowBa1
= (rowB
[k
] & 0x1);
1138 const GLint rowCa0
= (rowC
[j
] & 0x1);
1139 const GLint rowCa1
= (rowC
[k
] & 0x1);
1140 const GLint rowDa0
= (rowD
[j
] & 0x1);
1141 const GLint rowDa1
= (rowD
[k
] & 0x1);
1142 const GLint r
= FILTER_SUM_3D(rowAr0
, rowAr1
, rowBr0
, rowBr1
,
1143 rowCr0
, rowCr1
, rowDr0
, rowDr1
);
1144 const GLint g
= FILTER_SUM_3D(rowAg0
, rowAg1
, rowBg0
, rowBg1
,
1145 rowCg0
, rowCg1
, rowDg0
, rowDg1
);
1146 const GLint b
= FILTER_SUM_3D(rowAb0
, rowAb1
, rowBb0
, rowBb1
,
1147 rowCb0
, rowCb1
, rowDb0
, rowDb1
);
1148 const GLint a
= FILTER_SUM_3D(rowAa0
, rowAa1
, rowBa0
, rowBa1
,
1149 rowCa0
, rowCa1
, rowDa0
, rowDa1
);
1151 dst
[i
] = (r
<< 11) | (g
<< 6) | (b
<< 1) | a
;
1154 else if ((datatype
== GL_UNSIGNED_BYTE_3_3_2
) && (comps
== 3)) {
1155 DECLARE_ROW_POINTERS0(GLubyte
);
1157 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
1158 i
++, j
+= colStride
, k
+= colStride
) {
1159 const GLint rowAr0
= rowA
[j
] & 0x3;
1160 const GLint rowAr1
= rowA
[k
] & 0x3;
1161 const GLint rowBr0
= rowB
[j
] & 0x3;
1162 const GLint rowBr1
= rowB
[k
] & 0x3;
1163 const GLint rowCr0
= rowC
[j
] & 0x3;
1164 const GLint rowCr1
= rowC
[k
] & 0x3;
1165 const GLint rowDr0
= rowD
[j
] & 0x3;
1166 const GLint rowDr1
= rowD
[k
] & 0x3;
1167 const GLint rowAg0
= (rowA
[j
] >> 2) & 0x7;
1168 const GLint rowAg1
= (rowA
[k
] >> 2) & 0x7;
1169 const GLint rowBg0
= (rowB
[j
] >> 2) & 0x7;
1170 const GLint rowBg1
= (rowB
[k
] >> 2) & 0x7;
1171 const GLint rowCg0
= (rowC
[j
] >> 2) & 0x7;
1172 const GLint rowCg1
= (rowC
[k
] >> 2) & 0x7;
1173 const GLint rowDg0
= (rowD
[j
] >> 2) & 0x7;
1174 const GLint rowDg1
= (rowD
[k
] >> 2) & 0x7;
1175 const GLint rowAb0
= (rowA
[j
] >> 5) & 0x7;
1176 const GLint rowAb1
= (rowA
[k
] >> 5) & 0x7;
1177 const GLint rowBb0
= (rowB
[j
] >> 5) & 0x7;
1178 const GLint rowBb1
= (rowB
[k
] >> 5) & 0x7;
1179 const GLint rowCb0
= (rowC
[j
] >> 5) & 0x7;
1180 const GLint rowCb1
= (rowC
[k
] >> 5) & 0x7;
1181 const GLint rowDb0
= (rowD
[j
] >> 5) & 0x7;
1182 const GLint rowDb1
= (rowD
[k
] >> 5) & 0x7;
1183 const GLint r
= FILTER_SUM_3D(rowAr0
, rowAr1
, rowBr0
, rowBr1
,
1184 rowCr0
, rowCr1
, rowDr0
, rowDr1
);
1185 const GLint g
= FILTER_SUM_3D(rowAg0
, rowAg1
, rowBg0
, rowBg1
,
1186 rowCg0
, rowCg1
, rowDg0
, rowDg1
);
1187 const GLint b
= FILTER_SUM_3D(rowAb0
, rowAb1
, rowBb0
, rowBb1
,
1188 rowCb0
, rowCb1
, rowDb0
, rowDb1
);
1189 dst
[i
] = (b
<< 5) | (g
<< 2) | r
;
1192 else if (datatype
== MESA_UNSIGNED_BYTE_4_4
&& comps
== 2) {
1193 DECLARE_ROW_POINTERS0(GLubyte
);
1195 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
1196 i
++, j
+= colStride
, k
+= colStride
) {
1197 const GLint rowAr0
= rowA
[j
] & 0xf;
1198 const GLint rowAr1
= rowA
[k
] & 0xf;
1199 const GLint rowBr0
= rowB
[j
] & 0xf;
1200 const GLint rowBr1
= rowB
[k
] & 0xf;
1201 const GLint rowCr0
= rowC
[j
] & 0xf;
1202 const GLint rowCr1
= rowC
[k
] & 0xf;
1203 const GLint rowDr0
= rowD
[j
] & 0xf;
1204 const GLint rowDr1
= rowD
[k
] & 0xf;
1205 const GLint rowAg0
= (rowA
[j
] >> 4) & 0xf;
1206 const GLint rowAg1
= (rowA
[k
] >> 4) & 0xf;
1207 const GLint rowBg0
= (rowB
[j
] >> 4) & 0xf;
1208 const GLint rowBg1
= (rowB
[k
] >> 4) & 0xf;
1209 const GLint rowCg0
= (rowC
[j
] >> 4) & 0xf;
1210 const GLint rowCg1
= (rowC
[k
] >> 4) & 0xf;
1211 const GLint rowDg0
= (rowD
[j
] >> 4) & 0xf;
1212 const GLint rowDg1
= (rowD
[k
] >> 4) & 0xf;
1213 const GLint r
= FILTER_SUM_3D(rowAr0
, rowAr1
, rowBr0
, rowBr1
,
1214 rowCr0
, rowCr1
, rowDr0
, rowDr1
);
1215 const GLint g
= FILTER_SUM_3D(rowAg0
, rowAg1
, rowBg0
, rowBg1
,
1216 rowCg0
, rowCg1
, rowDg0
, rowDg1
);
1217 dst
[i
] = (g
<< 4) | r
;
1220 else if ((datatype
== GL_UNSIGNED_INT_2_10_10_10_REV
) && (comps
== 4)) {
1221 DECLARE_ROW_POINTERS0(GLuint
);
1223 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
1224 i
++, j
+= colStride
, k
+= colStride
) {
1225 const GLint rowAr0
= rowA
[j
] & 0x3ff;
1226 const GLint rowAr1
= rowA
[k
] & 0x3ff;
1227 const GLint rowBr0
= rowB
[j
] & 0x3ff;
1228 const GLint rowBr1
= rowB
[k
] & 0x3ff;
1229 const GLint rowCr0
= rowC
[j
] & 0x3ff;
1230 const GLint rowCr1
= rowC
[k
] & 0x3ff;
1231 const GLint rowDr0
= rowD
[j
] & 0x3ff;
1232 const GLint rowDr1
= rowD
[k
] & 0x3ff;
1233 const GLint rowAg0
= (rowA
[j
] >> 10) & 0x3ff;
1234 const GLint rowAg1
= (rowA
[k
] >> 10) & 0x3ff;
1235 const GLint rowBg0
= (rowB
[j
] >> 10) & 0x3ff;
1236 const GLint rowBg1
= (rowB
[k
] >> 10) & 0x3ff;
1237 const GLint rowCg0
= (rowC
[j
] >> 10) & 0x3ff;
1238 const GLint rowCg1
= (rowC
[k
] >> 10) & 0x3ff;
1239 const GLint rowDg0
= (rowD
[j
] >> 10) & 0x3ff;
1240 const GLint rowDg1
= (rowD
[k
] >> 10) & 0x3ff;
1241 const GLint rowAb0
= (rowA
[j
] >> 20) & 0x3ff;
1242 const GLint rowAb1
= (rowA
[k
] >> 20) & 0x3ff;
1243 const GLint rowBb0
= (rowB
[j
] >> 20) & 0x3ff;
1244 const GLint rowBb1
= (rowB
[k
] >> 20) & 0x3ff;
1245 const GLint rowCb0
= (rowC
[j
] >> 20) & 0x3ff;
1246 const GLint rowCb1
= (rowC
[k
] >> 20) & 0x3ff;
1247 const GLint rowDb0
= (rowD
[j
] >> 20) & 0x3ff;
1248 const GLint rowDb1
= (rowD
[k
] >> 20) & 0x3ff;
1249 const GLint rowAa0
= (rowA
[j
] >> 30) & 0x3;
1250 const GLint rowAa1
= (rowA
[k
] >> 30) & 0x3;
1251 const GLint rowBa0
= (rowB
[j
] >> 30) & 0x3;
1252 const GLint rowBa1
= (rowB
[k
] >> 30) & 0x3;
1253 const GLint rowCa0
= (rowC
[j
] >> 30) & 0x3;
1254 const GLint rowCa1
= (rowC
[k
] >> 30) & 0x3;
1255 const GLint rowDa0
= (rowD
[j
] >> 30) & 0x3;
1256 const GLint rowDa1
= (rowD
[k
] >> 30) & 0x3;
1257 const GLint r
= FILTER_SUM_3D(rowAr0
, rowAr1
, rowBr0
, rowBr1
,
1258 rowCr0
, rowCr1
, rowDr0
, rowDr1
);
1259 const GLint g
= FILTER_SUM_3D(rowAg0
, rowAg1
, rowBg0
, rowBg1
,
1260 rowCg0
, rowCg1
, rowDg0
, rowDg1
);
1261 const GLint b
= FILTER_SUM_3D(rowAb0
, rowAb1
, rowBb0
, rowBb1
,
1262 rowCb0
, rowCb1
, rowDb0
, rowDb1
);
1263 const GLint a
= FILTER_SUM_3D(rowAa0
, rowAa1
, rowBa0
, rowBa1
,
1264 rowCa0
, rowCa1
, rowDa0
, rowDa1
);
1266 dst
[i
] = (a
<< 30) | (b
<< 20) | (g
<< 10) | r
;
1270 else if (datatype
== GL_UNSIGNED_INT_5_9_9_9_REV
&& comps
== 3) {
1271 DECLARE_ROW_POINTERS0(GLuint
);
1274 GLfloat rowAj
[3], rowBj
[3], rowCj
[3], rowDj
[3];
1275 GLfloat rowAk
[3], rowBk
[3], rowCk
[3], rowDk
[3];
1277 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
1278 i
++, j
+= colStride
, k
+= colStride
) {
1279 rgb9e5_to_float3(rowA
[j
], rowAj
);
1280 rgb9e5_to_float3(rowB
[j
], rowBj
);
1281 rgb9e5_to_float3(rowC
[j
], rowCj
);
1282 rgb9e5_to_float3(rowD
[j
], rowDj
);
1283 rgb9e5_to_float3(rowA
[k
], rowAk
);
1284 rgb9e5_to_float3(rowB
[k
], rowBk
);
1285 rgb9e5_to_float3(rowC
[k
], rowCk
);
1286 rgb9e5_to_float3(rowD
[k
], rowDk
);
1287 res
[0] = (rowAj
[0] + rowAk
[0] + rowBj
[0] + rowBk
[0] +
1288 rowCj
[0] + rowCk
[0] + rowDj
[0] + rowDk
[0]) * 0.125F
;
1289 res
[1] = (rowAj
[1] + rowAk
[1] + rowBj
[1] + rowBk
[1] +
1290 rowCj
[1] + rowCk
[1] + rowDj
[1] + rowDk
[1]) * 0.125F
;
1291 res
[2] = (rowAj
[2] + rowAk
[2] + rowBj
[2] + rowBk
[2] +
1292 rowCj
[2] + rowCk
[2] + rowDj
[2] + rowDk
[2]) * 0.125F
;
1293 dst
[i
] = float3_to_rgb9e5(res
);
1298 _mesa_problem(NULL
, "bad format in do_row()");
1304 * These functions generate a 1/2-size mipmap image from a source image.
1305 * Texture borders are handled by copying or averaging the source image's
1306 * border texels, depending on the scale-down factor.
1310 make_1d_mipmap(GLenum datatype
, GLuint comps
, GLint border
,
1311 GLint srcWidth
, const GLubyte
*srcPtr
,
1312 GLint dstWidth
, GLubyte
*dstPtr
)
1314 const GLint bpt
= bytes_per_pixel(datatype
, comps
);
1318 /* skip the border pixel, if any */
1319 src
= srcPtr
+ border
* bpt
;
1320 dst
= dstPtr
+ border
* bpt
;
1322 /* we just duplicate the input row, kind of hack, saves code */
1323 do_row(datatype
, comps
, srcWidth
- 2 * border
, src
, src
,
1324 dstWidth
- 2 * border
, dst
);
1327 /* copy left-most pixel from source */
1330 memcpy(dstPtr
, srcPtr
, bpt
);
1331 /* copy right-most pixel from source */
1332 memcpy(dstPtr
+ (dstWidth
- 1) * bpt
,
1333 srcPtr
+ (srcWidth
- 1) * bpt
,
1340 make_2d_mipmap(GLenum datatype
, GLuint comps
, GLint border
,
1341 GLint srcWidth
, GLint srcHeight
,
1342 const GLubyte
*srcPtr
, GLint srcRowStride
,
1343 GLint dstWidth
, GLint dstHeight
,
1344 GLubyte
*dstPtr
, GLint dstRowStride
)
1346 const GLint bpt
= bytes_per_pixel(datatype
, comps
);
1347 const GLint srcWidthNB
= srcWidth
- 2 * border
; /* sizes w/out border */
1348 const GLint dstWidthNB
= dstWidth
- 2 * border
;
1349 const GLint dstHeightNB
= dstHeight
- 2 * border
;
1350 const GLint srcRowBytes
= bpt
* srcRowStride
;
1351 const GLint dstRowBytes
= bpt
* dstRowStride
;
1352 const GLubyte
*srcA
, *srcB
;
1354 GLint row
, srcRowStep
;
1356 /* Compute src and dst pointers, skipping any border */
1357 srcA
= srcPtr
+ border
* ((srcWidth
+ 1) * bpt
);
1358 if (srcHeight
> 1 && srcHeight
> dstHeight
) {
1359 /* sample from two source rows */
1360 srcB
= srcA
+ srcRowBytes
;
1364 /* sample from one source row */
1369 dst
= dstPtr
+ border
* ((dstWidth
+ 1) * bpt
);
1371 for (row
= 0; row
< dstHeightNB
; row
++) {
1372 do_row(datatype
, comps
, srcWidthNB
, srcA
, srcB
,
1374 srcA
+= srcRowStep
* srcRowBytes
;
1375 srcB
+= srcRowStep
* srcRowBytes
;
1379 /* This is ugly but probably won't be used much */
1381 /* fill in dest border */
1382 /* lower-left border pixel */
1385 memcpy(dstPtr
, srcPtr
, bpt
);
1386 /* lower-right border pixel */
1387 memcpy(dstPtr
+ (dstWidth
- 1) * bpt
,
1388 srcPtr
+ (srcWidth
- 1) * bpt
, bpt
);
1389 /* upper-left border pixel */
1390 memcpy(dstPtr
+ dstWidth
* (dstHeight
- 1) * bpt
,
1391 srcPtr
+ srcWidth
* (srcHeight
- 1) * bpt
, bpt
);
1392 /* upper-right border pixel */
1393 memcpy(dstPtr
+ (dstWidth
* dstHeight
- 1) * bpt
,
1394 srcPtr
+ (srcWidth
* srcHeight
- 1) * bpt
, bpt
);
1396 do_row(datatype
, comps
, srcWidthNB
,
1399 dstWidthNB
, dstPtr
+ bpt
);
1401 do_row(datatype
, comps
, srcWidthNB
,
1402 srcPtr
+ (srcWidth
* (srcHeight
- 1) + 1) * bpt
,
1403 srcPtr
+ (srcWidth
* (srcHeight
- 1) + 1) * bpt
,
1405 dstPtr
+ (dstWidth
* (dstHeight
- 1) + 1) * bpt
);
1406 /* left and right borders */
1407 if (srcHeight
== dstHeight
) {
1408 /* copy border pixel from src to dst */
1409 for (row
= 1; row
< srcHeight
; row
++) {
1410 memcpy(dstPtr
+ dstWidth
* row
* bpt
,
1411 srcPtr
+ srcWidth
* row
* bpt
, bpt
);
1412 memcpy(dstPtr
+ (dstWidth
* row
+ dstWidth
- 1) * bpt
,
1413 srcPtr
+ (srcWidth
* row
+ srcWidth
- 1) * bpt
, bpt
);
1417 /* average two src pixels each dest pixel */
1418 for (row
= 0; row
< dstHeightNB
; row
+= 2) {
1419 do_row(datatype
, comps
, 1,
1420 srcPtr
+ (srcWidth
* (row
* 2 + 1)) * bpt
,
1421 srcPtr
+ (srcWidth
* (row
* 2 + 2)) * bpt
,
1422 1, dstPtr
+ (dstWidth
* row
+ 1) * bpt
);
1423 do_row(datatype
, comps
, 1,
1424 srcPtr
+ (srcWidth
* (row
* 2 + 1) + srcWidth
- 1) * bpt
,
1425 srcPtr
+ (srcWidth
* (row
* 2 + 2) + srcWidth
- 1) * bpt
,
1426 1, dstPtr
+ (dstWidth
* row
+ 1 + dstWidth
- 1) * bpt
);
1434 make_3d_mipmap(GLenum datatype
, GLuint comps
, GLint border
,
1435 GLint srcWidth
, GLint srcHeight
, GLint srcDepth
,
1436 const GLubyte
*srcPtr
, GLint srcRowStride
,
1437 GLint dstWidth
, GLint dstHeight
, GLint dstDepth
,
1438 GLubyte
*dstPtr
, GLint dstRowStride
)
1440 const GLint bpt
= bytes_per_pixel(datatype
, comps
);
1441 const GLint srcWidthNB
= srcWidth
- 2 * border
; /* sizes w/out border */
1442 const GLint srcDepthNB
= srcDepth
- 2 * border
;
1443 const GLint dstWidthNB
= dstWidth
- 2 * border
;
1444 const GLint dstHeightNB
= dstHeight
- 2 * border
;
1445 const GLint dstDepthNB
= dstDepth
- 2 * border
;
1447 GLint bytesPerSrcImage
, bytesPerDstImage
;
1448 GLint bytesPerSrcRow
, bytesPerDstRow
;
1449 GLint srcImageOffset
, srcRowOffset
;
1451 (void) srcDepthNB
; /* silence warnings */
1454 bytesPerSrcImage
= srcWidth
* srcHeight
* bpt
;
1455 bytesPerDstImage
= dstWidth
* dstHeight
* bpt
;
1457 bytesPerSrcRow
= srcWidth
* bpt
;
1458 bytesPerDstRow
= dstWidth
* bpt
;
1460 /* Offset between adjacent src images to be averaged together */
1461 srcImageOffset
= (srcDepth
== dstDepth
) ? 0 : bytesPerSrcImage
;
1463 /* Offset between adjacent src rows to be averaged together */
1464 srcRowOffset
= (srcHeight
== dstHeight
) ? 0 : srcWidth
* bpt
;
1467 * Need to average together up to 8 src pixels for each dest pixel.
1468 * Break that down into 3 operations:
1469 * 1. take two rows from source image and average them together.
1470 * 2. take two rows from next source image and average them together.
1471 * 3. take the two averaged rows and average them for the final dst row.
1475 printf("mip3d %d x %d x %d -> %d x %d x %d\n",
1476 srcWidth, srcHeight, srcDepth, dstWidth, dstHeight, dstDepth);
1479 for (img
= 0; img
< dstDepthNB
; img
++) {
1480 /* first source image pointer, skipping border */
1481 const GLubyte
*imgSrcA
= srcPtr
1482 + (bytesPerSrcImage
+ bytesPerSrcRow
+ border
) * bpt
* border
1483 + img
* (bytesPerSrcImage
+ srcImageOffset
);
1484 /* second source image pointer, skipping border */
1485 const GLubyte
*imgSrcB
= imgSrcA
+ srcImageOffset
;
1486 /* address of the dest image, skipping border */
1487 GLubyte
*imgDst
= dstPtr
1488 + (bytesPerDstImage
+ bytesPerDstRow
+ border
) * bpt
* border
1489 + img
* bytesPerDstImage
;
1491 /* setup the four source row pointers and the dest row pointer */
1492 const GLubyte
*srcImgARowA
= imgSrcA
;
1493 const GLubyte
*srcImgARowB
= imgSrcA
+ srcRowOffset
;
1494 const GLubyte
*srcImgBRowA
= imgSrcB
;
1495 const GLubyte
*srcImgBRowB
= imgSrcB
+ srcRowOffset
;
1496 GLubyte
*dstImgRow
= imgDst
;
1498 for (row
= 0; row
< dstHeightNB
; row
++) {
1499 do_row_3D(datatype
, comps
, srcWidthNB
,
1500 srcImgARowA
, srcImgARowB
,
1501 srcImgBRowA
, srcImgBRowB
,
1502 dstWidthNB
, dstImgRow
);
1504 /* advance to next rows */
1505 srcImgARowA
+= bytesPerSrcRow
+ srcRowOffset
;
1506 srcImgARowB
+= bytesPerSrcRow
+ srcRowOffset
;
1507 srcImgBRowA
+= bytesPerSrcRow
+ srcRowOffset
;
1508 srcImgBRowB
+= bytesPerSrcRow
+ srcRowOffset
;
1509 dstImgRow
+= bytesPerDstRow
;
1514 /* Luckily we can leverage the make_2d_mipmap() function here! */
1516 /* do front border image */
1517 make_2d_mipmap(datatype
, comps
, 1, srcWidth
, srcHeight
, srcPtr
, srcRowStride
,
1518 dstWidth
, dstHeight
, dstPtr
, dstRowStride
);
1519 /* do back border image */
1520 make_2d_mipmap(datatype
, comps
, 1, srcWidth
, srcHeight
,
1521 srcPtr
+ bytesPerSrcImage
* (srcDepth
- 1), srcRowStride
,
1522 dstWidth
, dstHeight
,
1523 dstPtr
+ bytesPerDstImage
* (dstDepth
- 1), dstRowStride
);
1524 /* do four remaining border edges that span the image slices */
1525 if (srcDepth
== dstDepth
) {
1526 /* just copy border pixels from src to dst */
1527 for (img
= 0; img
< dstDepthNB
; img
++) {
1531 /* do border along [img][row=0][col=0] */
1532 src
= srcPtr
+ (img
+ 1) * bytesPerSrcImage
;
1533 dst
= dstPtr
+ (img
+ 1) * bytesPerDstImage
;
1534 memcpy(dst
, src
, bpt
);
1536 /* do border along [img][row=dstHeight-1][col=0] */
1537 src
= srcPtr
+ (img
* 2 + 1) * bytesPerSrcImage
1538 + (srcHeight
- 1) * bytesPerSrcRow
;
1539 dst
= dstPtr
+ (img
+ 1) * bytesPerDstImage
1540 + (dstHeight
- 1) * bytesPerDstRow
;
1541 memcpy(dst
, src
, bpt
);
1543 /* do border along [img][row=0][col=dstWidth-1] */
1544 src
= srcPtr
+ (img
* 2 + 1) * bytesPerSrcImage
1545 + (srcWidth
- 1) * bpt
;
1546 dst
= dstPtr
+ (img
+ 1) * bytesPerDstImage
1547 + (dstWidth
- 1) * bpt
;
1548 memcpy(dst
, src
, bpt
);
1550 /* do border along [img][row=dstHeight-1][col=dstWidth-1] */
1551 src
= srcPtr
+ (img
* 2 + 1) * bytesPerSrcImage
1552 + (bytesPerSrcImage
- bpt
);
1553 dst
= dstPtr
+ (img
+ 1) * bytesPerDstImage
1554 + (bytesPerDstImage
- bpt
);
1555 memcpy(dst
, src
, bpt
);
1559 /* average border pixels from adjacent src image pairs */
1560 ASSERT(srcDepthNB
== 2 * dstDepthNB
);
1561 for (img
= 0; img
< dstDepthNB
; img
++) {
1565 /* do border along [img][row=0][col=0] */
1566 src
= srcPtr
+ (img
* 2 + 1) * bytesPerSrcImage
;
1567 dst
= dstPtr
+ (img
+ 1) * bytesPerDstImage
;
1568 do_row(datatype
, comps
, 1, src
, src
+ srcImageOffset
, 1, dst
);
1570 /* do border along [img][row=dstHeight-1][col=0] */
1571 src
= srcPtr
+ (img
* 2 + 1) * bytesPerSrcImage
1572 + (srcHeight
- 1) * bytesPerSrcRow
;
1573 dst
= dstPtr
+ (img
+ 1) * bytesPerDstImage
1574 + (dstHeight
- 1) * bytesPerDstRow
;
1575 do_row(datatype
, comps
, 1, src
, src
+ srcImageOffset
, 1, dst
);
1577 /* do border along [img][row=0][col=dstWidth-1] */
1578 src
= srcPtr
+ (img
* 2 + 1) * bytesPerSrcImage
1579 + (srcWidth
- 1) * bpt
;
1580 dst
= dstPtr
+ (img
+ 1) * bytesPerDstImage
1581 + (dstWidth
- 1) * bpt
;
1582 do_row(datatype
, comps
, 1, src
, src
+ srcImageOffset
, 1, dst
);
1584 /* do border along [img][row=dstHeight-1][col=dstWidth-1] */
1585 src
= srcPtr
+ (img
* 2 + 1) * bytesPerSrcImage
1586 + (bytesPerSrcImage
- bpt
);
1587 dst
= dstPtr
+ (img
+ 1) * bytesPerDstImage
1588 + (bytesPerDstImage
- bpt
);
1589 do_row(datatype
, comps
, 1, src
, src
+ srcImageOffset
, 1, dst
);
1597 make_1d_stack_mipmap(GLenum datatype
, GLuint comps
, GLint border
,
1598 GLint srcWidth
, const GLubyte
*srcPtr
, GLuint srcRowStride
,
1599 GLint dstWidth
, GLint dstHeight
,
1600 GLubyte
*dstPtr
, GLuint dstRowStride
)
1602 const GLint bpt
= bytes_per_pixel(datatype
, comps
);
1603 const GLint srcWidthNB
= srcWidth
- 2 * border
; /* sizes w/out border */
1604 const GLint dstWidthNB
= dstWidth
- 2 * border
;
1605 const GLint dstHeightNB
= dstHeight
- 2 * border
;
1606 const GLint srcRowBytes
= bpt
* srcRowStride
;
1607 const GLint dstRowBytes
= bpt
* dstRowStride
;
1612 /* Compute src and dst pointers, skipping any border */
1613 src
= srcPtr
+ border
* ((srcWidth
+ 1) * bpt
);
1614 dst
= dstPtr
+ border
* ((dstWidth
+ 1) * bpt
);
1616 for (row
= 0; row
< dstHeightNB
; row
++) {
1617 do_row(datatype
, comps
, srcWidthNB
, src
, src
,
1624 /* copy left-most pixel from source */
1627 memcpy(dstPtr
, srcPtr
, bpt
);
1628 /* copy right-most pixel from source */
1629 memcpy(dstPtr
+ (dstWidth
- 1) * bpt
,
1630 srcPtr
+ (srcWidth
- 1) * bpt
,
1638 * There is quite a bit of refactoring that could be done with this function
1639 * and \c make_2d_mipmap.
1642 make_2d_stack_mipmap(GLenum datatype
, GLuint comps
, GLint border
,
1643 GLint srcWidth
, GLint srcHeight
,
1644 const GLubyte
*srcPtr
, GLint srcRowStride
,
1645 GLint dstWidth
, GLint dstHeight
, GLint dstDepth
,
1646 GLubyte
*dstPtr
, GLint dstRowStride
)
1648 const GLint bpt
= bytes_per_pixel(datatype
, comps
);
1649 const GLint srcWidthNB
= srcWidth
- 2 * border
; /* sizes w/out border */
1650 const GLint dstWidthNB
= dstWidth
- 2 * border
;
1651 const GLint dstHeightNB
= dstHeight
- 2 * border
;
1652 const GLint dstDepthNB
= dstDepth
- 2 * border
;
1653 const GLint srcRowBytes
= bpt
* srcRowStride
;
1654 const GLint dstRowBytes
= bpt
* dstRowStride
;
1655 const GLubyte
*srcA
, *srcB
;
1660 /* Compute src and dst pointers, skipping any border */
1661 srcA
= srcPtr
+ border
* ((srcWidth
+ 1) * bpt
);
1663 srcB
= srcA
+ srcRowBytes
;
1666 dst
= dstPtr
+ border
* ((dstWidth
+ 1) * bpt
);
1668 for (layer
= 0; layer
< dstDepthNB
; layer
++) {
1669 for (row
= 0; row
< dstHeightNB
; row
++) {
1670 do_row(datatype
, comps
, srcWidthNB
, srcA
, srcB
,
1672 srcA
+= 2 * srcRowBytes
;
1673 srcB
+= 2 * srcRowBytes
;
1677 /* This is ugly but probably won't be used much */
1679 /* fill in dest border */
1680 /* lower-left border pixel */
1683 memcpy(dstPtr
, srcPtr
, bpt
);
1684 /* lower-right border pixel */
1685 memcpy(dstPtr
+ (dstWidth
- 1) * bpt
,
1686 srcPtr
+ (srcWidth
- 1) * bpt
, bpt
);
1687 /* upper-left border pixel */
1688 memcpy(dstPtr
+ dstWidth
* (dstHeight
- 1) * bpt
,
1689 srcPtr
+ srcWidth
* (srcHeight
- 1) * bpt
, bpt
);
1690 /* upper-right border pixel */
1691 memcpy(dstPtr
+ (dstWidth
* dstHeight
- 1) * bpt
,
1692 srcPtr
+ (srcWidth
* srcHeight
- 1) * bpt
, bpt
);
1694 do_row(datatype
, comps
, srcWidthNB
,
1697 dstWidthNB
, dstPtr
+ bpt
);
1699 do_row(datatype
, comps
, srcWidthNB
,
1700 srcPtr
+ (srcWidth
* (srcHeight
- 1) + 1) * bpt
,
1701 srcPtr
+ (srcWidth
* (srcHeight
- 1) + 1) * bpt
,
1703 dstPtr
+ (dstWidth
* (dstHeight
- 1) + 1) * bpt
);
1704 /* left and right borders */
1705 if (srcHeight
== dstHeight
) {
1706 /* copy border pixel from src to dst */
1707 for (row
= 1; row
< srcHeight
; row
++) {
1708 memcpy(dstPtr
+ dstWidth
* row
* bpt
,
1709 srcPtr
+ srcWidth
* row
* bpt
, bpt
);
1710 memcpy(dstPtr
+ (dstWidth
* row
+ dstWidth
- 1) * bpt
,
1711 srcPtr
+ (srcWidth
* row
+ srcWidth
- 1) * bpt
, bpt
);
1715 /* average two src pixels each dest pixel */
1716 for (row
= 0; row
< dstHeightNB
; row
+= 2) {
1717 do_row(datatype
, comps
, 1,
1718 srcPtr
+ (srcWidth
* (row
* 2 + 1)) * bpt
,
1719 srcPtr
+ (srcWidth
* (row
* 2 + 2)) * bpt
,
1720 1, dstPtr
+ (dstWidth
* row
+ 1) * bpt
);
1721 do_row(datatype
, comps
, 1,
1722 srcPtr
+ (srcWidth
* (row
* 2 + 1) + srcWidth
- 1) * bpt
,
1723 srcPtr
+ (srcWidth
* (row
* 2 + 2) + srcWidth
- 1) * bpt
,
1724 1, dstPtr
+ (dstWidth
* row
+ 1 + dstWidth
- 1) * bpt
);
1733 * Down-sample a texture image to produce the next lower mipmap level.
1734 * \param comps components per texel (1, 2, 3 or 4)
1735 * \param srcRowStride stride between source rows, in texels
1736 * \param dstRowStride stride between destination rows, in texels
1739 _mesa_generate_mipmap_level(GLenum target
,
1740 GLenum datatype
, GLuint comps
,
1742 GLint srcWidth
, GLint srcHeight
, GLint srcDepth
,
1743 const GLubyte
*srcData
,
1745 GLint dstWidth
, GLint dstHeight
, GLint dstDepth
,
1750 * We use simple 2x2 averaging to compute the next mipmap level.
1754 make_1d_mipmap(datatype
, comps
, border
,
1759 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
1760 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
1761 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
1762 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
1763 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
1764 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
1765 make_2d_mipmap(datatype
, comps
, border
,
1766 srcWidth
, srcHeight
, srcData
, srcRowStride
,
1767 dstWidth
, dstHeight
, dstData
, dstRowStride
);
1770 make_3d_mipmap(datatype
, comps
, border
,
1771 srcWidth
, srcHeight
, srcDepth
,
1772 srcData
, srcRowStride
,
1773 dstWidth
, dstHeight
, dstDepth
,
1774 dstData
, dstRowStride
);
1776 case GL_TEXTURE_1D_ARRAY_EXT
:
1777 make_1d_stack_mipmap(datatype
, comps
, border
,
1778 srcWidth
, srcData
, srcRowStride
,
1779 dstWidth
, dstHeight
,
1780 dstData
, dstRowStride
);
1782 case GL_TEXTURE_2D_ARRAY_EXT
:
1783 make_2d_stack_mipmap(datatype
, comps
, border
,
1784 srcWidth
, srcHeight
,
1785 srcData
, srcRowStride
,
1786 dstWidth
, dstHeight
,
1787 dstDepth
, dstData
, dstRowStride
);
1789 case GL_TEXTURE_RECTANGLE_NV
:
1790 /* no mipmaps, do nothing */
1793 _mesa_problem(NULL
, "bad dimensions in _mesa_generate_mipmaps");
1800 * compute next (level+1) image size
1801 * \return GL_FALSE if no smaller size can be generated (eg. src is 1x1x1 size)
1804 next_mipmap_level_size(GLenum target
, GLint border
,
1805 GLint srcWidth
, GLint srcHeight
, GLint srcDepth
,
1806 GLint
*dstWidth
, GLint
*dstHeight
, GLint
*dstDepth
)
1808 if (srcWidth
- 2 * border
> 1) {
1809 *dstWidth
= (srcWidth
- 2 * border
) / 2 + 2 * border
;
1812 *dstWidth
= srcWidth
; /* can't go smaller */
1815 if ((srcHeight
- 2 * border
> 1) &&
1816 (target
!= GL_TEXTURE_1D_ARRAY_EXT
)) {
1817 *dstHeight
= (srcHeight
- 2 * border
) / 2 + 2 * border
;
1820 *dstHeight
= srcHeight
; /* can't go smaller */
1823 if ((srcDepth
- 2 * border
> 1) &&
1824 (target
!= GL_TEXTURE_2D_ARRAY_EXT
)) {
1825 *dstDepth
= (srcDepth
- 2 * border
) / 2 + 2 * border
;
1828 *dstDepth
= srcDepth
; /* can't go smaller */
1831 if (*dstWidth
== srcWidth
&&
1832 *dstHeight
== srcHeight
&&
1833 *dstDepth
== srcDepth
) {
1845 * Automatic mipmap generation.
1846 * This is the fallback/default function for ctx->Driver.GenerateMipmap().
1847 * Generate a complete set of mipmaps from texObj's BaseLevel image.
1848 * Stop at texObj's MaxLevel or when we get to the 1x1 texture.
1849 * For cube maps, target will be one of
1850 * GL_TEXTURE_CUBE_MAP_POSITIVE/NEGATIVE_X/Y/Z; never GL_TEXTURE_CUBE_MAP.
1853 _mesa_generate_mipmap(struct gl_context
*ctx
, GLenum target
,
1854 struct gl_texture_object
*texObj
)
1856 const struct gl_texture_image
*srcImage
;
1857 gl_format convertFormat
;
1858 const GLubyte
*srcData
= NULL
;
1859 GLubyte
*dstData
= NULL
;
1860 GLint level
, maxLevels
;
1865 srcImage
= _mesa_select_tex_image(ctx
, texObj
, target
, texObj
->BaseLevel
);
1868 maxLevels
= _mesa_max_texture_levels(ctx
, texObj
->Target
);
1869 ASSERT(maxLevels
> 0); /* bad target */
1871 /* Find convertFormat - the format that do_row() will process */
1873 if (_mesa_is_format_compressed(srcImage
->TexFormat
)) {
1874 /* setup for compressed textures - need to allocate temporary
1875 * image buffers to hold uncompressed images.
1878 GLint components
, size
;
1881 assert(texObj
->Target
== GL_TEXTURE_2D
||
1882 texObj
->Target
== GL_TEXTURE_CUBE_MAP_ARB
);
1884 if (srcImage
->_BaseFormat
== GL_RGB
) {
1885 convertFormat
= MESA_FORMAT_RGB888
;
1887 } else if (srcImage
->_BaseFormat
== GL_RED
) {
1888 convertFormat
= MESA_FORMAT_R8
;
1890 } else if (srcImage
->_BaseFormat
== GL_RG
) {
1891 convertFormat
= MESA_FORMAT_RG88
;
1893 } else if (srcImage
->_BaseFormat
== GL_RGBA
) {
1894 convertFormat
= MESA_FORMAT_RGBA8888
;
1896 } else if (srcImage
->_BaseFormat
== GL_LUMINANCE
) {
1897 convertFormat
= MESA_FORMAT_L8
;
1899 } else if (srcImage
->_BaseFormat
== GL_LUMINANCE_ALPHA
) {
1900 convertFormat
= MESA_FORMAT_AL88
;
1903 _mesa_problem(ctx
, "bad srcImage->_BaseFormat in _mesa_generate_mipmaps");
1907 /* allocate storage for uncompressed GL_RGB or GL_RGBA images */
1908 size
= _mesa_bytes_per_pixel(srcImage
->_BaseFormat
, CHAN_TYPE
)
1909 * srcImage
->Width
* srcImage
->Height
* srcImage
->Depth
+ 20;
1910 /* 20 extra bytes, just be safe when calling last FetchTexel */
1911 srcData
= (GLubyte
*) malloc(size
);
1913 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "generate mipmaps");
1916 dstData
= (GLubyte
*) malloc(size
/ 2); /* 1/4 would probably be OK */
1918 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "generate mipmaps");
1919 free((void *) srcData
);
1923 /* decompress base image here */
1924 dst
= (GLchan
*) srcData
;
1925 for (row
= 0; row
< srcImage
->Height
; row
++) {
1927 for (col
= 0; col
< srcImage
->Width
; col
++) {
1928 srcImage
->FetchTexelc(srcImage
, col
, row
, 0, dst
);
1935 convertFormat
= srcImage
->TexFormat
;
1938 _mesa_format_to_type_and_comps(convertFormat
, &datatype
, &comps
);
1940 for (level
= texObj
->BaseLevel
; level
< texObj
->MaxLevel
1941 && level
< maxLevels
- 1; level
++) {
1942 /* generate image[level+1] from image[level] */
1943 const struct gl_texture_image
*srcImage
;
1944 struct gl_texture_image
*dstImage
;
1945 GLint srcWidth
, srcHeight
, srcDepth
;
1946 GLint dstWidth
, dstHeight
, dstDepth
;
1948 GLboolean nextLevel
;
1950 /* get src image parameters */
1951 srcImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
1953 srcWidth
= srcImage
->Width
;
1954 srcHeight
= srcImage
->Height
;
1955 srcDepth
= srcImage
->Depth
;
1956 border
= srcImage
->Border
;
1958 nextLevel
= next_mipmap_level_size(target
, border
,
1959 srcWidth
, srcHeight
, srcDepth
,
1960 &dstWidth
, &dstHeight
, &dstDepth
);
1963 if (_mesa_is_format_compressed(srcImage
->TexFormat
)) {
1964 free((void *) srcData
);
1970 /* get dest gl_texture_image */
1971 dstImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
+ 1);
1973 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "generating mipmaps");
1977 /* Free old image data */
1979 ctx
->Driver
.FreeTexImageData(ctx
, dstImage
);
1981 /* initialize new image */
1982 _mesa_init_teximage_fields(ctx
, target
, dstImage
, dstWidth
, dstHeight
,
1983 dstDepth
, border
, srcImage
->InternalFormat
,
1984 srcImage
->TexFormat
);
1985 dstImage
->DriverData
= NULL
;
1986 dstImage
->FetchTexelc
= srcImage
->FetchTexelc
;
1987 dstImage
->FetchTexelf
= srcImage
->FetchTexelf
;
1989 /* Alloc new teximage data buffer */
1991 GLuint size
= _mesa_format_image_size(dstImage
->TexFormat
,
1992 dstWidth
, dstHeight
, dstDepth
);
1993 dstImage
->Data
= _mesa_alloc_texmemory(size
);
1994 if (!dstImage
->Data
) {
1995 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "generating mipmaps");
2000 /* Setup src and dest data pointers */
2001 if (_mesa_is_format_compressed(dstImage
->TexFormat
)) {
2002 /* srcData and dstData are already set */
2007 srcData
= (const GLubyte
*) srcImage
->Data
;
2008 dstData
= (GLubyte
*) dstImage
->Data
;
2011 ASSERT(dstImage
->TexFormat
);
2012 ASSERT(dstImage
->FetchTexelc
);
2013 ASSERT(dstImage
->FetchTexelf
);
2015 _mesa_generate_mipmap_level(target
, datatype
, comps
, border
,
2016 srcWidth
, srcHeight
, srcDepth
,
2017 srcData
, srcImage
->RowStride
,
2018 dstWidth
, dstHeight
, dstDepth
,
2019 dstData
, dstImage
->RowStride
);
2022 if (_mesa_is_format_compressed(dstImage
->TexFormat
)) {
2024 /* compress image from dstData into dstImage->Data */
2025 const GLenum srcFormat
= _mesa_get_format_base_format(convertFormat
);
2027 = _mesa_format_row_stride(dstImage
->TexFormat
, dstWidth
);
2029 _mesa_texstore(ctx
, 2, dstImage
->_BaseFormat
,
2030 dstImage
->TexFormat
,
2032 0, 0, 0, /* dstX/Y/Zoffset */
2033 dstRowStride
, 0, /* strides */
2034 dstWidth
, dstHeight
, 1, /* size */
2035 srcFormat
, CHAN_TYPE
,
2036 dstData
, /* src data, actually */
2037 &ctx
->DefaultPacking
);
2039 /* swap src and dest pointers */
2040 temp
= (GLubyte
*) srcData
;
2045 } /* loop over mipmap levels */
2050 * Helper function for drivers which need to rescale texture images to
2051 * certain aspect ratios.
2052 * Nearest filtering only (for broken hardware that can't support
2053 * all aspect ratios). This can be made a lot faster, but I don't
2054 * really care enough...
2057 _mesa_rescale_teximage2d(GLuint bytesPerPixel
,
2058 GLuint srcStrideInPixels
,
2059 GLuint dstRowStride
,
2060 GLint srcWidth
, GLint srcHeight
,
2061 GLint dstWidth
, GLint dstHeight
,
2062 const GLvoid
*srcImage
, GLvoid
*dstImage
)
2066 #define INNER_LOOP( TYPE, HOP, WOP ) \
2067 for ( row = 0 ; row < dstHeight ; row++ ) { \
2068 GLint srcRow = row HOP hScale; \
2069 for ( col = 0 ; col < dstWidth ; col++ ) { \
2070 GLint srcCol = col WOP wScale; \
2071 dst[col] = src[srcRow * srcStrideInPixels + srcCol]; \
2073 dst = (TYPE *) ((GLubyte *) dst + dstRowStride); \
2076 #define RESCALE_IMAGE( TYPE ) \
2078 const TYPE *src = (const TYPE *)srcImage; \
2079 TYPE *dst = (TYPE *)dstImage; \
2081 if ( srcHeight < dstHeight ) { \
2082 const GLint hScale = dstHeight / srcHeight; \
2083 if ( srcWidth < dstWidth ) { \
2084 const GLint wScale = dstWidth / srcWidth; \
2085 INNER_LOOP( TYPE, /, / ); \
2088 const GLint wScale = srcWidth / dstWidth; \
2089 INNER_LOOP( TYPE, /, * ); \
2093 const GLint hScale = srcHeight / dstHeight; \
2094 if ( srcWidth < dstWidth ) { \
2095 const GLint wScale = dstWidth / srcWidth; \
2096 INNER_LOOP( TYPE, *, / ); \
2099 const GLint wScale = srcWidth / dstWidth; \
2100 INNER_LOOP( TYPE, *, * ); \
2105 switch ( bytesPerPixel
) {
2107 RESCALE_IMAGE( GLuint
);
2111 RESCALE_IMAGE( GLushort
);
2115 RESCALE_IMAGE( GLubyte
);
2118 _mesa_problem(NULL
,"unexpected bytes/pixel in _mesa_rescale_teximage2d");
2124 * Upscale an image by replication, not (typical) stretching.
2125 * We use this when the image width or height is less than a
2126 * certain size (4, 8) and we need to upscale an image.
2129 _mesa_upscale_teximage2d(GLsizei inWidth
, GLsizei inHeight
,
2130 GLsizei outWidth
, GLsizei outHeight
,
2131 GLint comps
, const GLchan
*src
, GLint srcRowStride
,
2136 ASSERT(outWidth
>= inWidth
);
2137 ASSERT(outHeight
>= inHeight
);
2139 ASSERT(inWidth
== 1 || inWidth
== 2 || inHeight
== 1 || inHeight
== 2);
2140 ASSERT((outWidth
& 3) == 0);
2141 ASSERT((outHeight
& 3) == 0);
2144 for (i
= 0; i
< outHeight
; i
++) {
2145 const GLint ii
= i
% inHeight
;
2146 for (j
= 0; j
< outWidth
; j
++) {
2147 const GLint jj
= j
% inWidth
;
2148 for (k
= 0; k
< comps
; k
++) {
2149 dest
[(i
* outWidth
+ j
) * comps
+ k
]
2150 = src
[ii
* srcRowStride
+ jj
* comps
+ k
];