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.
41 bytes_per_pixel(GLenum datatype
, GLuint comps
)
43 GLint b
= _mesa_sizeof_packed_type(datatype
);
46 if (_mesa_type_is_packed(datatype
))
54 * \name Support macros for do_row and do_row_3d
56 * The macro madness is here for two reasons. First, it compacts the code
57 * slightly. Second, it makes it much easier to adjust the specifics of the
58 * filter to tune the rounding characteristics.
61 #define DECLARE_ROW_POINTERS(t, e) \
62 const t(*rowA)[e] = (const t(*)[e]) srcRowA; \
63 const t(*rowB)[e] = (const t(*)[e]) srcRowB; \
64 const t(*rowC)[e] = (const t(*)[e]) srcRowC; \
65 const t(*rowD)[e] = (const t(*)[e]) srcRowD; \
66 t(*dst)[e] = (t(*)[e]) dstRow
68 #define DECLARE_ROW_POINTERS0(t) \
69 const t *rowA = (const t *) srcRowA; \
70 const t *rowB = (const t *) srcRowB; \
71 const t *rowC = (const t *) srcRowC; \
72 const t *rowD = (const t *) srcRowD; \
75 #define FILTER_SUM_3D(Aj, Ak, Bj, Bk, Cj, Ck, Dj, Dk) \
76 ((unsigned) Aj + (unsigned) Ak \
77 + (unsigned) Bj + (unsigned) Bk \
78 + (unsigned) Cj + (unsigned) Ck \
79 + (unsigned) Dj + (unsigned) Dk \
82 #define FILTER_3D(e) \
84 dst[i][e] = FILTER_SUM_3D(rowA[j][e], rowA[k][e], \
85 rowB[j][e], rowB[k][e], \
86 rowC[j][e], rowC[k][e], \
87 rowD[j][e], rowD[k][e]); \
90 #define FILTER_SUM_3D_SIGNED(Aj, Ak, Bj, Bk, Cj, Ck, Dj, Dk) \
97 #define FILTER_3D_SIGNED(e) \
99 dst[i][e] = FILTER_SUM_3D_SIGNED(rowA[j][e], rowA[k][e], \
100 rowB[j][e], rowB[k][e], \
101 rowC[j][e], rowC[k][e], \
102 rowD[j][e], rowD[k][e]); \
105 #define FILTER_F_3D(e) \
107 dst[i][e] = (rowA[j][e] + rowA[k][e] \
108 + rowB[j][e] + rowB[k][e] \
109 + rowC[j][e] + rowC[k][e] \
110 + rowD[j][e] + rowD[k][e]) * 0.125F; \
113 #define FILTER_HF_3D(e) \
115 const GLfloat aj = _mesa_half_to_float(rowA[j][e]); \
116 const GLfloat ak = _mesa_half_to_float(rowA[k][e]); \
117 const GLfloat bj = _mesa_half_to_float(rowB[j][e]); \
118 const GLfloat bk = _mesa_half_to_float(rowB[k][e]); \
119 const GLfloat cj = _mesa_half_to_float(rowC[j][e]); \
120 const GLfloat ck = _mesa_half_to_float(rowC[k][e]); \
121 const GLfloat dj = _mesa_half_to_float(rowD[j][e]); \
122 const GLfloat dk = _mesa_half_to_float(rowD[k][e]); \
123 dst[i][e] = _mesa_float_to_half((aj + ak + bj + bk + cj + ck + dj + dk) \
130 * Average together two rows of a source image to produce a single new
131 * row in the dest image. It's legal for the two source rows to point
132 * to the same data. The source width must be equal to either the
133 * dest width or two times the dest width.
134 * \param datatype GL_UNSIGNED_BYTE, GL_UNSIGNED_SHORT, GL_FLOAT, etc.
135 * \param comps number of components per pixel (1..4)
138 do_row(GLenum datatype
, GLuint comps
, GLint srcWidth
,
139 const GLvoid
*srcRowA
, const GLvoid
*srcRowB
,
140 GLint dstWidth
, GLvoid
*dstRow
)
142 const GLuint k0
= (srcWidth
== dstWidth
) ? 0 : 1;
143 const GLuint colStride
= (srcWidth
== dstWidth
) ? 1 : 2;
148 /* This assertion is no longer valid with non-power-of-2 textures
149 assert(srcWidth == dstWidth || srcWidth == 2 * dstWidth);
152 if (datatype
== GL_UNSIGNED_BYTE
&& comps
== 4) {
154 const GLubyte(*rowA
)[4] = (const GLubyte(*)[4]) srcRowA
;
155 const GLubyte(*rowB
)[4] = (const GLubyte(*)[4]) srcRowB
;
156 GLubyte(*dst
)[4] = (GLubyte(*)[4]) dstRow
;
157 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
158 i
++, j
+= colStride
, k
+= colStride
) {
159 dst
[i
][0] = (rowA
[j
][0] + rowA
[k
][0] + rowB
[j
][0] + rowB
[k
][0]) / 4;
160 dst
[i
][1] = (rowA
[j
][1] + rowA
[k
][1] + rowB
[j
][1] + rowB
[k
][1]) / 4;
161 dst
[i
][2] = (rowA
[j
][2] + rowA
[k
][2] + rowB
[j
][2] + rowB
[k
][2]) / 4;
162 dst
[i
][3] = (rowA
[j
][3] + rowA
[k
][3] + rowB
[j
][3] + rowB
[k
][3]) / 4;
165 else if (datatype
== GL_UNSIGNED_BYTE
&& comps
== 3) {
167 const GLubyte(*rowA
)[3] = (const GLubyte(*)[3]) srcRowA
;
168 const GLubyte(*rowB
)[3] = (const GLubyte(*)[3]) srcRowB
;
169 GLubyte(*dst
)[3] = (GLubyte(*)[3]) dstRow
;
170 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
171 i
++, j
+= colStride
, k
+= colStride
) {
172 dst
[i
][0] = (rowA
[j
][0] + rowA
[k
][0] + rowB
[j
][0] + rowB
[k
][0]) / 4;
173 dst
[i
][1] = (rowA
[j
][1] + rowA
[k
][1] + rowB
[j
][1] + rowB
[k
][1]) / 4;
174 dst
[i
][2] = (rowA
[j
][2] + rowA
[k
][2] + rowB
[j
][2] + rowB
[k
][2]) / 4;
177 else if (datatype
== GL_UNSIGNED_BYTE
&& comps
== 2) {
179 const GLubyte(*rowA
)[2] = (const GLubyte(*)[2]) srcRowA
;
180 const GLubyte(*rowB
)[2] = (const GLubyte(*)[2]) srcRowB
;
181 GLubyte(*dst
)[2] = (GLubyte(*)[2]) dstRow
;
182 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
183 i
++, j
+= colStride
, k
+= colStride
) {
184 dst
[i
][0] = (rowA
[j
][0] + rowA
[k
][0] + rowB
[j
][0] + rowB
[k
][0]) >> 2;
185 dst
[i
][1] = (rowA
[j
][1] + rowA
[k
][1] + rowB
[j
][1] + rowB
[k
][1]) >> 2;
188 else if (datatype
== GL_UNSIGNED_BYTE
&& comps
== 1) {
190 const GLubyte
*rowA
= (const GLubyte
*) srcRowA
;
191 const GLubyte
*rowB
= (const GLubyte
*) srcRowB
;
192 GLubyte
*dst
= (GLubyte
*) dstRow
;
193 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
194 i
++, j
+= colStride
, k
+= colStride
) {
195 dst
[i
] = (rowA
[j
] + rowA
[k
] + rowB
[j
] + rowB
[k
]) >> 2;
199 else if (datatype
== GL_BYTE
&& comps
== 4) {
201 const GLbyte(*rowA
)[4] = (const GLbyte(*)[4]) srcRowA
;
202 const GLbyte(*rowB
)[4] = (const GLbyte(*)[4]) srcRowB
;
203 GLbyte(*dst
)[4] = (GLbyte(*)[4]) dstRow
;
204 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
205 i
++, j
+= colStride
, k
+= colStride
) {
206 dst
[i
][0] = (rowA
[j
][0] + rowA
[k
][0] + rowB
[j
][0] + rowB
[k
][0]) / 4;
207 dst
[i
][1] = (rowA
[j
][1] + rowA
[k
][1] + rowB
[j
][1] + rowB
[k
][1]) / 4;
208 dst
[i
][2] = (rowA
[j
][2] + rowA
[k
][2] + rowB
[j
][2] + rowB
[k
][2]) / 4;
209 dst
[i
][3] = (rowA
[j
][3] + rowA
[k
][3] + rowB
[j
][3] + rowB
[k
][3]) / 4;
212 else if (datatype
== GL_BYTE
&& comps
== 3) {
214 const GLbyte(*rowA
)[3] = (const GLbyte(*)[3]) srcRowA
;
215 const GLbyte(*rowB
)[3] = (const GLbyte(*)[3]) srcRowB
;
216 GLbyte(*dst
)[3] = (GLbyte(*)[3]) dstRow
;
217 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
218 i
++, j
+= colStride
, k
+= colStride
) {
219 dst
[i
][0] = (rowA
[j
][0] + rowA
[k
][0] + rowB
[j
][0] + rowB
[k
][0]) / 4;
220 dst
[i
][1] = (rowA
[j
][1] + rowA
[k
][1] + rowB
[j
][1] + rowB
[k
][1]) / 4;
221 dst
[i
][2] = (rowA
[j
][2] + rowA
[k
][2] + rowB
[j
][2] + rowB
[k
][2]) / 4;
224 else if (datatype
== GL_BYTE
&& comps
== 2) {
226 const GLbyte(*rowA
)[2] = (const GLbyte(*)[2]) srcRowA
;
227 const GLbyte(*rowB
)[2] = (const GLbyte(*)[2]) srcRowB
;
228 GLbyte(*dst
)[2] = (GLbyte(*)[2]) dstRow
;
229 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
230 i
++, j
+= colStride
, k
+= colStride
) {
231 dst
[i
][0] = (rowA
[j
][0] + rowA
[k
][0] + rowB
[j
][0] + rowB
[k
][0]) / 4;
232 dst
[i
][1] = (rowA
[j
][1] + rowA
[k
][1] + rowB
[j
][1] + rowB
[k
][1]) / 4;
235 else if (datatype
== GL_BYTE
&& comps
== 1) {
237 const GLbyte
*rowA
= (const GLbyte
*) srcRowA
;
238 const GLbyte
*rowB
= (const GLbyte
*) srcRowB
;
239 GLbyte
*dst
= (GLbyte
*) dstRow
;
240 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
241 i
++, j
+= colStride
, k
+= colStride
) {
242 dst
[i
] = (rowA
[j
] + rowA
[k
] + rowB
[j
] + rowB
[k
]) / 4;
246 else if (datatype
== GL_UNSIGNED_SHORT
&& comps
== 4) {
248 const GLushort(*rowA
)[4] = (const GLushort(*)[4]) srcRowA
;
249 const GLushort(*rowB
)[4] = (const GLushort(*)[4]) srcRowB
;
250 GLushort(*dst
)[4] = (GLushort(*)[4]) dstRow
;
251 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
252 i
++, j
+= colStride
, k
+= colStride
) {
253 dst
[i
][0] = (rowA
[j
][0] + rowA
[k
][0] + rowB
[j
][0] + rowB
[k
][0]) / 4;
254 dst
[i
][1] = (rowA
[j
][1] + rowA
[k
][1] + rowB
[j
][1] + rowB
[k
][1]) / 4;
255 dst
[i
][2] = (rowA
[j
][2] + rowA
[k
][2] + rowB
[j
][2] + rowB
[k
][2]) / 4;
256 dst
[i
][3] = (rowA
[j
][3] + rowA
[k
][3] + rowB
[j
][3] + rowB
[k
][3]) / 4;
259 else if (datatype
== GL_UNSIGNED_SHORT
&& comps
== 3) {
261 const GLushort(*rowA
)[3] = (const GLushort(*)[3]) srcRowA
;
262 const GLushort(*rowB
)[3] = (const GLushort(*)[3]) srcRowB
;
263 GLushort(*dst
)[3] = (GLushort(*)[3]) dstRow
;
264 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
265 i
++, j
+= colStride
, k
+= colStride
) {
266 dst
[i
][0] = (rowA
[j
][0] + rowA
[k
][0] + rowB
[j
][0] + rowB
[k
][0]) / 4;
267 dst
[i
][1] = (rowA
[j
][1] + rowA
[k
][1] + rowB
[j
][1] + rowB
[k
][1]) / 4;
268 dst
[i
][2] = (rowA
[j
][2] + rowA
[k
][2] + rowB
[j
][2] + rowB
[k
][2]) / 4;
271 else if (datatype
== GL_UNSIGNED_SHORT
&& comps
== 2) {
273 const GLushort(*rowA
)[2] = (const GLushort(*)[2]) srcRowA
;
274 const GLushort(*rowB
)[2] = (const GLushort(*)[2]) srcRowB
;
275 GLushort(*dst
)[2] = (GLushort(*)[2]) dstRow
;
276 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
277 i
++, j
+= colStride
, k
+= colStride
) {
278 dst
[i
][0] = (rowA
[j
][0] + rowA
[k
][0] + rowB
[j
][0] + rowB
[k
][0]) / 4;
279 dst
[i
][1] = (rowA
[j
][1] + rowA
[k
][1] + rowB
[j
][1] + rowB
[k
][1]) / 4;
282 else if (datatype
== GL_UNSIGNED_SHORT
&& comps
== 1) {
284 const GLushort
*rowA
= (const GLushort
*) srcRowA
;
285 const GLushort
*rowB
= (const GLushort
*) srcRowB
;
286 GLushort
*dst
= (GLushort
*) dstRow
;
287 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
288 i
++, j
+= colStride
, k
+= colStride
) {
289 dst
[i
] = (rowA
[j
] + rowA
[k
] + rowB
[j
] + rowB
[k
]) / 4;
293 else if (datatype
== GL_SHORT
&& comps
== 4) {
295 const GLshort(*rowA
)[4] = (const GLshort(*)[4]) srcRowA
;
296 const GLshort(*rowB
)[4] = (const GLshort(*)[4]) srcRowB
;
297 GLshort(*dst
)[4] = (GLshort(*)[4]) dstRow
;
298 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
299 i
++, j
+= colStride
, k
+= colStride
) {
300 dst
[i
][0] = (rowA
[j
][0] + rowA
[k
][0] + rowB
[j
][0] + rowB
[k
][0]) / 4;
301 dst
[i
][1] = (rowA
[j
][1] + rowA
[k
][1] + rowB
[j
][1] + rowB
[k
][1]) / 4;
302 dst
[i
][2] = (rowA
[j
][2] + rowA
[k
][2] + rowB
[j
][2] + rowB
[k
][2]) / 4;
303 dst
[i
][3] = (rowA
[j
][3] + rowA
[k
][3] + rowB
[j
][3] + rowB
[k
][3]) / 4;
306 else if (datatype
== GL_SHORT
&& comps
== 3) {
308 const GLshort(*rowA
)[3] = (const GLshort(*)[3]) srcRowA
;
309 const GLshort(*rowB
)[3] = (const GLshort(*)[3]) srcRowB
;
310 GLshort(*dst
)[3] = (GLshort(*)[3]) dstRow
;
311 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
312 i
++, j
+= colStride
, k
+= colStride
) {
313 dst
[i
][0] = (rowA
[j
][0] + rowA
[k
][0] + rowB
[j
][0] + rowB
[k
][0]) / 4;
314 dst
[i
][1] = (rowA
[j
][1] + rowA
[k
][1] + rowB
[j
][1] + rowB
[k
][1]) / 4;
315 dst
[i
][2] = (rowA
[j
][2] + rowA
[k
][2] + rowB
[j
][2] + rowB
[k
][2]) / 4;
318 else if (datatype
== GL_SHORT
&& comps
== 2) {
320 const GLshort(*rowA
)[2] = (const GLshort(*)[2]) srcRowA
;
321 const GLshort(*rowB
)[2] = (const GLshort(*)[2]) srcRowB
;
322 GLshort(*dst
)[2] = (GLshort(*)[2]) dstRow
;
323 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
324 i
++, j
+= colStride
, k
+= colStride
) {
325 dst
[i
][0] = (rowA
[j
][0] + rowA
[k
][0] + rowB
[j
][0] + rowB
[k
][0]) / 4;
326 dst
[i
][1] = (rowA
[j
][1] + rowA
[k
][1] + rowB
[j
][1] + rowB
[k
][1]) / 4;
329 else if (datatype
== GL_SHORT
&& comps
== 1) {
331 const GLshort
*rowA
= (const GLshort
*) srcRowA
;
332 const GLshort
*rowB
= (const GLshort
*) srcRowB
;
333 GLshort
*dst
= (GLshort
*) dstRow
;
334 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
335 i
++, j
+= colStride
, k
+= colStride
) {
336 dst
[i
] = (rowA
[j
] + rowA
[k
] + rowB
[j
] + rowB
[k
]) / 4;
340 else if (datatype
== GL_FLOAT
&& comps
== 4) {
342 const GLfloat(*rowA
)[4] = (const GLfloat(*)[4]) srcRowA
;
343 const GLfloat(*rowB
)[4] = (const GLfloat(*)[4]) srcRowB
;
344 GLfloat(*dst
)[4] = (GLfloat(*)[4]) dstRow
;
345 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
346 i
++, j
+= colStride
, k
+= colStride
) {
347 dst
[i
][0] = (rowA
[j
][0] + rowA
[k
][0] +
348 rowB
[j
][0] + rowB
[k
][0]) * 0.25F
;
349 dst
[i
][1] = (rowA
[j
][1] + rowA
[k
][1] +
350 rowB
[j
][1] + rowB
[k
][1]) * 0.25F
;
351 dst
[i
][2] = (rowA
[j
][2] + rowA
[k
][2] +
352 rowB
[j
][2] + rowB
[k
][2]) * 0.25F
;
353 dst
[i
][3] = (rowA
[j
][3] + rowA
[k
][3] +
354 rowB
[j
][3] + rowB
[k
][3]) * 0.25F
;
357 else if (datatype
== GL_FLOAT
&& comps
== 3) {
359 const GLfloat(*rowA
)[3] = (const GLfloat(*)[3]) srcRowA
;
360 const GLfloat(*rowB
)[3] = (const GLfloat(*)[3]) srcRowB
;
361 GLfloat(*dst
)[3] = (GLfloat(*)[3]) dstRow
;
362 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
363 i
++, j
+= colStride
, k
+= colStride
) {
364 dst
[i
][0] = (rowA
[j
][0] + rowA
[k
][0] +
365 rowB
[j
][0] + rowB
[k
][0]) * 0.25F
;
366 dst
[i
][1] = (rowA
[j
][1] + rowA
[k
][1] +
367 rowB
[j
][1] + rowB
[k
][1]) * 0.25F
;
368 dst
[i
][2] = (rowA
[j
][2] + rowA
[k
][2] +
369 rowB
[j
][2] + rowB
[k
][2]) * 0.25F
;
372 else if (datatype
== GL_FLOAT
&& comps
== 2) {
374 const GLfloat(*rowA
)[2] = (const GLfloat(*)[2]) srcRowA
;
375 const GLfloat(*rowB
)[2] = (const GLfloat(*)[2]) srcRowB
;
376 GLfloat(*dst
)[2] = (GLfloat(*)[2]) dstRow
;
377 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
378 i
++, j
+= colStride
, k
+= colStride
) {
379 dst
[i
][0] = (rowA
[j
][0] + rowA
[k
][0] +
380 rowB
[j
][0] + rowB
[k
][0]) * 0.25F
;
381 dst
[i
][1] = (rowA
[j
][1] + rowA
[k
][1] +
382 rowB
[j
][1] + rowB
[k
][1]) * 0.25F
;
385 else if (datatype
== GL_FLOAT
&& comps
== 1) {
387 const GLfloat
*rowA
= (const GLfloat
*) srcRowA
;
388 const GLfloat
*rowB
= (const GLfloat
*) srcRowB
;
389 GLfloat
*dst
= (GLfloat
*) dstRow
;
390 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
391 i
++, j
+= colStride
, k
+= colStride
) {
392 dst
[i
] = (rowA
[j
] + rowA
[k
] + rowB
[j
] + rowB
[k
]) * 0.25F
;
396 else if (datatype
== GL_HALF_FLOAT_ARB
&& comps
== 4) {
397 GLuint i
, j
, k
, comp
;
398 const GLhalfARB(*rowA
)[4] = (const GLhalfARB(*)[4]) srcRowA
;
399 const GLhalfARB(*rowB
)[4] = (const GLhalfARB(*)[4]) srcRowB
;
400 GLhalfARB(*dst
)[4] = (GLhalfARB(*)[4]) dstRow
;
401 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
402 i
++, j
+= colStride
, k
+= colStride
) {
403 for (comp
= 0; comp
< 4; comp
++) {
404 GLfloat aj
, ak
, bj
, bk
;
405 aj
= _mesa_half_to_float(rowA
[j
][comp
]);
406 ak
= _mesa_half_to_float(rowA
[k
][comp
]);
407 bj
= _mesa_half_to_float(rowB
[j
][comp
]);
408 bk
= _mesa_half_to_float(rowB
[k
][comp
]);
409 dst
[i
][comp
] = _mesa_float_to_half((aj
+ ak
+ bj
+ bk
) * 0.25F
);
413 else if (datatype
== GL_HALF_FLOAT_ARB
&& comps
== 3) {
414 GLuint i
, j
, k
, comp
;
415 const GLhalfARB(*rowA
)[3] = (const GLhalfARB(*)[3]) srcRowA
;
416 const GLhalfARB(*rowB
)[3] = (const GLhalfARB(*)[3]) srcRowB
;
417 GLhalfARB(*dst
)[3] = (GLhalfARB(*)[3]) dstRow
;
418 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
419 i
++, j
+= colStride
, k
+= colStride
) {
420 for (comp
= 0; comp
< 3; comp
++) {
421 GLfloat aj
, ak
, bj
, bk
;
422 aj
= _mesa_half_to_float(rowA
[j
][comp
]);
423 ak
= _mesa_half_to_float(rowA
[k
][comp
]);
424 bj
= _mesa_half_to_float(rowB
[j
][comp
]);
425 bk
= _mesa_half_to_float(rowB
[k
][comp
]);
426 dst
[i
][comp
] = _mesa_float_to_half((aj
+ ak
+ bj
+ bk
) * 0.25F
);
430 else if (datatype
== GL_HALF_FLOAT_ARB
&& comps
== 2) {
431 GLuint i
, j
, k
, comp
;
432 const GLhalfARB(*rowA
)[2] = (const GLhalfARB(*)[2]) srcRowA
;
433 const GLhalfARB(*rowB
)[2] = (const GLhalfARB(*)[2]) srcRowB
;
434 GLhalfARB(*dst
)[2] = (GLhalfARB(*)[2]) dstRow
;
435 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
436 i
++, j
+= colStride
, k
+= colStride
) {
437 for (comp
= 0; comp
< 2; comp
++) {
438 GLfloat aj
, ak
, bj
, bk
;
439 aj
= _mesa_half_to_float(rowA
[j
][comp
]);
440 ak
= _mesa_half_to_float(rowA
[k
][comp
]);
441 bj
= _mesa_half_to_float(rowB
[j
][comp
]);
442 bk
= _mesa_half_to_float(rowB
[k
][comp
]);
443 dst
[i
][comp
] = _mesa_float_to_half((aj
+ ak
+ bj
+ bk
) * 0.25F
);
447 else if (datatype
== GL_HALF_FLOAT_ARB
&& comps
== 1) {
449 const GLhalfARB
*rowA
= (const GLhalfARB
*) srcRowA
;
450 const GLhalfARB
*rowB
= (const GLhalfARB
*) srcRowB
;
451 GLhalfARB
*dst
= (GLhalfARB
*) dstRow
;
452 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
453 i
++, j
+= colStride
, k
+= colStride
) {
454 GLfloat aj
, ak
, bj
, bk
;
455 aj
= _mesa_half_to_float(rowA
[j
]);
456 ak
= _mesa_half_to_float(rowA
[k
]);
457 bj
= _mesa_half_to_float(rowB
[j
]);
458 bk
= _mesa_half_to_float(rowB
[k
]);
459 dst
[i
] = _mesa_float_to_half((aj
+ ak
+ bj
+ bk
) * 0.25F
);
463 else if (datatype
== GL_UNSIGNED_INT
&& comps
== 1) {
465 const GLuint
*rowA
= (const GLuint
*) srcRowA
;
466 const GLuint
*rowB
= (const GLuint
*) srcRowB
;
467 GLuint
*dst
= (GLuint
*) dstRow
;
468 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
469 i
++, j
+= colStride
, k
+= colStride
) {
470 dst
[i
] = (GLfloat
)(rowA
[j
] / 4 + rowA
[k
] / 4 + rowB
[j
] / 4 + rowB
[k
] / 4);
474 else if (datatype
== GL_UNSIGNED_SHORT_5_6_5
&& comps
== 3) {
476 const GLushort
*rowA
= (const GLushort
*) srcRowA
;
477 const GLushort
*rowB
= (const GLushort
*) srcRowB
;
478 GLushort
*dst
= (GLushort
*) dstRow
;
479 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
480 i
++, j
+= colStride
, k
+= colStride
) {
481 const GLint rowAr0
= rowA
[j
] & 0x1f;
482 const GLint rowAr1
= rowA
[k
] & 0x1f;
483 const GLint rowBr0
= rowB
[j
] & 0x1f;
484 const GLint rowBr1
= rowB
[k
] & 0x1f;
485 const GLint rowAg0
= (rowA
[j
] >> 5) & 0x3f;
486 const GLint rowAg1
= (rowA
[k
] >> 5) & 0x3f;
487 const GLint rowBg0
= (rowB
[j
] >> 5) & 0x3f;
488 const GLint rowBg1
= (rowB
[k
] >> 5) & 0x3f;
489 const GLint rowAb0
= (rowA
[j
] >> 11) & 0x1f;
490 const GLint rowAb1
= (rowA
[k
] >> 11) & 0x1f;
491 const GLint rowBb0
= (rowB
[j
] >> 11) & 0x1f;
492 const GLint rowBb1
= (rowB
[k
] >> 11) & 0x1f;
493 const GLint red
= (rowAr0
+ rowAr1
+ rowBr0
+ rowBr1
) >> 2;
494 const GLint green
= (rowAg0
+ rowAg1
+ rowBg0
+ rowBg1
) >> 2;
495 const GLint blue
= (rowAb0
+ rowAb1
+ rowBb0
+ rowBb1
) >> 2;
496 dst
[i
] = (blue
<< 11) | (green
<< 5) | red
;
499 else if (datatype
== GL_UNSIGNED_SHORT_4_4_4_4
&& comps
== 4) {
501 const GLushort
*rowA
= (const GLushort
*) srcRowA
;
502 const GLushort
*rowB
= (const GLushort
*) srcRowB
;
503 GLushort
*dst
= (GLushort
*) dstRow
;
504 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
505 i
++, j
+= colStride
, k
+= colStride
) {
506 const GLint rowAr0
= rowA
[j
] & 0xf;
507 const GLint rowAr1
= rowA
[k
] & 0xf;
508 const GLint rowBr0
= rowB
[j
] & 0xf;
509 const GLint rowBr1
= rowB
[k
] & 0xf;
510 const GLint rowAg0
= (rowA
[j
] >> 4) & 0xf;
511 const GLint rowAg1
= (rowA
[k
] >> 4) & 0xf;
512 const GLint rowBg0
= (rowB
[j
] >> 4) & 0xf;
513 const GLint rowBg1
= (rowB
[k
] >> 4) & 0xf;
514 const GLint rowAb0
= (rowA
[j
] >> 8) & 0xf;
515 const GLint rowAb1
= (rowA
[k
] >> 8) & 0xf;
516 const GLint rowBb0
= (rowB
[j
] >> 8) & 0xf;
517 const GLint rowBb1
= (rowB
[k
] >> 8) & 0xf;
518 const GLint rowAa0
= (rowA
[j
] >> 12) & 0xf;
519 const GLint rowAa1
= (rowA
[k
] >> 12) & 0xf;
520 const GLint rowBa0
= (rowB
[j
] >> 12) & 0xf;
521 const GLint rowBa1
= (rowB
[k
] >> 12) & 0xf;
522 const GLint red
= (rowAr0
+ rowAr1
+ rowBr0
+ rowBr1
) >> 2;
523 const GLint green
= (rowAg0
+ rowAg1
+ rowBg0
+ rowBg1
) >> 2;
524 const GLint blue
= (rowAb0
+ rowAb1
+ rowBb0
+ rowBb1
) >> 2;
525 const GLint alpha
= (rowAa0
+ rowAa1
+ rowBa0
+ rowBa1
) >> 2;
526 dst
[i
] = (alpha
<< 12) | (blue
<< 8) | (green
<< 4) | red
;
529 else if (datatype
== GL_UNSIGNED_SHORT_1_5_5_5_REV
&& comps
== 4) {
531 const GLushort
*rowA
= (const GLushort
*) srcRowA
;
532 const GLushort
*rowB
= (const GLushort
*) srcRowB
;
533 GLushort
*dst
= (GLushort
*) dstRow
;
534 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
535 i
++, j
+= colStride
, k
+= colStride
) {
536 const GLint rowAr0
= rowA
[j
] & 0x1f;
537 const GLint rowAr1
= rowA
[k
] & 0x1f;
538 const GLint rowBr0
= rowB
[j
] & 0x1f;
539 const GLint rowBr1
= rowB
[k
] & 0x1f;
540 const GLint rowAg0
= (rowA
[j
] >> 5) & 0x1f;
541 const GLint rowAg1
= (rowA
[k
] >> 5) & 0x1f;
542 const GLint rowBg0
= (rowB
[j
] >> 5) & 0x1f;
543 const GLint rowBg1
= (rowB
[k
] >> 5) & 0x1f;
544 const GLint rowAb0
= (rowA
[j
] >> 10) & 0x1f;
545 const GLint rowAb1
= (rowA
[k
] >> 10) & 0x1f;
546 const GLint rowBb0
= (rowB
[j
] >> 10) & 0x1f;
547 const GLint rowBb1
= (rowB
[k
] >> 10) & 0x1f;
548 const GLint rowAa0
= (rowA
[j
] >> 15) & 0x1;
549 const GLint rowAa1
= (rowA
[k
] >> 15) & 0x1;
550 const GLint rowBa0
= (rowB
[j
] >> 15) & 0x1;
551 const GLint rowBa1
= (rowB
[k
] >> 15) & 0x1;
552 const GLint red
= (rowAr0
+ rowAr1
+ rowBr0
+ rowBr1
) >> 2;
553 const GLint green
= (rowAg0
+ rowAg1
+ rowBg0
+ rowBg1
) >> 2;
554 const GLint blue
= (rowAb0
+ rowAb1
+ rowBb0
+ rowBb1
) >> 2;
555 const GLint alpha
= (rowAa0
+ rowAa1
+ rowBa0
+ rowBa1
) >> 2;
556 dst
[i
] = (alpha
<< 15) | (blue
<< 10) | (green
<< 5) | red
;
559 else if (datatype
== GL_UNSIGNED_SHORT_5_5_5_1
&& comps
== 4) {
561 const GLushort
*rowA
= (const GLushort
*) srcRowA
;
562 const GLushort
*rowB
= (const GLushort
*) srcRowB
;
563 GLushort
*dst
= (GLushort
*) dstRow
;
564 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
565 i
++, j
+= colStride
, k
+= colStride
) {
566 const GLint rowAr0
= (rowA
[j
] >> 11) & 0x1f;
567 const GLint rowAr1
= (rowA
[k
] >> 11) & 0x1f;
568 const GLint rowBr0
= (rowB
[j
] >> 11) & 0x1f;
569 const GLint rowBr1
= (rowB
[k
] >> 11) & 0x1f;
570 const GLint rowAg0
= (rowA
[j
] >> 6) & 0x1f;
571 const GLint rowAg1
= (rowA
[k
] >> 6) & 0x1f;
572 const GLint rowBg0
= (rowB
[j
] >> 6) & 0x1f;
573 const GLint rowBg1
= (rowB
[k
] >> 6) & 0x1f;
574 const GLint rowAb0
= (rowA
[j
] >> 1) & 0x1f;
575 const GLint rowAb1
= (rowA
[k
] >> 1) & 0x1f;
576 const GLint rowBb0
= (rowB
[j
] >> 1) & 0x1f;
577 const GLint rowBb1
= (rowB
[k
] >> 1) & 0x1f;
578 const GLint rowAa0
= (rowA
[j
] & 0x1);
579 const GLint rowAa1
= (rowA
[k
] & 0x1);
580 const GLint rowBa0
= (rowB
[j
] & 0x1);
581 const GLint rowBa1
= (rowB
[k
] & 0x1);
582 const GLint red
= (rowAr0
+ rowAr1
+ rowBr0
+ rowBr1
) >> 2;
583 const GLint green
= (rowAg0
+ rowAg1
+ rowBg0
+ rowBg1
) >> 2;
584 const GLint blue
= (rowAb0
+ rowAb1
+ rowBb0
+ rowBb1
) >> 2;
585 const GLint alpha
= (rowAa0
+ rowAa1
+ rowBa0
+ rowBa1
) >> 2;
586 dst
[i
] = (red
<< 11) | (green
<< 6) | (blue
<< 1) | alpha
;
590 else if (datatype
== GL_UNSIGNED_BYTE_3_3_2
&& comps
== 3) {
592 const GLubyte
*rowA
= (const GLubyte
*) srcRowA
;
593 const GLubyte
*rowB
= (const GLubyte
*) srcRowB
;
594 GLubyte
*dst
= (GLubyte
*) dstRow
;
595 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
596 i
++, j
+= colStride
, k
+= colStride
) {
597 const GLint rowAr0
= rowA
[j
] & 0x3;
598 const GLint rowAr1
= rowA
[k
] & 0x3;
599 const GLint rowBr0
= rowB
[j
] & 0x3;
600 const GLint rowBr1
= rowB
[k
] & 0x3;
601 const GLint rowAg0
= (rowA
[j
] >> 2) & 0x7;
602 const GLint rowAg1
= (rowA
[k
] >> 2) & 0x7;
603 const GLint rowBg0
= (rowB
[j
] >> 2) & 0x7;
604 const GLint rowBg1
= (rowB
[k
] >> 2) & 0x7;
605 const GLint rowAb0
= (rowA
[j
] >> 5) & 0x7;
606 const GLint rowAb1
= (rowA
[k
] >> 5) & 0x7;
607 const GLint rowBb0
= (rowB
[j
] >> 5) & 0x7;
608 const GLint rowBb1
= (rowB
[k
] >> 5) & 0x7;
609 const GLint red
= (rowAr0
+ rowAr1
+ rowBr0
+ rowBr1
) >> 2;
610 const GLint green
= (rowAg0
+ rowAg1
+ rowBg0
+ rowBg1
) >> 2;
611 const GLint blue
= (rowAb0
+ rowAb1
+ rowBb0
+ rowBb1
) >> 2;
612 dst
[i
] = (blue
<< 5) | (green
<< 2) | red
;
616 else if (datatype
== MESA_UNSIGNED_BYTE_4_4
&& comps
== 2) {
618 const GLubyte
*rowA
= (const GLubyte
*) srcRowA
;
619 const GLubyte
*rowB
= (const GLubyte
*) srcRowB
;
620 GLubyte
*dst
= (GLubyte
*) dstRow
;
621 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
622 i
++, j
+= colStride
, k
+= colStride
) {
623 const GLint rowAr0
= rowA
[j
] & 0xf;
624 const GLint rowAr1
= rowA
[k
] & 0xf;
625 const GLint rowBr0
= rowB
[j
] & 0xf;
626 const GLint rowBr1
= rowB
[k
] & 0xf;
627 const GLint rowAg0
= (rowA
[j
] >> 4) & 0xf;
628 const GLint rowAg1
= (rowA
[k
] >> 4) & 0xf;
629 const GLint rowBg0
= (rowB
[j
] >> 4) & 0xf;
630 const GLint rowBg1
= (rowB
[k
] >> 4) & 0xf;
631 const GLint r
= (rowAr0
+ rowAr1
+ rowBr0
+ rowBr1
) >> 2;
632 const GLint g
= (rowAg0
+ rowAg1
+ rowBg0
+ rowBg1
) >> 2;
633 dst
[i
] = (g
<< 4) | r
;
638 _mesa_problem(NULL
, "bad format in do_row()");
644 * Average together four rows of a source image to produce a single new
645 * row in the dest image. It's legal for the two source rows to point
646 * to the same data. The source width must be equal to either the
647 * dest width or two times the dest width.
649 * \param datatype GL pixel type \c GL_UNSIGNED_BYTE, \c GL_UNSIGNED_SHORT,
651 * \param comps number of components per pixel (1..4)
652 * \param srcWidth Width of a row in the source data
653 * \param srcRowA Pointer to one of the rows of source data
654 * \param srcRowB Pointer to one of the rows of source data
655 * \param srcRowC Pointer to one of the rows of source data
656 * \param srcRowD Pointer to one of the rows of source data
657 * \param dstWidth Width of a row in the destination data
658 * \param srcRowA Pointer to the row of destination data
661 do_row_3D(GLenum datatype
, GLuint comps
, GLint srcWidth
,
662 const GLvoid
*srcRowA
, const GLvoid
*srcRowB
,
663 const GLvoid
*srcRowC
, const GLvoid
*srcRowD
,
664 GLint dstWidth
, GLvoid
*dstRow
)
666 const GLuint k0
= (srcWidth
== dstWidth
) ? 0 : 1;
667 const GLuint colStride
= (srcWidth
== dstWidth
) ? 1 : 2;
673 if ((datatype
== GL_UNSIGNED_BYTE
) && (comps
== 4)) {
674 DECLARE_ROW_POINTERS(GLubyte
, 4);
676 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
677 i
++, j
+= colStride
, k
+= colStride
) {
684 else if ((datatype
== GL_UNSIGNED_BYTE
) && (comps
== 3)) {
685 DECLARE_ROW_POINTERS(GLubyte
, 3);
687 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
688 i
++, j
+= colStride
, k
+= colStride
) {
694 else if ((datatype
== GL_UNSIGNED_BYTE
) && (comps
== 2)) {
695 DECLARE_ROW_POINTERS(GLubyte
, 2);
697 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
698 i
++, j
+= colStride
, k
+= colStride
) {
703 else if ((datatype
== GL_UNSIGNED_BYTE
) && (comps
== 1)) {
704 DECLARE_ROW_POINTERS(GLubyte
, 1);
706 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
707 i
++, j
+= colStride
, k
+= colStride
) {
711 else if ((datatype
== GL_BYTE
) && (comps
== 4)) {
712 DECLARE_ROW_POINTERS(GLbyte
, 4);
714 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
715 i
++, j
+= colStride
, k
+= colStride
) {
722 else if ((datatype
== GL_BYTE
) && (comps
== 3)) {
723 DECLARE_ROW_POINTERS(GLbyte
, 3);
725 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
726 i
++, j
+= colStride
, k
+= colStride
) {
732 else if ((datatype
== GL_BYTE
) && (comps
== 2)) {
733 DECLARE_ROW_POINTERS(GLbyte
, 2);
735 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
736 i
++, j
+= colStride
, k
+= colStride
) {
741 else if ((datatype
== GL_BYTE
) && (comps
== 1)) {
742 DECLARE_ROW_POINTERS(GLbyte
, 1);
744 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
745 i
++, j
+= colStride
, k
+= colStride
) {
749 else if ((datatype
== GL_UNSIGNED_SHORT
) && (comps
== 4)) {
750 DECLARE_ROW_POINTERS(GLushort
, 4);
752 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
753 i
++, j
+= colStride
, k
+= colStride
) {
760 else if ((datatype
== GL_UNSIGNED_SHORT
) && (comps
== 3)) {
761 DECLARE_ROW_POINTERS(GLushort
, 3);
763 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
764 i
++, j
+= colStride
, k
+= colStride
) {
770 else if ((datatype
== GL_UNSIGNED_SHORT
) && (comps
== 2)) {
771 DECLARE_ROW_POINTERS(GLushort
, 2);
773 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
774 i
++, j
+= colStride
, k
+= colStride
) {
779 else if ((datatype
== GL_UNSIGNED_SHORT
) && (comps
== 1)) {
780 DECLARE_ROW_POINTERS(GLushort
, 1);
782 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
783 i
++, j
+= colStride
, k
+= colStride
) {
787 else if ((datatype
== GL_SHORT
) && (comps
== 4)) {
788 DECLARE_ROW_POINTERS(GLshort
, 4);
790 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
791 i
++, j
+= colStride
, k
+= colStride
) {
798 else if ((datatype
== GL_SHORT
) && (comps
== 3)) {
799 DECLARE_ROW_POINTERS(GLshort
, 3);
801 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
802 i
++, j
+= colStride
, k
+= colStride
) {
808 else if ((datatype
== GL_SHORT
) && (comps
== 2)) {
809 DECLARE_ROW_POINTERS(GLshort
, 2);
811 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
812 i
++, j
+= colStride
, k
+= colStride
) {
817 else if ((datatype
== GL_SHORT
) && (comps
== 1)) {
818 DECLARE_ROW_POINTERS(GLshort
, 1);
820 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
821 i
++, j
+= colStride
, k
+= colStride
) {
825 else if ((datatype
== GL_FLOAT
) && (comps
== 4)) {
826 DECLARE_ROW_POINTERS(GLfloat
, 4);
828 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
829 i
++, j
+= colStride
, k
+= colStride
) {
836 else if ((datatype
== GL_FLOAT
) && (comps
== 3)) {
837 DECLARE_ROW_POINTERS(GLfloat
, 3);
839 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
840 i
++, j
+= colStride
, k
+= colStride
) {
846 else if ((datatype
== GL_FLOAT
) && (comps
== 2)) {
847 DECLARE_ROW_POINTERS(GLfloat
, 2);
849 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
850 i
++, j
+= colStride
, k
+= colStride
) {
855 else if ((datatype
== GL_FLOAT
) && (comps
== 1)) {
856 DECLARE_ROW_POINTERS(GLfloat
, 1);
858 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
859 i
++, j
+= colStride
, k
+= colStride
) {
863 else if ((datatype
== GL_HALF_FLOAT_ARB
) && (comps
== 4)) {
864 DECLARE_ROW_POINTERS(GLhalfARB
, 4);
866 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
867 i
++, j
+= colStride
, k
+= colStride
) {
874 else if ((datatype
== GL_HALF_FLOAT_ARB
) && (comps
== 3)) {
875 DECLARE_ROW_POINTERS(GLhalfARB
, 4);
877 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
878 i
++, j
+= colStride
, k
+= colStride
) {
884 else if ((datatype
== GL_HALF_FLOAT_ARB
) && (comps
== 2)) {
885 DECLARE_ROW_POINTERS(GLhalfARB
, 4);
887 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
888 i
++, j
+= colStride
, k
+= colStride
) {
893 else if ((datatype
== GL_HALF_FLOAT_ARB
) && (comps
== 1)) {
894 DECLARE_ROW_POINTERS(GLhalfARB
, 4);
896 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
897 i
++, j
+= colStride
, k
+= colStride
) {
901 else if ((datatype
== GL_UNSIGNED_INT
) && (comps
== 1)) {
902 const GLuint
*rowA
= (const GLuint
*) srcRowA
;
903 const GLuint
*rowB
= (const GLuint
*) srcRowB
;
904 const GLuint
*rowC
= (const GLuint
*) srcRowC
;
905 const GLuint
*rowD
= (const GLuint
*) srcRowD
;
906 GLfloat
*dst
= (GLfloat
*) dstRow
;
908 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
909 i
++, j
+= colStride
, k
+= colStride
) {
910 const uint64_t tmp
= (((uint64_t) rowA
[j
] + (uint64_t) rowA
[k
])
911 + ((uint64_t) rowB
[j
] + (uint64_t) rowB
[k
])
912 + ((uint64_t) rowC
[j
] + (uint64_t) rowC
[k
])
913 + ((uint64_t) rowD
[j
] + (uint64_t) rowD
[k
]));
914 dst
[i
] = (GLfloat
)((double) tmp
* 0.125);
917 else if ((datatype
== GL_UNSIGNED_SHORT_5_6_5
) && (comps
== 3)) {
918 DECLARE_ROW_POINTERS0(GLushort
);
920 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
921 i
++, j
+= colStride
, k
+= colStride
) {
922 const GLint rowAr0
= rowA
[j
] & 0x1f;
923 const GLint rowAr1
= rowA
[k
] & 0x1f;
924 const GLint rowBr0
= rowB
[j
] & 0x1f;
925 const GLint rowBr1
= rowB
[k
] & 0x1f;
926 const GLint rowCr0
= rowC
[j
] & 0x1f;
927 const GLint rowCr1
= rowC
[k
] & 0x1f;
928 const GLint rowDr0
= rowD
[j
] & 0x1f;
929 const GLint rowDr1
= rowD
[k
] & 0x1f;
930 const GLint rowAg0
= (rowA
[j
] >> 5) & 0x3f;
931 const GLint rowAg1
= (rowA
[k
] >> 5) & 0x3f;
932 const GLint rowBg0
= (rowB
[j
] >> 5) & 0x3f;
933 const GLint rowBg1
= (rowB
[k
] >> 5) & 0x3f;
934 const GLint rowCg0
= (rowC
[j
] >> 5) & 0x3f;
935 const GLint rowCg1
= (rowC
[k
] >> 5) & 0x3f;
936 const GLint rowDg0
= (rowD
[j
] >> 5) & 0x3f;
937 const GLint rowDg1
= (rowD
[k
] >> 5) & 0x3f;
938 const GLint rowAb0
= (rowA
[j
] >> 11) & 0x1f;
939 const GLint rowAb1
= (rowA
[k
] >> 11) & 0x1f;
940 const GLint rowBb0
= (rowB
[j
] >> 11) & 0x1f;
941 const GLint rowBb1
= (rowB
[k
] >> 11) & 0x1f;
942 const GLint rowCb0
= (rowC
[j
] >> 11) & 0x1f;
943 const GLint rowCb1
= (rowC
[k
] >> 11) & 0x1f;
944 const GLint rowDb0
= (rowD
[j
] >> 11) & 0x1f;
945 const GLint rowDb1
= (rowD
[k
] >> 11) & 0x1f;
946 const GLint r
= FILTER_SUM_3D(rowAr0
, rowAr1
, rowBr0
, rowBr1
,
947 rowCr0
, rowCr1
, rowDr0
, rowDr1
);
948 const GLint g
= FILTER_SUM_3D(rowAg0
, rowAg1
, rowBg0
, rowBg1
,
949 rowCg0
, rowCg1
, rowDg0
, rowDg1
);
950 const GLint b
= FILTER_SUM_3D(rowAb0
, rowAb1
, rowBb0
, rowBb1
,
951 rowCb0
, rowCb1
, rowDb0
, rowDb1
);
952 dst
[i
] = (b
<< 11) | (g
<< 5) | r
;
955 else if ((datatype
== GL_UNSIGNED_SHORT_4_4_4_4
) && (comps
== 4)) {
956 DECLARE_ROW_POINTERS0(GLushort
);
958 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
959 i
++, j
+= colStride
, k
+= colStride
) {
960 const GLint rowAr0
= rowA
[j
] & 0xf;
961 const GLint rowAr1
= rowA
[k
] & 0xf;
962 const GLint rowBr0
= rowB
[j
] & 0xf;
963 const GLint rowBr1
= rowB
[k
] & 0xf;
964 const GLint rowCr0
= rowC
[j
] & 0xf;
965 const GLint rowCr1
= rowC
[k
] & 0xf;
966 const GLint rowDr0
= rowD
[j
] & 0xf;
967 const GLint rowDr1
= rowD
[k
] & 0xf;
968 const GLint rowAg0
= (rowA
[j
] >> 4) & 0xf;
969 const GLint rowAg1
= (rowA
[k
] >> 4) & 0xf;
970 const GLint rowBg0
= (rowB
[j
] >> 4) & 0xf;
971 const GLint rowBg1
= (rowB
[k
] >> 4) & 0xf;
972 const GLint rowCg0
= (rowC
[j
] >> 4) & 0xf;
973 const GLint rowCg1
= (rowC
[k
] >> 4) & 0xf;
974 const GLint rowDg0
= (rowD
[j
] >> 4) & 0xf;
975 const GLint rowDg1
= (rowD
[k
] >> 4) & 0xf;
976 const GLint rowAb0
= (rowA
[j
] >> 8) & 0xf;
977 const GLint rowAb1
= (rowA
[k
] >> 8) & 0xf;
978 const GLint rowBb0
= (rowB
[j
] >> 8) & 0xf;
979 const GLint rowBb1
= (rowB
[k
] >> 8) & 0xf;
980 const GLint rowCb0
= (rowC
[j
] >> 8) & 0xf;
981 const GLint rowCb1
= (rowC
[k
] >> 8) & 0xf;
982 const GLint rowDb0
= (rowD
[j
] >> 8) & 0xf;
983 const GLint rowDb1
= (rowD
[k
] >> 8) & 0xf;
984 const GLint rowAa0
= (rowA
[j
] >> 12) & 0xf;
985 const GLint rowAa1
= (rowA
[k
] >> 12) & 0xf;
986 const GLint rowBa0
= (rowB
[j
] >> 12) & 0xf;
987 const GLint rowBa1
= (rowB
[k
] >> 12) & 0xf;
988 const GLint rowCa0
= (rowC
[j
] >> 12) & 0xf;
989 const GLint rowCa1
= (rowC
[k
] >> 12) & 0xf;
990 const GLint rowDa0
= (rowD
[j
] >> 12) & 0xf;
991 const GLint rowDa1
= (rowD
[k
] >> 12) & 0xf;
992 const GLint r
= FILTER_SUM_3D(rowAr0
, rowAr1
, rowBr0
, rowBr1
,
993 rowCr0
, rowCr1
, rowDr0
, rowDr1
);
994 const GLint g
= FILTER_SUM_3D(rowAg0
, rowAg1
, rowBg0
, rowBg1
,
995 rowCg0
, rowCg1
, rowDg0
, rowDg1
);
996 const GLint b
= FILTER_SUM_3D(rowAb0
, rowAb1
, rowBb0
, rowBb1
,
997 rowCb0
, rowCb1
, rowDb0
, rowDb1
);
998 const GLint a
= FILTER_SUM_3D(rowAa0
, rowAa1
, rowBa0
, rowBa1
,
999 rowCa0
, rowCa1
, rowDa0
, rowDa1
);
1001 dst
[i
] = (a
<< 12) | (b
<< 8) | (g
<< 4) | r
;
1004 else if ((datatype
== GL_UNSIGNED_SHORT_1_5_5_5_REV
) && (comps
== 4)) {
1005 DECLARE_ROW_POINTERS0(GLushort
);
1007 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
1008 i
++, j
+= colStride
, k
+= colStride
) {
1009 const GLint rowAr0
= rowA
[j
] & 0x1f;
1010 const GLint rowAr1
= rowA
[k
] & 0x1f;
1011 const GLint rowBr0
= rowB
[j
] & 0x1f;
1012 const GLint rowBr1
= rowB
[k
] & 0x1f;
1013 const GLint rowCr0
= rowC
[j
] & 0x1f;
1014 const GLint rowCr1
= rowC
[k
] & 0x1f;
1015 const GLint rowDr0
= rowD
[j
] & 0x1f;
1016 const GLint rowDr1
= rowD
[k
] & 0x1f;
1017 const GLint rowAg0
= (rowA
[j
] >> 5) & 0x1f;
1018 const GLint rowAg1
= (rowA
[k
] >> 5) & 0x1f;
1019 const GLint rowBg0
= (rowB
[j
] >> 5) & 0x1f;
1020 const GLint rowBg1
= (rowB
[k
] >> 5) & 0x1f;
1021 const GLint rowCg0
= (rowC
[j
] >> 5) & 0x1f;
1022 const GLint rowCg1
= (rowC
[k
] >> 5) & 0x1f;
1023 const GLint rowDg0
= (rowD
[j
] >> 5) & 0x1f;
1024 const GLint rowDg1
= (rowD
[k
] >> 5) & 0x1f;
1025 const GLint rowAb0
= (rowA
[j
] >> 10) & 0x1f;
1026 const GLint rowAb1
= (rowA
[k
] >> 10) & 0x1f;
1027 const GLint rowBb0
= (rowB
[j
] >> 10) & 0x1f;
1028 const GLint rowBb1
= (rowB
[k
] >> 10) & 0x1f;
1029 const GLint rowCb0
= (rowC
[j
] >> 10) & 0x1f;
1030 const GLint rowCb1
= (rowC
[k
] >> 10) & 0x1f;
1031 const GLint rowDb0
= (rowD
[j
] >> 10) & 0x1f;
1032 const GLint rowDb1
= (rowD
[k
] >> 10) & 0x1f;
1033 const GLint rowAa0
= (rowA
[j
] >> 15) & 0x1;
1034 const GLint rowAa1
= (rowA
[k
] >> 15) & 0x1;
1035 const GLint rowBa0
= (rowB
[j
] >> 15) & 0x1;
1036 const GLint rowBa1
= (rowB
[k
] >> 15) & 0x1;
1037 const GLint rowCa0
= (rowC
[j
] >> 15) & 0x1;
1038 const GLint rowCa1
= (rowC
[k
] >> 15) & 0x1;
1039 const GLint rowDa0
= (rowD
[j
] >> 15) & 0x1;
1040 const GLint rowDa1
= (rowD
[k
] >> 15) & 0x1;
1041 const GLint r
= FILTER_SUM_3D(rowAr0
, rowAr1
, rowBr0
, rowBr1
,
1042 rowCr0
, rowCr1
, rowDr0
, rowDr1
);
1043 const GLint g
= FILTER_SUM_3D(rowAg0
, rowAg1
, rowBg0
, rowBg1
,
1044 rowCg0
, rowCg1
, rowDg0
, rowDg1
);
1045 const GLint b
= FILTER_SUM_3D(rowAb0
, rowAb1
, rowBb0
, rowBb1
,
1046 rowCb0
, rowCb1
, rowDb0
, rowDb1
);
1047 const GLint a
= FILTER_SUM_3D(rowAa0
, rowAa1
, rowBa0
, rowBa1
,
1048 rowCa0
, rowCa1
, rowDa0
, rowDa1
);
1050 dst
[i
] = (a
<< 15) | (b
<< 10) | (g
<< 5) | r
;
1053 else if ((datatype
== GL_UNSIGNED_SHORT_5_5_5_1
) && (comps
== 4)) {
1054 DECLARE_ROW_POINTERS0(GLushort
);
1056 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
1057 i
++, j
+= colStride
, k
+= colStride
) {
1058 const GLint rowAr0
= (rowA
[j
] >> 11) & 0x1f;
1059 const GLint rowAr1
= (rowA
[k
] >> 11) & 0x1f;
1060 const GLint rowBr0
= (rowB
[j
] >> 11) & 0x1f;
1061 const GLint rowBr1
= (rowB
[k
] >> 11) & 0x1f;
1062 const GLint rowCr0
= (rowC
[j
] >> 11) & 0x1f;
1063 const GLint rowCr1
= (rowC
[k
] >> 11) & 0x1f;
1064 const GLint rowDr0
= (rowD
[j
] >> 11) & 0x1f;
1065 const GLint rowDr1
= (rowD
[k
] >> 11) & 0x1f;
1066 const GLint rowAg0
= (rowA
[j
] >> 6) & 0x1f;
1067 const GLint rowAg1
= (rowA
[k
] >> 6) & 0x1f;
1068 const GLint rowBg0
= (rowB
[j
] >> 6) & 0x1f;
1069 const GLint rowBg1
= (rowB
[k
] >> 6) & 0x1f;
1070 const GLint rowCg0
= (rowC
[j
] >> 6) & 0x1f;
1071 const GLint rowCg1
= (rowC
[k
] >> 6) & 0x1f;
1072 const GLint rowDg0
= (rowD
[j
] >> 6) & 0x1f;
1073 const GLint rowDg1
= (rowD
[k
] >> 6) & 0x1f;
1074 const GLint rowAb0
= (rowA
[j
] >> 1) & 0x1f;
1075 const GLint rowAb1
= (rowA
[k
] >> 1) & 0x1f;
1076 const GLint rowBb0
= (rowB
[j
] >> 1) & 0x1f;
1077 const GLint rowBb1
= (rowB
[k
] >> 1) & 0x1f;
1078 const GLint rowCb0
= (rowC
[j
] >> 1) & 0x1f;
1079 const GLint rowCb1
= (rowC
[k
] >> 1) & 0x1f;
1080 const GLint rowDb0
= (rowD
[j
] >> 1) & 0x1f;
1081 const GLint rowDb1
= (rowD
[k
] >> 1) & 0x1f;
1082 const GLint rowAa0
= (rowA
[j
] & 0x1);
1083 const GLint rowAa1
= (rowA
[k
] & 0x1);
1084 const GLint rowBa0
= (rowB
[j
] & 0x1);
1085 const GLint rowBa1
= (rowB
[k
] & 0x1);
1086 const GLint rowCa0
= (rowC
[j
] & 0x1);
1087 const GLint rowCa1
= (rowC
[k
] & 0x1);
1088 const GLint rowDa0
= (rowD
[j
] & 0x1);
1089 const GLint rowDa1
= (rowD
[k
] & 0x1);
1090 const GLint r
= FILTER_SUM_3D(rowAr0
, rowAr1
, rowBr0
, rowBr1
,
1091 rowCr0
, rowCr1
, rowDr0
, rowDr1
);
1092 const GLint g
= FILTER_SUM_3D(rowAg0
, rowAg1
, rowBg0
, rowBg1
,
1093 rowCg0
, rowCg1
, rowDg0
, rowDg1
);
1094 const GLint b
= FILTER_SUM_3D(rowAb0
, rowAb1
, rowBb0
, rowBb1
,
1095 rowCb0
, rowCb1
, rowDb0
, rowDb1
);
1096 const GLint a
= FILTER_SUM_3D(rowAa0
, rowAa1
, rowBa0
, rowBa1
,
1097 rowCa0
, rowCa1
, rowDa0
, rowDa1
);
1099 dst
[i
] = (r
<< 11) | (g
<< 6) | (b
<< 1) | a
;
1102 else if ((datatype
== GL_UNSIGNED_BYTE_3_3_2
) && (comps
== 3)) {
1103 DECLARE_ROW_POINTERS0(GLubyte
);
1105 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
1106 i
++, j
+= colStride
, k
+= colStride
) {
1107 const GLint rowAr0
= rowA
[j
] & 0x3;
1108 const GLint rowAr1
= rowA
[k
] & 0x3;
1109 const GLint rowBr0
= rowB
[j
] & 0x3;
1110 const GLint rowBr1
= rowB
[k
] & 0x3;
1111 const GLint rowCr0
= rowC
[j
] & 0x3;
1112 const GLint rowCr1
= rowC
[k
] & 0x3;
1113 const GLint rowDr0
= rowD
[j
] & 0x3;
1114 const GLint rowDr1
= rowD
[k
] & 0x3;
1115 const GLint rowAg0
= (rowA
[j
] >> 2) & 0x7;
1116 const GLint rowAg1
= (rowA
[k
] >> 2) & 0x7;
1117 const GLint rowBg0
= (rowB
[j
] >> 2) & 0x7;
1118 const GLint rowBg1
= (rowB
[k
] >> 2) & 0x7;
1119 const GLint rowCg0
= (rowC
[j
] >> 2) & 0x7;
1120 const GLint rowCg1
= (rowC
[k
] >> 2) & 0x7;
1121 const GLint rowDg0
= (rowD
[j
] >> 2) & 0x7;
1122 const GLint rowDg1
= (rowD
[k
] >> 2) & 0x7;
1123 const GLint rowAb0
= (rowA
[j
] >> 5) & 0x7;
1124 const GLint rowAb1
= (rowA
[k
] >> 5) & 0x7;
1125 const GLint rowBb0
= (rowB
[j
] >> 5) & 0x7;
1126 const GLint rowBb1
= (rowB
[k
] >> 5) & 0x7;
1127 const GLint rowCb0
= (rowC
[j
] >> 5) & 0x7;
1128 const GLint rowCb1
= (rowC
[k
] >> 5) & 0x7;
1129 const GLint rowDb0
= (rowD
[j
] >> 5) & 0x7;
1130 const GLint rowDb1
= (rowD
[k
] >> 5) & 0x7;
1131 const GLint r
= FILTER_SUM_3D(rowAr0
, rowAr1
, rowBr0
, rowBr1
,
1132 rowCr0
, rowCr1
, rowDr0
, rowDr1
);
1133 const GLint g
= FILTER_SUM_3D(rowAg0
, rowAg1
, rowBg0
, rowBg1
,
1134 rowCg0
, rowCg1
, rowDg0
, rowDg1
);
1135 const GLint b
= FILTER_SUM_3D(rowAb0
, rowAb1
, rowBb0
, rowBb1
,
1136 rowCb0
, rowCb1
, rowDb0
, rowDb1
);
1137 dst
[i
] = (b
<< 5) | (g
<< 2) | r
;
1140 else if (datatype
== MESA_UNSIGNED_BYTE_4_4
&& comps
== 2) {
1141 DECLARE_ROW_POINTERS0(GLubyte
);
1143 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
1144 i
++, j
+= colStride
, k
+= colStride
) {
1145 const GLint rowAr0
= rowA
[j
] & 0xf;
1146 const GLint rowAr1
= rowA
[k
] & 0xf;
1147 const GLint rowBr0
= rowB
[j
] & 0xf;
1148 const GLint rowBr1
= rowB
[k
] & 0xf;
1149 const GLint rowCr0
= rowC
[j
] & 0xf;
1150 const GLint rowCr1
= rowC
[k
] & 0xf;
1151 const GLint rowDr0
= rowD
[j
] & 0xf;
1152 const GLint rowDr1
= rowD
[k
] & 0xf;
1153 const GLint rowAg0
= (rowA
[j
] >> 4) & 0xf;
1154 const GLint rowAg1
= (rowA
[k
] >> 4) & 0xf;
1155 const GLint rowBg0
= (rowB
[j
] >> 4) & 0xf;
1156 const GLint rowBg1
= (rowB
[k
] >> 4) & 0xf;
1157 const GLint rowCg0
= (rowC
[j
] >> 4) & 0xf;
1158 const GLint rowCg1
= (rowC
[k
] >> 4) & 0xf;
1159 const GLint rowDg0
= (rowD
[j
] >> 4) & 0xf;
1160 const GLint rowDg1
= (rowD
[k
] >> 4) & 0xf;
1161 const GLint r
= FILTER_SUM_3D(rowAr0
, rowAr1
, rowBr0
, rowBr1
,
1162 rowCr0
, rowCr1
, rowDr0
, rowDr1
);
1163 const GLint g
= FILTER_SUM_3D(rowAg0
, rowAg1
, rowBg0
, rowBg1
,
1164 rowCg0
, rowCg1
, rowDg0
, rowDg1
);
1165 dst
[i
] = (g
<< 4) | r
;
1169 _mesa_problem(NULL
, "bad format in do_row()");
1175 * These functions generate a 1/2-size mipmap image from a source image.
1176 * Texture borders are handled by copying or averaging the source image's
1177 * border texels, depending on the scale-down factor.
1181 make_1d_mipmap(GLenum datatype
, GLuint comps
, GLint border
,
1182 GLint srcWidth
, const GLubyte
*srcPtr
,
1183 GLint dstWidth
, GLubyte
*dstPtr
)
1185 const GLint bpt
= bytes_per_pixel(datatype
, comps
);
1189 /* skip the border pixel, if any */
1190 src
= srcPtr
+ border
* bpt
;
1191 dst
= dstPtr
+ border
* bpt
;
1193 /* we just duplicate the input row, kind of hack, saves code */
1194 do_row(datatype
, comps
, srcWidth
- 2 * border
, src
, src
,
1195 dstWidth
- 2 * border
, dst
);
1198 /* copy left-most pixel from source */
1201 memcpy(dstPtr
, srcPtr
, bpt
);
1202 /* copy right-most pixel from source */
1203 memcpy(dstPtr
+ (dstWidth
- 1) * bpt
,
1204 srcPtr
+ (srcWidth
- 1) * bpt
,
1211 make_2d_mipmap(GLenum datatype
, GLuint comps
, GLint border
,
1212 GLint srcWidth
, GLint srcHeight
,
1213 const GLubyte
*srcPtr
, GLint srcRowStride
,
1214 GLint dstWidth
, GLint dstHeight
,
1215 GLubyte
*dstPtr
, GLint dstRowStride
)
1217 const GLint bpt
= bytes_per_pixel(datatype
, comps
);
1218 const GLint srcWidthNB
= srcWidth
- 2 * border
; /* sizes w/out border */
1219 const GLint dstWidthNB
= dstWidth
- 2 * border
;
1220 const GLint dstHeightNB
= dstHeight
- 2 * border
;
1221 const GLint srcRowBytes
= bpt
* srcRowStride
;
1222 const GLint dstRowBytes
= bpt
* dstRowStride
;
1223 const GLubyte
*srcA
, *srcB
;
1225 GLint row
, srcRowStep
;
1227 /* Compute src and dst pointers, skipping any border */
1228 srcA
= srcPtr
+ border
* ((srcWidth
+ 1) * bpt
);
1229 if (srcHeight
> 1 && srcHeight
> dstHeight
) {
1230 /* sample from two source rows */
1231 srcB
= srcA
+ srcRowBytes
;
1235 /* sample from one source row */
1240 dst
= dstPtr
+ border
* ((dstWidth
+ 1) * bpt
);
1242 for (row
= 0; row
< dstHeightNB
; row
++) {
1243 do_row(datatype
, comps
, srcWidthNB
, srcA
, srcB
,
1245 srcA
+= srcRowStep
* srcRowBytes
;
1246 srcB
+= srcRowStep
* srcRowBytes
;
1250 /* This is ugly but probably won't be used much */
1252 /* fill in dest border */
1253 /* lower-left border pixel */
1256 memcpy(dstPtr
, srcPtr
, bpt
);
1257 /* lower-right border pixel */
1258 memcpy(dstPtr
+ (dstWidth
- 1) * bpt
,
1259 srcPtr
+ (srcWidth
- 1) * bpt
, bpt
);
1260 /* upper-left border pixel */
1261 memcpy(dstPtr
+ dstWidth
* (dstHeight
- 1) * bpt
,
1262 srcPtr
+ srcWidth
* (srcHeight
- 1) * bpt
, bpt
);
1263 /* upper-right border pixel */
1264 memcpy(dstPtr
+ (dstWidth
* dstHeight
- 1) * bpt
,
1265 srcPtr
+ (srcWidth
* srcHeight
- 1) * bpt
, bpt
);
1267 do_row(datatype
, comps
, srcWidthNB
,
1270 dstWidthNB
, dstPtr
+ bpt
);
1272 do_row(datatype
, comps
, srcWidthNB
,
1273 srcPtr
+ (srcWidth
* (srcHeight
- 1) + 1) * bpt
,
1274 srcPtr
+ (srcWidth
* (srcHeight
- 1) + 1) * bpt
,
1276 dstPtr
+ (dstWidth
* (dstHeight
- 1) + 1) * bpt
);
1277 /* left and right borders */
1278 if (srcHeight
== dstHeight
) {
1279 /* copy border pixel from src to dst */
1280 for (row
= 1; row
< srcHeight
; row
++) {
1281 memcpy(dstPtr
+ dstWidth
* row
* bpt
,
1282 srcPtr
+ srcWidth
* row
* bpt
, bpt
);
1283 memcpy(dstPtr
+ (dstWidth
* row
+ dstWidth
- 1) * bpt
,
1284 srcPtr
+ (srcWidth
* row
+ srcWidth
- 1) * bpt
, bpt
);
1288 /* average two src pixels each dest pixel */
1289 for (row
= 0; row
< dstHeightNB
; row
+= 2) {
1290 do_row(datatype
, comps
, 1,
1291 srcPtr
+ (srcWidth
* (row
* 2 + 1)) * bpt
,
1292 srcPtr
+ (srcWidth
* (row
* 2 + 2)) * bpt
,
1293 1, dstPtr
+ (dstWidth
* row
+ 1) * bpt
);
1294 do_row(datatype
, comps
, 1,
1295 srcPtr
+ (srcWidth
* (row
* 2 + 1) + srcWidth
- 1) * bpt
,
1296 srcPtr
+ (srcWidth
* (row
* 2 + 2) + srcWidth
- 1) * bpt
,
1297 1, dstPtr
+ (dstWidth
* row
+ 1 + dstWidth
- 1) * bpt
);
1305 make_3d_mipmap(GLenum datatype
, GLuint comps
, GLint border
,
1306 GLint srcWidth
, GLint srcHeight
, GLint srcDepth
,
1307 const GLubyte
*srcPtr
, GLint srcRowStride
,
1308 GLint dstWidth
, GLint dstHeight
, GLint dstDepth
,
1309 GLubyte
*dstPtr
, GLint dstRowStride
)
1311 const GLint bpt
= bytes_per_pixel(datatype
, comps
);
1312 const GLint srcWidthNB
= srcWidth
- 2 * border
; /* sizes w/out border */
1313 const GLint srcDepthNB
= srcDepth
- 2 * border
;
1314 const GLint dstWidthNB
= dstWidth
- 2 * border
;
1315 const GLint dstHeightNB
= dstHeight
- 2 * border
;
1316 const GLint dstDepthNB
= dstDepth
- 2 * border
;
1318 GLint bytesPerSrcImage
, bytesPerDstImage
;
1319 GLint bytesPerSrcRow
, bytesPerDstRow
;
1320 GLint srcImageOffset
, srcRowOffset
;
1322 (void) srcDepthNB
; /* silence warnings */
1325 bytesPerSrcImage
= srcWidth
* srcHeight
* bpt
;
1326 bytesPerDstImage
= dstWidth
* dstHeight
* bpt
;
1328 bytesPerSrcRow
= srcWidth
* bpt
;
1329 bytesPerDstRow
= dstWidth
* bpt
;
1331 /* Offset between adjacent src images to be averaged together */
1332 srcImageOffset
= (srcDepth
== dstDepth
) ? 0 : bytesPerSrcImage
;
1334 /* Offset between adjacent src rows to be averaged together */
1335 srcRowOffset
= (srcHeight
== dstHeight
) ? 0 : srcWidth
* bpt
;
1338 * Need to average together up to 8 src pixels for each dest pixel.
1339 * Break that down into 3 operations:
1340 * 1. take two rows from source image and average them together.
1341 * 2. take two rows from next source image and average them together.
1342 * 3. take the two averaged rows and average them for the final dst row.
1346 printf("mip3d %d x %d x %d -> %d x %d x %d\n",
1347 srcWidth, srcHeight, srcDepth, dstWidth, dstHeight, dstDepth);
1350 for (img
= 0; img
< dstDepthNB
; img
++) {
1351 /* first source image pointer, skipping border */
1352 const GLubyte
*imgSrcA
= srcPtr
1353 + (bytesPerSrcImage
+ bytesPerSrcRow
+ border
) * bpt
* border
1354 + img
* (bytesPerSrcImage
+ srcImageOffset
);
1355 /* second source image pointer, skipping border */
1356 const GLubyte
*imgSrcB
= imgSrcA
+ srcImageOffset
;
1357 /* address of the dest image, skipping border */
1358 GLubyte
*imgDst
= dstPtr
1359 + (bytesPerDstImage
+ bytesPerDstRow
+ border
) * bpt
* border
1360 + img
* bytesPerDstImage
;
1362 /* setup the four source row pointers and the dest row pointer */
1363 const GLubyte
*srcImgARowA
= imgSrcA
;
1364 const GLubyte
*srcImgARowB
= imgSrcA
+ srcRowOffset
;
1365 const GLubyte
*srcImgBRowA
= imgSrcB
;
1366 const GLubyte
*srcImgBRowB
= imgSrcB
+ srcRowOffset
;
1367 GLubyte
*dstImgRow
= imgDst
;
1369 for (row
= 0; row
< dstHeightNB
; row
++) {
1370 do_row_3D(datatype
, comps
, srcWidthNB
,
1371 srcImgARowA
, srcImgARowB
,
1372 srcImgBRowA
, srcImgBRowB
,
1373 dstWidthNB
, dstImgRow
);
1375 /* advance to next rows */
1376 srcImgARowA
+= bytesPerSrcRow
+ srcRowOffset
;
1377 srcImgARowB
+= bytesPerSrcRow
+ srcRowOffset
;
1378 srcImgBRowA
+= bytesPerSrcRow
+ srcRowOffset
;
1379 srcImgBRowB
+= bytesPerSrcRow
+ srcRowOffset
;
1380 dstImgRow
+= bytesPerDstRow
;
1385 /* Luckily we can leverage the make_2d_mipmap() function here! */
1387 /* do front border image */
1388 make_2d_mipmap(datatype
, comps
, 1, srcWidth
, srcHeight
, srcPtr
, srcRowStride
,
1389 dstWidth
, dstHeight
, dstPtr
, dstRowStride
);
1390 /* do back border image */
1391 make_2d_mipmap(datatype
, comps
, 1, srcWidth
, srcHeight
,
1392 srcPtr
+ bytesPerSrcImage
* (srcDepth
- 1), srcRowStride
,
1393 dstWidth
, dstHeight
,
1394 dstPtr
+ bytesPerDstImage
* (dstDepth
- 1), dstRowStride
);
1395 /* do four remaining border edges that span the image slices */
1396 if (srcDepth
== dstDepth
) {
1397 /* just copy border pixels from src to dst */
1398 for (img
= 0; img
< dstDepthNB
; img
++) {
1402 /* do border along [img][row=0][col=0] */
1403 src
= srcPtr
+ (img
+ 1) * bytesPerSrcImage
;
1404 dst
= dstPtr
+ (img
+ 1) * bytesPerDstImage
;
1405 memcpy(dst
, src
, bpt
);
1407 /* do border along [img][row=dstHeight-1][col=0] */
1408 src
= srcPtr
+ (img
* 2 + 1) * bytesPerSrcImage
1409 + (srcHeight
- 1) * bytesPerSrcRow
;
1410 dst
= dstPtr
+ (img
+ 1) * bytesPerDstImage
1411 + (dstHeight
- 1) * bytesPerDstRow
;
1412 memcpy(dst
, src
, bpt
);
1414 /* do border along [img][row=0][col=dstWidth-1] */
1415 src
= srcPtr
+ (img
* 2 + 1) * bytesPerSrcImage
1416 + (srcWidth
- 1) * bpt
;
1417 dst
= dstPtr
+ (img
+ 1) * bytesPerDstImage
1418 + (dstWidth
- 1) * bpt
;
1419 memcpy(dst
, src
, bpt
);
1421 /* do border along [img][row=dstHeight-1][col=dstWidth-1] */
1422 src
= srcPtr
+ (img
* 2 + 1) * bytesPerSrcImage
1423 + (bytesPerSrcImage
- bpt
);
1424 dst
= dstPtr
+ (img
+ 1) * bytesPerDstImage
1425 + (bytesPerDstImage
- bpt
);
1426 memcpy(dst
, src
, bpt
);
1430 /* average border pixels from adjacent src image pairs */
1431 ASSERT(srcDepthNB
== 2 * dstDepthNB
);
1432 for (img
= 0; img
< dstDepthNB
; img
++) {
1436 /* do border along [img][row=0][col=0] */
1437 src
= srcPtr
+ (img
* 2 + 1) * bytesPerSrcImage
;
1438 dst
= dstPtr
+ (img
+ 1) * bytesPerDstImage
;
1439 do_row(datatype
, comps
, 1, src
, src
+ srcImageOffset
, 1, dst
);
1441 /* do border along [img][row=dstHeight-1][col=0] */
1442 src
= srcPtr
+ (img
* 2 + 1) * bytesPerSrcImage
1443 + (srcHeight
- 1) * bytesPerSrcRow
;
1444 dst
= dstPtr
+ (img
+ 1) * bytesPerDstImage
1445 + (dstHeight
- 1) * bytesPerDstRow
;
1446 do_row(datatype
, comps
, 1, src
, src
+ srcImageOffset
, 1, dst
);
1448 /* do border along [img][row=0][col=dstWidth-1] */
1449 src
= srcPtr
+ (img
* 2 + 1) * bytesPerSrcImage
1450 + (srcWidth
- 1) * bpt
;
1451 dst
= dstPtr
+ (img
+ 1) * bytesPerDstImage
1452 + (dstWidth
- 1) * bpt
;
1453 do_row(datatype
, comps
, 1, src
, src
+ srcImageOffset
, 1, dst
);
1455 /* do border along [img][row=dstHeight-1][col=dstWidth-1] */
1456 src
= srcPtr
+ (img
* 2 + 1) * bytesPerSrcImage
1457 + (bytesPerSrcImage
- bpt
);
1458 dst
= dstPtr
+ (img
+ 1) * bytesPerDstImage
1459 + (bytesPerDstImage
- bpt
);
1460 do_row(datatype
, comps
, 1, src
, src
+ srcImageOffset
, 1, dst
);
1468 make_1d_stack_mipmap(GLenum datatype
, GLuint comps
, GLint border
,
1469 GLint srcWidth
, const GLubyte
*srcPtr
, GLuint srcRowStride
,
1470 GLint dstWidth
, GLint dstHeight
,
1471 GLubyte
*dstPtr
, GLuint dstRowStride
)
1473 const GLint bpt
= bytes_per_pixel(datatype
, comps
);
1474 const GLint srcWidthNB
= srcWidth
- 2 * border
; /* sizes w/out border */
1475 const GLint dstWidthNB
= dstWidth
- 2 * border
;
1476 const GLint dstHeightNB
= dstHeight
- 2 * border
;
1477 const GLint srcRowBytes
= bpt
* srcRowStride
;
1478 const GLint dstRowBytes
= bpt
* dstRowStride
;
1483 /* Compute src and dst pointers, skipping any border */
1484 src
= srcPtr
+ border
* ((srcWidth
+ 1) * bpt
);
1485 dst
= dstPtr
+ border
* ((dstWidth
+ 1) * bpt
);
1487 for (row
= 0; row
< dstHeightNB
; row
++) {
1488 do_row(datatype
, comps
, srcWidthNB
, src
, src
,
1495 /* copy left-most pixel from source */
1498 memcpy(dstPtr
, srcPtr
, bpt
);
1499 /* copy right-most pixel from source */
1500 memcpy(dstPtr
+ (dstWidth
- 1) * bpt
,
1501 srcPtr
+ (srcWidth
- 1) * bpt
,
1509 * There is quite a bit of refactoring that could be done with this function
1510 * and \c make_2d_mipmap.
1513 make_2d_stack_mipmap(GLenum datatype
, GLuint comps
, GLint border
,
1514 GLint srcWidth
, GLint srcHeight
,
1515 const GLubyte
*srcPtr
, GLint srcRowStride
,
1516 GLint dstWidth
, GLint dstHeight
, GLint dstDepth
,
1517 GLubyte
*dstPtr
, GLint dstRowStride
)
1519 const GLint bpt
= bytes_per_pixel(datatype
, comps
);
1520 const GLint srcWidthNB
= srcWidth
- 2 * border
; /* sizes w/out border */
1521 const GLint dstWidthNB
= dstWidth
- 2 * border
;
1522 const GLint dstHeightNB
= dstHeight
- 2 * border
;
1523 const GLint dstDepthNB
= dstDepth
- 2 * border
;
1524 const GLint srcRowBytes
= bpt
* srcRowStride
;
1525 const GLint dstRowBytes
= bpt
* dstRowStride
;
1526 const GLubyte
*srcA
, *srcB
;
1531 /* Compute src and dst pointers, skipping any border */
1532 srcA
= srcPtr
+ border
* ((srcWidth
+ 1) * bpt
);
1534 srcB
= srcA
+ srcRowBytes
;
1537 dst
= dstPtr
+ border
* ((dstWidth
+ 1) * bpt
);
1539 for (layer
= 0; layer
< dstDepthNB
; layer
++) {
1540 for (row
= 0; row
< dstHeightNB
; row
++) {
1541 do_row(datatype
, comps
, srcWidthNB
, srcA
, srcB
,
1543 srcA
+= 2 * srcRowBytes
;
1544 srcB
+= 2 * srcRowBytes
;
1548 /* This is ugly but probably won't be used much */
1550 /* fill in dest border */
1551 /* lower-left border pixel */
1554 memcpy(dstPtr
, srcPtr
, bpt
);
1555 /* lower-right border pixel */
1556 memcpy(dstPtr
+ (dstWidth
- 1) * bpt
,
1557 srcPtr
+ (srcWidth
- 1) * bpt
, bpt
);
1558 /* upper-left border pixel */
1559 memcpy(dstPtr
+ dstWidth
* (dstHeight
- 1) * bpt
,
1560 srcPtr
+ srcWidth
* (srcHeight
- 1) * bpt
, bpt
);
1561 /* upper-right border pixel */
1562 memcpy(dstPtr
+ (dstWidth
* dstHeight
- 1) * bpt
,
1563 srcPtr
+ (srcWidth
* srcHeight
- 1) * bpt
, bpt
);
1565 do_row(datatype
, comps
, srcWidthNB
,
1568 dstWidthNB
, dstPtr
+ bpt
);
1570 do_row(datatype
, comps
, srcWidthNB
,
1571 srcPtr
+ (srcWidth
* (srcHeight
- 1) + 1) * bpt
,
1572 srcPtr
+ (srcWidth
* (srcHeight
- 1) + 1) * bpt
,
1574 dstPtr
+ (dstWidth
* (dstHeight
- 1) + 1) * bpt
);
1575 /* left and right borders */
1576 if (srcHeight
== dstHeight
) {
1577 /* copy border pixel from src to dst */
1578 for (row
= 1; row
< srcHeight
; row
++) {
1579 memcpy(dstPtr
+ dstWidth
* row
* bpt
,
1580 srcPtr
+ srcWidth
* row
* bpt
, bpt
);
1581 memcpy(dstPtr
+ (dstWidth
* row
+ dstWidth
- 1) * bpt
,
1582 srcPtr
+ (srcWidth
* row
+ srcWidth
- 1) * bpt
, bpt
);
1586 /* average two src pixels each dest pixel */
1587 for (row
= 0; row
< dstHeightNB
; row
+= 2) {
1588 do_row(datatype
, comps
, 1,
1589 srcPtr
+ (srcWidth
* (row
* 2 + 1)) * bpt
,
1590 srcPtr
+ (srcWidth
* (row
* 2 + 2)) * bpt
,
1591 1, dstPtr
+ (dstWidth
* row
+ 1) * bpt
);
1592 do_row(datatype
, comps
, 1,
1593 srcPtr
+ (srcWidth
* (row
* 2 + 1) + srcWidth
- 1) * bpt
,
1594 srcPtr
+ (srcWidth
* (row
* 2 + 2) + srcWidth
- 1) * bpt
,
1595 1, dstPtr
+ (dstWidth
* row
+ 1 + dstWidth
- 1) * bpt
);
1604 * Down-sample a texture image to produce the next lower mipmap level.
1605 * \param comps components per texel (1, 2, 3 or 4)
1606 * \param srcRowStride stride between source rows, in texels
1607 * \param dstRowStride stride between destination rows, in texels
1610 _mesa_generate_mipmap_level(GLenum target
,
1611 GLenum datatype
, GLuint comps
,
1613 GLint srcWidth
, GLint srcHeight
, GLint srcDepth
,
1614 const GLubyte
*srcData
,
1616 GLint dstWidth
, GLint dstHeight
, GLint dstDepth
,
1621 * We use simple 2x2 averaging to compute the next mipmap level.
1625 make_1d_mipmap(datatype
, comps
, border
,
1630 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
1631 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
1632 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
1633 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
1634 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
1635 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
1636 make_2d_mipmap(datatype
, comps
, border
,
1637 srcWidth
, srcHeight
, srcData
, srcRowStride
,
1638 dstWidth
, dstHeight
, dstData
, dstRowStride
);
1641 make_3d_mipmap(datatype
, comps
, border
,
1642 srcWidth
, srcHeight
, srcDepth
,
1643 srcData
, srcRowStride
,
1644 dstWidth
, dstHeight
, dstDepth
,
1645 dstData
, dstRowStride
);
1647 case GL_TEXTURE_1D_ARRAY_EXT
:
1648 make_1d_stack_mipmap(datatype
, comps
, border
,
1649 srcWidth
, srcData
, srcRowStride
,
1650 dstWidth
, dstHeight
,
1651 dstData
, dstRowStride
);
1653 case GL_TEXTURE_2D_ARRAY_EXT
:
1654 make_2d_stack_mipmap(datatype
, comps
, border
,
1655 srcWidth
, srcHeight
,
1656 srcData
, srcRowStride
,
1657 dstWidth
, dstHeight
,
1658 dstDepth
, dstData
, dstRowStride
);
1660 case GL_TEXTURE_RECTANGLE_NV
:
1661 /* no mipmaps, do nothing */
1664 _mesa_problem(NULL
, "bad dimensions in _mesa_generate_mipmaps");
1671 * compute next (level+1) image size
1672 * \return GL_FALSE if no smaller size can be generated (eg. src is 1x1x1 size)
1675 next_mipmap_level_size(GLenum target
, GLint border
,
1676 GLint srcWidth
, GLint srcHeight
, GLint srcDepth
,
1677 GLint
*dstWidth
, GLint
*dstHeight
, GLint
*dstDepth
)
1679 if (srcWidth
- 2 * border
> 1) {
1680 *dstWidth
= (srcWidth
- 2 * border
) / 2 + 2 * border
;
1683 *dstWidth
= srcWidth
; /* can't go smaller */
1686 if ((srcHeight
- 2 * border
> 1) &&
1687 (target
!= GL_TEXTURE_1D_ARRAY_EXT
)) {
1688 *dstHeight
= (srcHeight
- 2 * border
) / 2 + 2 * border
;
1691 *dstHeight
= srcHeight
; /* can't go smaller */
1694 if ((srcDepth
- 2 * border
> 1) &&
1695 (target
!= GL_TEXTURE_2D_ARRAY_EXT
)) {
1696 *dstDepth
= (srcDepth
- 2 * border
) / 2 + 2 * border
;
1699 *dstDepth
= srcDepth
; /* can't go smaller */
1702 if (*dstWidth
== srcWidth
&&
1703 *dstHeight
== srcHeight
&&
1704 *dstDepth
== srcDepth
) {
1716 * Automatic mipmap generation.
1717 * This is the fallback/default function for ctx->Driver.GenerateMipmap().
1718 * Generate a complete set of mipmaps from texObj's BaseLevel image.
1719 * Stop at texObj's MaxLevel or when we get to the 1x1 texture.
1720 * For cube maps, target will be one of
1721 * GL_TEXTURE_CUBE_MAP_POSITIVE/NEGATIVE_X/Y/Z; never GL_TEXTURE_CUBE_MAP.
1724 _mesa_generate_mipmap(struct gl_context
*ctx
, GLenum target
,
1725 struct gl_texture_object
*texObj
)
1727 const struct gl_texture_image
*srcImage
;
1728 gl_format convertFormat
;
1729 const GLubyte
*srcData
= NULL
;
1730 GLubyte
*dstData
= NULL
;
1731 GLint level
, maxLevels
;
1736 srcImage
= _mesa_select_tex_image(ctx
, texObj
, target
, texObj
->BaseLevel
);
1739 maxLevels
= _mesa_max_texture_levels(ctx
, texObj
->Target
);
1740 ASSERT(maxLevels
> 0); /* bad target */
1742 /* Find convertFormat - the format that do_row() will process */
1744 if (_mesa_is_format_compressed(srcImage
->TexFormat
)) {
1745 /* setup for compressed textures - need to allocate temporary
1746 * image buffers to hold uncompressed images.
1749 GLint components
, size
;
1752 assert(texObj
->Target
== GL_TEXTURE_2D
||
1753 texObj
->Target
== GL_TEXTURE_CUBE_MAP_ARB
);
1755 if (srcImage
->_BaseFormat
== GL_RGB
) {
1756 convertFormat
= MESA_FORMAT_RGB888
;
1759 else if (srcImage
->_BaseFormat
== GL_RGBA
) {
1760 convertFormat
= MESA_FORMAT_RGBA8888
;
1764 _mesa_problem(ctx
, "bad srcImage->_BaseFormat in _mesa_generate_mipmaps");
1768 /* allocate storage for uncompressed GL_RGB or GL_RGBA images */
1769 size
= _mesa_bytes_per_pixel(srcImage
->_BaseFormat
, CHAN_TYPE
)
1770 * srcImage
->Width
* srcImage
->Height
* srcImage
->Depth
+ 20;
1771 /* 20 extra bytes, just be safe when calling last FetchTexel */
1772 srcData
= (GLubyte
*) malloc(size
);
1774 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "generate mipmaps");
1777 dstData
= (GLubyte
*) malloc(size
/ 2); /* 1/4 would probably be OK */
1779 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "generate mipmaps");
1780 free((void *) srcData
);
1784 /* decompress base image here */
1785 dst
= (GLchan
*) srcData
;
1786 for (row
= 0; row
< srcImage
->Height
; row
++) {
1788 for (col
= 0; col
< srcImage
->Width
; col
++) {
1789 srcImage
->FetchTexelc(srcImage
, col
, row
, 0, dst
);
1796 convertFormat
= srcImage
->TexFormat
;
1799 _mesa_format_to_type_and_comps(convertFormat
, &datatype
, &comps
);
1801 for (level
= texObj
->BaseLevel
; level
< texObj
->MaxLevel
1802 && level
< maxLevels
- 1; level
++) {
1803 /* generate image[level+1] from image[level] */
1804 const struct gl_texture_image
*srcImage
;
1805 struct gl_texture_image
*dstImage
;
1806 GLint srcWidth
, srcHeight
, srcDepth
;
1807 GLint dstWidth
, dstHeight
, dstDepth
;
1809 GLboolean nextLevel
;
1811 /* get src image parameters */
1812 srcImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
1814 srcWidth
= srcImage
->Width
;
1815 srcHeight
= srcImage
->Height
;
1816 srcDepth
= srcImage
->Depth
;
1817 border
= srcImage
->Border
;
1819 nextLevel
= next_mipmap_level_size(target
, border
,
1820 srcWidth
, srcHeight
, srcDepth
,
1821 &dstWidth
, &dstHeight
, &dstDepth
);
1824 if (_mesa_is_format_compressed(srcImage
->TexFormat
)) {
1825 free((void *) srcData
);
1831 /* get dest gl_texture_image */
1832 dstImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
+ 1);
1834 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "generating mipmaps");
1838 /* Free old image data */
1840 ctx
->Driver
.FreeTexImageData(ctx
, dstImage
);
1842 /* initialize new image */
1843 _mesa_init_teximage_fields(ctx
, target
, dstImage
, dstWidth
, dstHeight
,
1844 dstDepth
, border
, srcImage
->InternalFormat
,
1845 srcImage
->TexFormat
);
1846 dstImage
->DriverData
= NULL
;
1847 dstImage
->FetchTexelc
= srcImage
->FetchTexelc
;
1848 dstImage
->FetchTexelf
= srcImage
->FetchTexelf
;
1850 /* Alloc new teximage data buffer */
1852 GLuint size
= _mesa_format_image_size(dstImage
->TexFormat
,
1853 dstWidth
, dstHeight
, dstDepth
);
1854 dstImage
->Data
= _mesa_alloc_texmemory(size
);
1855 if (!dstImage
->Data
) {
1856 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "generating mipmaps");
1861 /* Setup src and dest data pointers */
1862 if (_mesa_is_format_compressed(dstImage
->TexFormat
)) {
1863 /* srcData and dstData are already set */
1868 srcData
= (const GLubyte
*) srcImage
->Data
;
1869 dstData
= (GLubyte
*) dstImage
->Data
;
1872 ASSERT(dstImage
->TexFormat
);
1873 ASSERT(dstImage
->FetchTexelc
);
1874 ASSERT(dstImage
->FetchTexelf
);
1876 _mesa_generate_mipmap_level(target
, datatype
, comps
, border
,
1877 srcWidth
, srcHeight
, srcDepth
,
1878 srcData
, srcImage
->RowStride
,
1879 dstWidth
, dstHeight
, dstDepth
,
1880 dstData
, dstImage
->RowStride
);
1883 if (_mesa_is_format_compressed(dstImage
->TexFormat
)) {
1885 /* compress image from dstData into dstImage->Data */
1886 const GLenum srcFormat
= _mesa_get_format_base_format(convertFormat
);
1888 = _mesa_format_row_stride(dstImage
->TexFormat
, dstWidth
);
1889 ASSERT(srcFormat
== GL_RGB
|| srcFormat
== GL_RGBA
);
1891 _mesa_texstore(ctx
, 2, dstImage
->_BaseFormat
,
1892 dstImage
->TexFormat
,
1894 0, 0, 0, /* dstX/Y/Zoffset */
1895 dstRowStride
, 0, /* strides */
1896 dstWidth
, dstHeight
, 1, /* size */
1897 srcFormat
, CHAN_TYPE
,
1898 dstData
, /* src data, actually */
1899 &ctx
->DefaultPacking
);
1901 /* swap src and dest pointers */
1902 temp
= (GLubyte
*) srcData
;
1907 } /* loop over mipmap levels */
1912 * Helper function for drivers which need to rescale texture images to
1913 * certain aspect ratios.
1914 * Nearest filtering only (for broken hardware that can't support
1915 * all aspect ratios). This can be made a lot faster, but I don't
1916 * really care enough...
1919 _mesa_rescale_teximage2d(GLuint bytesPerPixel
,
1920 GLuint srcStrideInPixels
,
1921 GLuint dstRowStride
,
1922 GLint srcWidth
, GLint srcHeight
,
1923 GLint dstWidth
, GLint dstHeight
,
1924 const GLvoid
*srcImage
, GLvoid
*dstImage
)
1928 #define INNER_LOOP( TYPE, HOP, WOP ) \
1929 for ( row = 0 ; row < dstHeight ; row++ ) { \
1930 GLint srcRow = row HOP hScale; \
1931 for ( col = 0 ; col < dstWidth ; col++ ) { \
1932 GLint srcCol = col WOP wScale; \
1933 dst[col] = src[srcRow * srcStrideInPixels + srcCol]; \
1935 dst = (TYPE *) ((GLubyte *) dst + dstRowStride); \
1938 #define RESCALE_IMAGE( TYPE ) \
1940 const TYPE *src = (const TYPE *)srcImage; \
1941 TYPE *dst = (TYPE *)dstImage; \
1943 if ( srcHeight < dstHeight ) { \
1944 const GLint hScale = dstHeight / srcHeight; \
1945 if ( srcWidth < dstWidth ) { \
1946 const GLint wScale = dstWidth / srcWidth; \
1947 INNER_LOOP( TYPE, /, / ); \
1950 const GLint wScale = srcWidth / dstWidth; \
1951 INNER_LOOP( TYPE, /, * ); \
1955 const GLint hScale = srcHeight / dstHeight; \
1956 if ( srcWidth < dstWidth ) { \
1957 const GLint wScale = dstWidth / srcWidth; \
1958 INNER_LOOP( TYPE, *, / ); \
1961 const GLint wScale = srcWidth / dstWidth; \
1962 INNER_LOOP( TYPE, *, * ); \
1967 switch ( bytesPerPixel
) {
1969 RESCALE_IMAGE( GLuint
);
1973 RESCALE_IMAGE( GLushort
);
1977 RESCALE_IMAGE( GLubyte
);
1980 _mesa_problem(NULL
,"unexpected bytes/pixel in _mesa_rescale_teximage2d");
1986 * Upscale an image by replication, not (typical) stretching.
1987 * We use this when the image width or height is less than a
1988 * certain size (4, 8) and we need to upscale an image.
1991 _mesa_upscale_teximage2d(GLsizei inWidth
, GLsizei inHeight
,
1992 GLsizei outWidth
, GLsizei outHeight
,
1993 GLint comps
, const GLchan
*src
, GLint srcRowStride
,
1998 ASSERT(outWidth
>= inWidth
);
1999 ASSERT(outHeight
>= inHeight
);
2001 ASSERT(inWidth
== 1 || inWidth
== 2 || inHeight
== 1 || inHeight
== 2);
2002 ASSERT((outWidth
& 3) == 0);
2003 ASSERT((outHeight
& 3) == 0);
2006 for (i
= 0; i
< outHeight
; i
++) {
2007 const GLint ii
= i
% inHeight
;
2008 for (j
= 0; j
< outWidth
; j
++) {
2009 const GLint jj
= j
% inWidth
;
2010 for (k
= 0; k
< comps
; k
++) {
2011 dest
[(i
* outWidth
+ j
) * comps
+ k
]
2012 = src
[ii
* srcRowStride
+ jj
* comps
+ k
];