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 _mesa_problem(NULL
, "bad format in do_row()");
622 * Average together four rows of a source image to produce a single new
623 * row in the dest image. It's legal for the two source rows to point
624 * to the same data. The source width must be equal to either the
625 * dest width or two times the dest width.
627 * \param datatype GL pixel type \c GL_UNSIGNED_BYTE, \c GL_UNSIGNED_SHORT,
629 * \param comps number of components per pixel (1..4)
630 * \param srcWidth Width of a row in the source data
631 * \param srcRowA Pointer to one of the rows of source data
632 * \param srcRowB Pointer to one of the rows of source data
633 * \param srcRowC Pointer to one of the rows of source data
634 * \param srcRowD Pointer to one of the rows of source data
635 * \param dstWidth Width of a row in the destination data
636 * \param srcRowA Pointer to the row of destination data
639 do_row_3D(GLenum datatype
, GLuint comps
, GLint srcWidth
,
640 const GLvoid
*srcRowA
, const GLvoid
*srcRowB
,
641 const GLvoid
*srcRowC
, const GLvoid
*srcRowD
,
642 GLint dstWidth
, GLvoid
*dstRow
)
644 const GLuint k0
= (srcWidth
== dstWidth
) ? 0 : 1;
645 const GLuint colStride
= (srcWidth
== dstWidth
) ? 1 : 2;
651 if ((datatype
== GL_UNSIGNED_BYTE
) && (comps
== 4)) {
652 DECLARE_ROW_POINTERS(GLubyte
, 4);
654 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
655 i
++, j
+= colStride
, k
+= colStride
) {
662 else if ((datatype
== GL_UNSIGNED_BYTE
) && (comps
== 3)) {
663 DECLARE_ROW_POINTERS(GLubyte
, 3);
665 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
666 i
++, j
+= colStride
, k
+= colStride
) {
672 else if ((datatype
== GL_UNSIGNED_BYTE
) && (comps
== 2)) {
673 DECLARE_ROW_POINTERS(GLubyte
, 2);
675 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
676 i
++, j
+= colStride
, k
+= colStride
) {
681 else if ((datatype
== GL_UNSIGNED_BYTE
) && (comps
== 1)) {
682 DECLARE_ROW_POINTERS(GLubyte
, 1);
684 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
685 i
++, j
+= colStride
, k
+= colStride
) {
689 else if ((datatype
== GL_BYTE
) && (comps
== 4)) {
690 DECLARE_ROW_POINTERS(GLbyte
, 4);
692 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
693 i
++, j
+= colStride
, k
+= colStride
) {
700 else if ((datatype
== GL_BYTE
) && (comps
== 3)) {
701 DECLARE_ROW_POINTERS(GLbyte
, 3);
703 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
704 i
++, j
+= colStride
, k
+= colStride
) {
710 else if ((datatype
== GL_BYTE
) && (comps
== 2)) {
711 DECLARE_ROW_POINTERS(GLbyte
, 2);
713 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
714 i
++, j
+= colStride
, k
+= colStride
) {
719 else if ((datatype
== GL_BYTE
) && (comps
== 1)) {
720 DECLARE_ROW_POINTERS(GLbyte
, 1);
722 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
723 i
++, j
+= colStride
, k
+= colStride
) {
727 else if ((datatype
== GL_UNSIGNED_SHORT
) && (comps
== 4)) {
728 DECLARE_ROW_POINTERS(GLushort
, 4);
730 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
731 i
++, j
+= colStride
, k
+= colStride
) {
738 else if ((datatype
== GL_UNSIGNED_SHORT
) && (comps
== 3)) {
739 DECLARE_ROW_POINTERS(GLushort
, 3);
741 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
742 i
++, j
+= colStride
, k
+= colStride
) {
748 else if ((datatype
== GL_UNSIGNED_SHORT
) && (comps
== 2)) {
749 DECLARE_ROW_POINTERS(GLushort
, 2);
751 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
752 i
++, j
+= colStride
, k
+= colStride
) {
757 else if ((datatype
== GL_UNSIGNED_SHORT
) && (comps
== 1)) {
758 DECLARE_ROW_POINTERS(GLushort
, 1);
760 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
761 i
++, j
+= colStride
, k
+= colStride
) {
765 else if ((datatype
== GL_SHORT
) && (comps
== 4)) {
766 DECLARE_ROW_POINTERS(GLshort
, 4);
768 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
769 i
++, j
+= colStride
, k
+= colStride
) {
776 else if ((datatype
== GL_SHORT
) && (comps
== 3)) {
777 DECLARE_ROW_POINTERS(GLshort
, 3);
779 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
780 i
++, j
+= colStride
, k
+= colStride
) {
786 else if ((datatype
== GL_SHORT
) && (comps
== 2)) {
787 DECLARE_ROW_POINTERS(GLshort
, 2);
789 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
790 i
++, j
+= colStride
, k
+= colStride
) {
795 else if ((datatype
== GL_SHORT
) && (comps
== 1)) {
796 DECLARE_ROW_POINTERS(GLshort
, 1);
798 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
799 i
++, j
+= colStride
, k
+= colStride
) {
803 else if ((datatype
== GL_FLOAT
) && (comps
== 4)) {
804 DECLARE_ROW_POINTERS(GLfloat
, 4);
806 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
807 i
++, j
+= colStride
, k
+= colStride
) {
814 else if ((datatype
== GL_FLOAT
) && (comps
== 3)) {
815 DECLARE_ROW_POINTERS(GLfloat
, 3);
817 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
818 i
++, j
+= colStride
, k
+= colStride
) {
824 else if ((datatype
== GL_FLOAT
) && (comps
== 2)) {
825 DECLARE_ROW_POINTERS(GLfloat
, 2);
827 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
828 i
++, j
+= colStride
, k
+= colStride
) {
833 else if ((datatype
== GL_FLOAT
) && (comps
== 1)) {
834 DECLARE_ROW_POINTERS(GLfloat
, 1);
836 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
837 i
++, j
+= colStride
, k
+= colStride
) {
841 else if ((datatype
== GL_HALF_FLOAT_ARB
) && (comps
== 4)) {
842 DECLARE_ROW_POINTERS(GLhalfARB
, 4);
844 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
845 i
++, j
+= colStride
, k
+= colStride
) {
852 else if ((datatype
== GL_HALF_FLOAT_ARB
) && (comps
== 3)) {
853 DECLARE_ROW_POINTERS(GLhalfARB
, 4);
855 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
856 i
++, j
+= colStride
, k
+= colStride
) {
862 else if ((datatype
== GL_HALF_FLOAT_ARB
) && (comps
== 2)) {
863 DECLARE_ROW_POINTERS(GLhalfARB
, 4);
865 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
866 i
++, j
+= colStride
, k
+= colStride
) {
871 else if ((datatype
== GL_HALF_FLOAT_ARB
) && (comps
== 1)) {
872 DECLARE_ROW_POINTERS(GLhalfARB
, 4);
874 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
875 i
++, j
+= colStride
, k
+= colStride
) {
879 else if ((datatype
== GL_UNSIGNED_INT
) && (comps
== 1)) {
880 const GLuint
*rowA
= (const GLuint
*) srcRowA
;
881 const GLuint
*rowB
= (const GLuint
*) srcRowB
;
882 const GLuint
*rowC
= (const GLuint
*) srcRowC
;
883 const GLuint
*rowD
= (const GLuint
*) srcRowD
;
884 GLfloat
*dst
= (GLfloat
*) dstRow
;
886 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
887 i
++, j
+= colStride
, k
+= colStride
) {
888 const uint64_t tmp
= (((uint64_t) rowA
[j
] + (uint64_t) rowA
[k
])
889 + ((uint64_t) rowB
[j
] + (uint64_t) rowB
[k
])
890 + ((uint64_t) rowC
[j
] + (uint64_t) rowC
[k
])
891 + ((uint64_t) rowD
[j
] + (uint64_t) rowD
[k
]));
892 dst
[i
] = (GLfloat
)((double) tmp
* 0.125);
895 else if ((datatype
== GL_UNSIGNED_SHORT_5_6_5
) && (comps
== 3)) {
896 DECLARE_ROW_POINTERS0(GLushort
);
898 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
899 i
++, j
+= colStride
, k
+= colStride
) {
900 const GLint rowAr0
= rowA
[j
] & 0x1f;
901 const GLint rowAr1
= rowA
[k
] & 0x1f;
902 const GLint rowBr0
= rowB
[j
] & 0x1f;
903 const GLint rowBr1
= rowB
[k
] & 0x1f;
904 const GLint rowCr0
= rowC
[j
] & 0x1f;
905 const GLint rowCr1
= rowC
[k
] & 0x1f;
906 const GLint rowDr0
= rowD
[j
] & 0x1f;
907 const GLint rowDr1
= rowD
[k
] & 0x1f;
908 const GLint rowAg0
= (rowA
[j
] >> 5) & 0x3f;
909 const GLint rowAg1
= (rowA
[k
] >> 5) & 0x3f;
910 const GLint rowBg0
= (rowB
[j
] >> 5) & 0x3f;
911 const GLint rowBg1
= (rowB
[k
] >> 5) & 0x3f;
912 const GLint rowCg0
= (rowC
[j
] >> 5) & 0x3f;
913 const GLint rowCg1
= (rowC
[k
] >> 5) & 0x3f;
914 const GLint rowDg0
= (rowD
[j
] >> 5) & 0x3f;
915 const GLint rowDg1
= (rowD
[k
] >> 5) & 0x3f;
916 const GLint rowAb0
= (rowA
[j
] >> 11) & 0x1f;
917 const GLint rowAb1
= (rowA
[k
] >> 11) & 0x1f;
918 const GLint rowBb0
= (rowB
[j
] >> 11) & 0x1f;
919 const GLint rowBb1
= (rowB
[k
] >> 11) & 0x1f;
920 const GLint rowCb0
= (rowC
[j
] >> 11) & 0x1f;
921 const GLint rowCb1
= (rowC
[k
] >> 11) & 0x1f;
922 const GLint rowDb0
= (rowD
[j
] >> 11) & 0x1f;
923 const GLint rowDb1
= (rowD
[k
] >> 11) & 0x1f;
924 const GLint r
= FILTER_SUM_3D(rowAr0
, rowAr1
, rowBr0
, rowBr1
,
925 rowCr0
, rowCr1
, rowDr0
, rowDr1
);
926 const GLint g
= FILTER_SUM_3D(rowAg0
, rowAg1
, rowBg0
, rowBg1
,
927 rowCg0
, rowCg1
, rowDg0
, rowDg1
);
928 const GLint b
= FILTER_SUM_3D(rowAb0
, rowAb1
, rowBb0
, rowBb1
,
929 rowCb0
, rowCb1
, rowDb0
, rowDb1
);
930 dst
[i
] = (b
<< 11) | (g
<< 5) | r
;
933 else if ((datatype
== GL_UNSIGNED_SHORT_4_4_4_4
) && (comps
== 4)) {
934 DECLARE_ROW_POINTERS0(GLushort
);
936 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
937 i
++, j
+= colStride
, k
+= colStride
) {
938 const GLint rowAr0
= rowA
[j
] & 0xf;
939 const GLint rowAr1
= rowA
[k
] & 0xf;
940 const GLint rowBr0
= rowB
[j
] & 0xf;
941 const GLint rowBr1
= rowB
[k
] & 0xf;
942 const GLint rowCr0
= rowC
[j
] & 0xf;
943 const GLint rowCr1
= rowC
[k
] & 0xf;
944 const GLint rowDr0
= rowD
[j
] & 0xf;
945 const GLint rowDr1
= rowD
[k
] & 0xf;
946 const GLint rowAg0
= (rowA
[j
] >> 4) & 0xf;
947 const GLint rowAg1
= (rowA
[k
] >> 4) & 0xf;
948 const GLint rowBg0
= (rowB
[j
] >> 4) & 0xf;
949 const GLint rowBg1
= (rowB
[k
] >> 4) & 0xf;
950 const GLint rowCg0
= (rowC
[j
] >> 4) & 0xf;
951 const GLint rowCg1
= (rowC
[k
] >> 4) & 0xf;
952 const GLint rowDg0
= (rowD
[j
] >> 4) & 0xf;
953 const GLint rowDg1
= (rowD
[k
] >> 4) & 0xf;
954 const GLint rowAb0
= (rowA
[j
] >> 8) & 0xf;
955 const GLint rowAb1
= (rowA
[k
] >> 8) & 0xf;
956 const GLint rowBb0
= (rowB
[j
] >> 8) & 0xf;
957 const GLint rowBb1
= (rowB
[k
] >> 8) & 0xf;
958 const GLint rowCb0
= (rowC
[j
] >> 8) & 0xf;
959 const GLint rowCb1
= (rowC
[k
] >> 8) & 0xf;
960 const GLint rowDb0
= (rowD
[j
] >> 8) & 0xf;
961 const GLint rowDb1
= (rowD
[k
] >> 8) & 0xf;
962 const GLint rowAa0
= (rowA
[j
] >> 12) & 0xf;
963 const GLint rowAa1
= (rowA
[k
] >> 12) & 0xf;
964 const GLint rowBa0
= (rowB
[j
] >> 12) & 0xf;
965 const GLint rowBa1
= (rowB
[k
] >> 12) & 0xf;
966 const GLint rowCa0
= (rowC
[j
] >> 12) & 0xf;
967 const GLint rowCa1
= (rowC
[k
] >> 12) & 0xf;
968 const GLint rowDa0
= (rowD
[j
] >> 12) & 0xf;
969 const GLint rowDa1
= (rowD
[k
] >> 12) & 0xf;
970 const GLint r
= FILTER_SUM_3D(rowAr0
, rowAr1
, rowBr0
, rowBr1
,
971 rowCr0
, rowCr1
, rowDr0
, rowDr1
);
972 const GLint g
= FILTER_SUM_3D(rowAg0
, rowAg1
, rowBg0
, rowBg1
,
973 rowCg0
, rowCg1
, rowDg0
, rowDg1
);
974 const GLint b
= FILTER_SUM_3D(rowAb0
, rowAb1
, rowBb0
, rowBb1
,
975 rowCb0
, rowCb1
, rowDb0
, rowDb1
);
976 const GLint a
= FILTER_SUM_3D(rowAa0
, rowAa1
, rowBa0
, rowBa1
,
977 rowCa0
, rowCa1
, rowDa0
, rowDa1
);
979 dst
[i
] = (a
<< 12) | (b
<< 8) | (g
<< 4) | r
;
982 else if ((datatype
== GL_UNSIGNED_SHORT_1_5_5_5_REV
) && (comps
== 4)) {
983 DECLARE_ROW_POINTERS0(GLushort
);
985 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
986 i
++, j
+= colStride
, k
+= colStride
) {
987 const GLint rowAr0
= rowA
[j
] & 0x1f;
988 const GLint rowAr1
= rowA
[k
] & 0x1f;
989 const GLint rowBr0
= rowB
[j
] & 0x1f;
990 const GLint rowBr1
= rowB
[k
] & 0x1f;
991 const GLint rowCr0
= rowC
[j
] & 0x1f;
992 const GLint rowCr1
= rowC
[k
] & 0x1f;
993 const GLint rowDr0
= rowD
[j
] & 0x1f;
994 const GLint rowDr1
= rowD
[k
] & 0x1f;
995 const GLint rowAg0
= (rowA
[j
] >> 5) & 0x1f;
996 const GLint rowAg1
= (rowA
[k
] >> 5) & 0x1f;
997 const GLint rowBg0
= (rowB
[j
] >> 5) & 0x1f;
998 const GLint rowBg1
= (rowB
[k
] >> 5) & 0x1f;
999 const GLint rowCg0
= (rowC
[j
] >> 5) & 0x1f;
1000 const GLint rowCg1
= (rowC
[k
] >> 5) & 0x1f;
1001 const GLint rowDg0
= (rowD
[j
] >> 5) & 0x1f;
1002 const GLint rowDg1
= (rowD
[k
] >> 5) & 0x1f;
1003 const GLint rowAb0
= (rowA
[j
] >> 10) & 0x1f;
1004 const GLint rowAb1
= (rowA
[k
] >> 10) & 0x1f;
1005 const GLint rowBb0
= (rowB
[j
] >> 10) & 0x1f;
1006 const GLint rowBb1
= (rowB
[k
] >> 10) & 0x1f;
1007 const GLint rowCb0
= (rowC
[j
] >> 10) & 0x1f;
1008 const GLint rowCb1
= (rowC
[k
] >> 10) & 0x1f;
1009 const GLint rowDb0
= (rowD
[j
] >> 10) & 0x1f;
1010 const GLint rowDb1
= (rowD
[k
] >> 10) & 0x1f;
1011 const GLint rowAa0
= (rowA
[j
] >> 15) & 0x1;
1012 const GLint rowAa1
= (rowA
[k
] >> 15) & 0x1;
1013 const GLint rowBa0
= (rowB
[j
] >> 15) & 0x1;
1014 const GLint rowBa1
= (rowB
[k
] >> 15) & 0x1;
1015 const GLint rowCa0
= (rowC
[j
] >> 15) & 0x1;
1016 const GLint rowCa1
= (rowC
[k
] >> 15) & 0x1;
1017 const GLint rowDa0
= (rowD
[j
] >> 15) & 0x1;
1018 const GLint rowDa1
= (rowD
[k
] >> 15) & 0x1;
1019 const GLint r
= FILTER_SUM_3D(rowAr0
, rowAr1
, rowBr0
, rowBr1
,
1020 rowCr0
, rowCr1
, rowDr0
, rowDr1
);
1021 const GLint g
= FILTER_SUM_3D(rowAg0
, rowAg1
, rowBg0
, rowBg1
,
1022 rowCg0
, rowCg1
, rowDg0
, rowDg1
);
1023 const GLint b
= FILTER_SUM_3D(rowAb0
, rowAb1
, rowBb0
, rowBb1
,
1024 rowCb0
, rowCb1
, rowDb0
, rowDb1
);
1025 const GLint a
= FILTER_SUM_3D(rowAa0
, rowAa1
, rowBa0
, rowBa1
,
1026 rowCa0
, rowCa1
, rowDa0
, rowDa1
);
1028 dst
[i
] = (a
<< 15) | (b
<< 10) | (g
<< 5) | r
;
1031 else if ((datatype
== GL_UNSIGNED_SHORT_5_5_5_1
) && (comps
== 4)) {
1032 DECLARE_ROW_POINTERS0(GLushort
);
1034 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
1035 i
++, j
+= colStride
, k
+= colStride
) {
1036 const GLint rowAr0
= (rowA
[j
] >> 11) & 0x1f;
1037 const GLint rowAr1
= (rowA
[k
] >> 11) & 0x1f;
1038 const GLint rowBr0
= (rowB
[j
] >> 11) & 0x1f;
1039 const GLint rowBr1
= (rowB
[k
] >> 11) & 0x1f;
1040 const GLint rowCr0
= (rowC
[j
] >> 11) & 0x1f;
1041 const GLint rowCr1
= (rowC
[k
] >> 11) & 0x1f;
1042 const GLint rowDr0
= (rowD
[j
] >> 11) & 0x1f;
1043 const GLint rowDr1
= (rowD
[k
] >> 11) & 0x1f;
1044 const GLint rowAg0
= (rowA
[j
] >> 6) & 0x1f;
1045 const GLint rowAg1
= (rowA
[k
] >> 6) & 0x1f;
1046 const GLint rowBg0
= (rowB
[j
] >> 6) & 0x1f;
1047 const GLint rowBg1
= (rowB
[k
] >> 6) & 0x1f;
1048 const GLint rowCg0
= (rowC
[j
] >> 6) & 0x1f;
1049 const GLint rowCg1
= (rowC
[k
] >> 6) & 0x1f;
1050 const GLint rowDg0
= (rowD
[j
] >> 6) & 0x1f;
1051 const GLint rowDg1
= (rowD
[k
] >> 6) & 0x1f;
1052 const GLint rowAb0
= (rowA
[j
] >> 1) & 0x1f;
1053 const GLint rowAb1
= (rowA
[k
] >> 1) & 0x1f;
1054 const GLint rowBb0
= (rowB
[j
] >> 1) & 0x1f;
1055 const GLint rowBb1
= (rowB
[k
] >> 1) & 0x1f;
1056 const GLint rowCb0
= (rowC
[j
] >> 1) & 0x1f;
1057 const GLint rowCb1
= (rowC
[k
] >> 1) & 0x1f;
1058 const GLint rowDb0
= (rowD
[j
] >> 1) & 0x1f;
1059 const GLint rowDb1
= (rowD
[k
] >> 1) & 0x1f;
1060 const GLint rowAa0
= (rowA
[j
] & 0x1);
1061 const GLint rowAa1
= (rowA
[k
] & 0x1);
1062 const GLint rowBa0
= (rowB
[j
] & 0x1);
1063 const GLint rowBa1
= (rowB
[k
] & 0x1);
1064 const GLint rowCa0
= (rowC
[j
] & 0x1);
1065 const GLint rowCa1
= (rowC
[k
] & 0x1);
1066 const GLint rowDa0
= (rowD
[j
] & 0x1);
1067 const GLint rowDa1
= (rowD
[k
] & 0x1);
1068 const GLint r
= FILTER_SUM_3D(rowAr0
, rowAr1
, rowBr0
, rowBr1
,
1069 rowCr0
, rowCr1
, rowDr0
, rowDr1
);
1070 const GLint g
= FILTER_SUM_3D(rowAg0
, rowAg1
, rowBg0
, rowBg1
,
1071 rowCg0
, rowCg1
, rowDg0
, rowDg1
);
1072 const GLint b
= FILTER_SUM_3D(rowAb0
, rowAb1
, rowBb0
, rowBb1
,
1073 rowCb0
, rowCb1
, rowDb0
, rowDb1
);
1074 const GLint a
= FILTER_SUM_3D(rowAa0
, rowAa1
, rowBa0
, rowBa1
,
1075 rowCa0
, rowCa1
, rowDa0
, rowDa1
);
1077 dst
[i
] = (r
<< 11) | (g
<< 6) | (b
<< 1) | a
;
1080 else if ((datatype
== GL_UNSIGNED_BYTE_3_3_2
) && (comps
== 3)) {
1081 DECLARE_ROW_POINTERS0(GLushort
);
1083 for (i
= j
= 0, k
= k0
; i
< (GLuint
) dstWidth
;
1084 i
++, j
+= colStride
, k
+= colStride
) {
1085 const GLint rowAr0
= rowA
[j
] & 0x3;
1086 const GLint rowAr1
= rowA
[k
] & 0x3;
1087 const GLint rowBr0
= rowB
[j
] & 0x3;
1088 const GLint rowBr1
= rowB
[k
] & 0x3;
1089 const GLint rowCr0
= rowC
[j
] & 0x3;
1090 const GLint rowCr1
= rowC
[k
] & 0x3;
1091 const GLint rowDr0
= rowD
[j
] & 0x3;
1092 const GLint rowDr1
= rowD
[k
] & 0x3;
1093 const GLint rowAg0
= (rowA
[j
] >> 2) & 0x7;
1094 const GLint rowAg1
= (rowA
[k
] >> 2) & 0x7;
1095 const GLint rowBg0
= (rowB
[j
] >> 2) & 0x7;
1096 const GLint rowBg1
= (rowB
[k
] >> 2) & 0x7;
1097 const GLint rowCg0
= (rowC
[j
] >> 2) & 0x7;
1098 const GLint rowCg1
= (rowC
[k
] >> 2) & 0x7;
1099 const GLint rowDg0
= (rowD
[j
] >> 2) & 0x7;
1100 const GLint rowDg1
= (rowD
[k
] >> 2) & 0x7;
1101 const GLint rowAb0
= (rowA
[j
] >> 5) & 0x7;
1102 const GLint rowAb1
= (rowA
[k
] >> 5) & 0x7;
1103 const GLint rowBb0
= (rowB
[j
] >> 5) & 0x7;
1104 const GLint rowBb1
= (rowB
[k
] >> 5) & 0x7;
1105 const GLint rowCb0
= (rowC
[j
] >> 5) & 0x7;
1106 const GLint rowCb1
= (rowC
[k
] >> 5) & 0x7;
1107 const GLint rowDb0
= (rowD
[j
] >> 5) & 0x7;
1108 const GLint rowDb1
= (rowD
[k
] >> 5) & 0x7;
1109 const GLint r
= FILTER_SUM_3D(rowAr0
, rowAr1
, rowBr0
, rowBr1
,
1110 rowCr0
, rowCr1
, rowDr0
, rowDr1
);
1111 const GLint g
= FILTER_SUM_3D(rowAg0
, rowAg1
, rowBg0
, rowBg1
,
1112 rowCg0
, rowCg1
, rowDg0
, rowDg1
);
1113 const GLint b
= FILTER_SUM_3D(rowAb0
, rowAb1
, rowBb0
, rowBb1
,
1114 rowCb0
, rowCb1
, rowDb0
, rowDb1
);
1115 dst
[i
] = (b
<< 5) | (g
<< 2) | r
;
1119 _mesa_problem(NULL
, "bad format in do_row()");
1125 * These functions generate a 1/2-size mipmap image from a source image.
1126 * Texture borders are handled by copying or averaging the source image's
1127 * border texels, depending on the scale-down factor.
1131 make_1d_mipmap(GLenum datatype
, GLuint comps
, GLint border
,
1132 GLint srcWidth
, const GLubyte
*srcPtr
,
1133 GLint dstWidth
, GLubyte
*dstPtr
)
1135 const GLint bpt
= bytes_per_pixel(datatype
, comps
);
1139 /* skip the border pixel, if any */
1140 src
= srcPtr
+ border
* bpt
;
1141 dst
= dstPtr
+ border
* bpt
;
1143 /* we just duplicate the input row, kind of hack, saves code */
1144 do_row(datatype
, comps
, srcWidth
- 2 * border
, src
, src
,
1145 dstWidth
- 2 * border
, dst
);
1148 /* copy left-most pixel from source */
1151 memcpy(dstPtr
, srcPtr
, bpt
);
1152 /* copy right-most pixel from source */
1153 memcpy(dstPtr
+ (dstWidth
- 1) * bpt
,
1154 srcPtr
+ (srcWidth
- 1) * bpt
,
1161 make_2d_mipmap(GLenum datatype
, GLuint comps
, GLint border
,
1162 GLint srcWidth
, GLint srcHeight
,
1163 const GLubyte
*srcPtr
, GLint srcRowStride
,
1164 GLint dstWidth
, GLint dstHeight
,
1165 GLubyte
*dstPtr
, GLint dstRowStride
)
1167 const GLint bpt
= bytes_per_pixel(datatype
, comps
);
1168 const GLint srcWidthNB
= srcWidth
- 2 * border
; /* sizes w/out border */
1169 const GLint dstWidthNB
= dstWidth
- 2 * border
;
1170 const GLint dstHeightNB
= dstHeight
- 2 * border
;
1171 const GLint srcRowBytes
= bpt
* srcRowStride
;
1172 const GLint dstRowBytes
= bpt
* dstRowStride
;
1173 const GLubyte
*srcA
, *srcB
;
1175 GLint row
, srcRowStep
;
1177 /* Compute src and dst pointers, skipping any border */
1178 srcA
= srcPtr
+ border
* ((srcWidth
+ 1) * bpt
);
1179 if (srcHeight
> 1 && srcHeight
> dstHeight
) {
1180 /* sample from two source rows */
1181 srcB
= srcA
+ srcRowBytes
;
1185 /* sample from one source row */
1190 dst
= dstPtr
+ border
* ((dstWidth
+ 1) * bpt
);
1192 for (row
= 0; row
< dstHeightNB
; row
++) {
1193 do_row(datatype
, comps
, srcWidthNB
, srcA
, srcB
,
1195 srcA
+= srcRowStep
* srcRowBytes
;
1196 srcB
+= srcRowStep
* srcRowBytes
;
1200 /* This is ugly but probably won't be used much */
1202 /* fill in dest border */
1203 /* lower-left border pixel */
1206 memcpy(dstPtr
, srcPtr
, bpt
);
1207 /* lower-right border pixel */
1208 memcpy(dstPtr
+ (dstWidth
- 1) * bpt
,
1209 srcPtr
+ (srcWidth
- 1) * bpt
, bpt
);
1210 /* upper-left border pixel */
1211 memcpy(dstPtr
+ dstWidth
* (dstHeight
- 1) * bpt
,
1212 srcPtr
+ srcWidth
* (srcHeight
- 1) * bpt
, bpt
);
1213 /* upper-right border pixel */
1214 memcpy(dstPtr
+ (dstWidth
* dstHeight
- 1) * bpt
,
1215 srcPtr
+ (srcWidth
* srcHeight
- 1) * bpt
, bpt
);
1217 do_row(datatype
, comps
, srcWidthNB
,
1220 dstWidthNB
, dstPtr
+ bpt
);
1222 do_row(datatype
, comps
, srcWidthNB
,
1223 srcPtr
+ (srcWidth
* (srcHeight
- 1) + 1) * bpt
,
1224 srcPtr
+ (srcWidth
* (srcHeight
- 1) + 1) * bpt
,
1226 dstPtr
+ (dstWidth
* (dstHeight
- 1) + 1) * bpt
);
1227 /* left and right borders */
1228 if (srcHeight
== dstHeight
) {
1229 /* copy border pixel from src to dst */
1230 for (row
= 1; row
< srcHeight
; row
++) {
1231 memcpy(dstPtr
+ dstWidth
* row
* bpt
,
1232 srcPtr
+ srcWidth
* row
* bpt
, bpt
);
1233 memcpy(dstPtr
+ (dstWidth
* row
+ dstWidth
- 1) * bpt
,
1234 srcPtr
+ (srcWidth
* row
+ srcWidth
- 1) * bpt
, bpt
);
1238 /* average two src pixels each dest pixel */
1239 for (row
= 0; row
< dstHeightNB
; row
+= 2) {
1240 do_row(datatype
, comps
, 1,
1241 srcPtr
+ (srcWidth
* (row
* 2 + 1)) * bpt
,
1242 srcPtr
+ (srcWidth
* (row
* 2 + 2)) * bpt
,
1243 1, dstPtr
+ (dstWidth
* row
+ 1) * bpt
);
1244 do_row(datatype
, comps
, 1,
1245 srcPtr
+ (srcWidth
* (row
* 2 + 1) + srcWidth
- 1) * bpt
,
1246 srcPtr
+ (srcWidth
* (row
* 2 + 2) + srcWidth
- 1) * bpt
,
1247 1, dstPtr
+ (dstWidth
* row
+ 1 + dstWidth
- 1) * bpt
);
1255 make_3d_mipmap(GLenum datatype
, GLuint comps
, GLint border
,
1256 GLint srcWidth
, GLint srcHeight
, GLint srcDepth
,
1257 const GLubyte
*srcPtr
, GLint srcRowStride
,
1258 GLint dstWidth
, GLint dstHeight
, GLint dstDepth
,
1259 GLubyte
*dstPtr
, GLint dstRowStride
)
1261 const GLint bpt
= bytes_per_pixel(datatype
, comps
);
1262 const GLint srcWidthNB
= srcWidth
- 2 * border
; /* sizes w/out border */
1263 const GLint srcDepthNB
= srcDepth
- 2 * border
;
1264 const GLint dstWidthNB
= dstWidth
- 2 * border
;
1265 const GLint dstHeightNB
= dstHeight
- 2 * border
;
1266 const GLint dstDepthNB
= dstDepth
- 2 * border
;
1268 GLint bytesPerSrcImage
, bytesPerDstImage
;
1269 GLint bytesPerSrcRow
, bytesPerDstRow
;
1270 GLint srcImageOffset
, srcRowOffset
;
1272 (void) srcDepthNB
; /* silence warnings */
1275 bytesPerSrcImage
= srcWidth
* srcHeight
* bpt
;
1276 bytesPerDstImage
= dstWidth
* dstHeight
* bpt
;
1278 bytesPerSrcRow
= srcWidth
* bpt
;
1279 bytesPerDstRow
= dstWidth
* bpt
;
1281 /* Offset between adjacent src images to be averaged together */
1282 srcImageOffset
= (srcDepth
== dstDepth
) ? 0 : bytesPerSrcImage
;
1284 /* Offset between adjacent src rows to be averaged together */
1285 srcRowOffset
= (srcHeight
== dstHeight
) ? 0 : srcWidth
* bpt
;
1288 * Need to average together up to 8 src pixels for each dest pixel.
1289 * Break that down into 3 operations:
1290 * 1. take two rows from source image and average them together.
1291 * 2. take two rows from next source image and average them together.
1292 * 3. take the two averaged rows and average them for the final dst row.
1296 printf("mip3d %d x %d x %d -> %d x %d x %d\n",
1297 srcWidth, srcHeight, srcDepth, dstWidth, dstHeight, dstDepth);
1300 for (img
= 0; img
< dstDepthNB
; img
++) {
1301 /* first source image pointer, skipping border */
1302 const GLubyte
*imgSrcA
= srcPtr
1303 + (bytesPerSrcImage
+ bytesPerSrcRow
+ border
) * bpt
* border
1304 + img
* (bytesPerSrcImage
+ srcImageOffset
);
1305 /* second source image pointer, skipping border */
1306 const GLubyte
*imgSrcB
= imgSrcA
+ srcImageOffset
;
1307 /* address of the dest image, skipping border */
1308 GLubyte
*imgDst
= dstPtr
1309 + (bytesPerDstImage
+ bytesPerDstRow
+ border
) * bpt
* border
1310 + img
* bytesPerDstImage
;
1312 /* setup the four source row pointers and the dest row pointer */
1313 const GLubyte
*srcImgARowA
= imgSrcA
;
1314 const GLubyte
*srcImgARowB
= imgSrcA
+ srcRowOffset
;
1315 const GLubyte
*srcImgBRowA
= imgSrcB
;
1316 const GLubyte
*srcImgBRowB
= imgSrcB
+ srcRowOffset
;
1317 GLubyte
*dstImgRow
= imgDst
;
1319 for (row
= 0; row
< dstHeightNB
; row
++) {
1320 do_row_3D(datatype
, comps
, srcWidthNB
,
1321 srcImgARowA
, srcImgARowB
,
1322 srcImgBRowA
, srcImgBRowB
,
1323 dstWidthNB
, dstImgRow
);
1325 /* advance to next rows */
1326 srcImgARowA
+= bytesPerSrcRow
+ srcRowOffset
;
1327 srcImgARowB
+= bytesPerSrcRow
+ srcRowOffset
;
1328 srcImgBRowA
+= bytesPerSrcRow
+ srcRowOffset
;
1329 srcImgBRowB
+= bytesPerSrcRow
+ srcRowOffset
;
1330 dstImgRow
+= bytesPerDstRow
;
1335 /* Luckily we can leverage the make_2d_mipmap() function here! */
1337 /* do front border image */
1338 make_2d_mipmap(datatype
, comps
, 1, srcWidth
, srcHeight
, srcPtr
, srcRowStride
,
1339 dstWidth
, dstHeight
, dstPtr
, dstRowStride
);
1340 /* do back border image */
1341 make_2d_mipmap(datatype
, comps
, 1, srcWidth
, srcHeight
,
1342 srcPtr
+ bytesPerSrcImage
* (srcDepth
- 1), srcRowStride
,
1343 dstWidth
, dstHeight
,
1344 dstPtr
+ bytesPerDstImage
* (dstDepth
- 1), dstRowStride
);
1345 /* do four remaining border edges that span the image slices */
1346 if (srcDepth
== dstDepth
) {
1347 /* just copy border pixels from src to dst */
1348 for (img
= 0; img
< dstDepthNB
; img
++) {
1352 /* do border along [img][row=0][col=0] */
1353 src
= srcPtr
+ (img
+ 1) * bytesPerSrcImage
;
1354 dst
= dstPtr
+ (img
+ 1) * bytesPerDstImage
;
1355 memcpy(dst
, src
, bpt
);
1357 /* do border along [img][row=dstHeight-1][col=0] */
1358 src
= srcPtr
+ (img
* 2 + 1) * bytesPerSrcImage
1359 + (srcHeight
- 1) * bytesPerSrcRow
;
1360 dst
= dstPtr
+ (img
+ 1) * bytesPerDstImage
1361 + (dstHeight
- 1) * bytesPerDstRow
;
1362 memcpy(dst
, src
, bpt
);
1364 /* do border along [img][row=0][col=dstWidth-1] */
1365 src
= srcPtr
+ (img
* 2 + 1) * bytesPerSrcImage
1366 + (srcWidth
- 1) * bpt
;
1367 dst
= dstPtr
+ (img
+ 1) * bytesPerDstImage
1368 + (dstWidth
- 1) * bpt
;
1369 memcpy(dst
, src
, bpt
);
1371 /* do border along [img][row=dstHeight-1][col=dstWidth-1] */
1372 src
= srcPtr
+ (img
* 2 + 1) * bytesPerSrcImage
1373 + (bytesPerSrcImage
- bpt
);
1374 dst
= dstPtr
+ (img
+ 1) * bytesPerDstImage
1375 + (bytesPerDstImage
- bpt
);
1376 memcpy(dst
, src
, bpt
);
1380 /* average border pixels from adjacent src image pairs */
1381 ASSERT(srcDepthNB
== 2 * dstDepthNB
);
1382 for (img
= 0; img
< dstDepthNB
; img
++) {
1386 /* do border along [img][row=0][col=0] */
1387 src
= srcPtr
+ (img
* 2 + 1) * bytesPerSrcImage
;
1388 dst
= dstPtr
+ (img
+ 1) * bytesPerDstImage
;
1389 do_row(datatype
, comps
, 1, src
, src
+ srcImageOffset
, 1, dst
);
1391 /* do border along [img][row=dstHeight-1][col=0] */
1392 src
= srcPtr
+ (img
* 2 + 1) * bytesPerSrcImage
1393 + (srcHeight
- 1) * bytesPerSrcRow
;
1394 dst
= dstPtr
+ (img
+ 1) * bytesPerDstImage
1395 + (dstHeight
- 1) * bytesPerDstRow
;
1396 do_row(datatype
, comps
, 1, src
, src
+ srcImageOffset
, 1, dst
);
1398 /* do border along [img][row=0][col=dstWidth-1] */
1399 src
= srcPtr
+ (img
* 2 + 1) * bytesPerSrcImage
1400 + (srcWidth
- 1) * bpt
;
1401 dst
= dstPtr
+ (img
+ 1) * bytesPerDstImage
1402 + (dstWidth
- 1) * bpt
;
1403 do_row(datatype
, comps
, 1, src
, src
+ srcImageOffset
, 1, dst
);
1405 /* do border along [img][row=dstHeight-1][col=dstWidth-1] */
1406 src
= srcPtr
+ (img
* 2 + 1) * bytesPerSrcImage
1407 + (bytesPerSrcImage
- bpt
);
1408 dst
= dstPtr
+ (img
+ 1) * bytesPerDstImage
1409 + (bytesPerDstImage
- bpt
);
1410 do_row(datatype
, comps
, 1, src
, src
+ srcImageOffset
, 1, dst
);
1418 make_1d_stack_mipmap(GLenum datatype
, GLuint comps
, GLint border
,
1419 GLint srcWidth
, const GLubyte
*srcPtr
, GLuint srcRowStride
,
1420 GLint dstWidth
, GLint dstHeight
,
1421 GLubyte
*dstPtr
, GLuint dstRowStride
)
1423 const GLint bpt
= bytes_per_pixel(datatype
, comps
);
1424 const GLint srcWidthNB
= srcWidth
- 2 * border
; /* sizes w/out border */
1425 const GLint dstWidthNB
= dstWidth
- 2 * border
;
1426 const GLint dstHeightNB
= dstHeight
- 2 * border
;
1427 const GLint srcRowBytes
= bpt
* srcRowStride
;
1428 const GLint dstRowBytes
= bpt
* dstRowStride
;
1433 /* Compute src and dst pointers, skipping any border */
1434 src
= srcPtr
+ border
* ((srcWidth
+ 1) * bpt
);
1435 dst
= dstPtr
+ border
* ((dstWidth
+ 1) * bpt
);
1437 for (row
= 0; row
< dstHeightNB
; row
++) {
1438 do_row(datatype
, comps
, srcWidthNB
, src
, src
,
1445 /* copy left-most pixel from source */
1448 memcpy(dstPtr
, srcPtr
, bpt
);
1449 /* copy right-most pixel from source */
1450 memcpy(dstPtr
+ (dstWidth
- 1) * bpt
,
1451 srcPtr
+ (srcWidth
- 1) * bpt
,
1459 * There is quite a bit of refactoring that could be done with this function
1460 * and \c make_2d_mipmap.
1463 make_2d_stack_mipmap(GLenum datatype
, GLuint comps
, GLint border
,
1464 GLint srcWidth
, GLint srcHeight
,
1465 const GLubyte
*srcPtr
, GLint srcRowStride
,
1466 GLint dstWidth
, GLint dstHeight
, GLint dstDepth
,
1467 GLubyte
*dstPtr
, GLint dstRowStride
)
1469 const GLint bpt
= bytes_per_pixel(datatype
, comps
);
1470 const GLint srcWidthNB
= srcWidth
- 2 * border
; /* sizes w/out border */
1471 const GLint dstWidthNB
= dstWidth
- 2 * border
;
1472 const GLint dstHeightNB
= dstHeight
- 2 * border
;
1473 const GLint dstDepthNB
= dstDepth
- 2 * border
;
1474 const GLint srcRowBytes
= bpt
* srcRowStride
;
1475 const GLint dstRowBytes
= bpt
* dstRowStride
;
1476 const GLubyte
*srcA
, *srcB
;
1481 /* Compute src and dst pointers, skipping any border */
1482 srcA
= srcPtr
+ border
* ((srcWidth
+ 1) * bpt
);
1484 srcB
= srcA
+ srcRowBytes
;
1487 dst
= dstPtr
+ border
* ((dstWidth
+ 1) * bpt
);
1489 for (layer
= 0; layer
< dstDepthNB
; layer
++) {
1490 for (row
= 0; row
< dstHeightNB
; row
++) {
1491 do_row(datatype
, comps
, srcWidthNB
, srcA
, srcB
,
1493 srcA
+= 2 * srcRowBytes
;
1494 srcB
+= 2 * srcRowBytes
;
1498 /* This is ugly but probably won't be used much */
1500 /* fill in dest border */
1501 /* lower-left border pixel */
1504 memcpy(dstPtr
, srcPtr
, bpt
);
1505 /* lower-right border pixel */
1506 memcpy(dstPtr
+ (dstWidth
- 1) * bpt
,
1507 srcPtr
+ (srcWidth
- 1) * bpt
, bpt
);
1508 /* upper-left border pixel */
1509 memcpy(dstPtr
+ dstWidth
* (dstHeight
- 1) * bpt
,
1510 srcPtr
+ srcWidth
* (srcHeight
- 1) * bpt
, bpt
);
1511 /* upper-right border pixel */
1512 memcpy(dstPtr
+ (dstWidth
* dstHeight
- 1) * bpt
,
1513 srcPtr
+ (srcWidth
* srcHeight
- 1) * bpt
, bpt
);
1515 do_row(datatype
, comps
, srcWidthNB
,
1518 dstWidthNB
, dstPtr
+ bpt
);
1520 do_row(datatype
, comps
, srcWidthNB
,
1521 srcPtr
+ (srcWidth
* (srcHeight
- 1) + 1) * bpt
,
1522 srcPtr
+ (srcWidth
* (srcHeight
- 1) + 1) * bpt
,
1524 dstPtr
+ (dstWidth
* (dstHeight
- 1) + 1) * bpt
);
1525 /* left and right borders */
1526 if (srcHeight
== dstHeight
) {
1527 /* copy border pixel from src to dst */
1528 for (row
= 1; row
< srcHeight
; row
++) {
1529 memcpy(dstPtr
+ dstWidth
* row
* bpt
,
1530 srcPtr
+ srcWidth
* row
* bpt
, bpt
);
1531 memcpy(dstPtr
+ (dstWidth
* row
+ dstWidth
- 1) * bpt
,
1532 srcPtr
+ (srcWidth
* row
+ srcWidth
- 1) * bpt
, bpt
);
1536 /* average two src pixels each dest pixel */
1537 for (row
= 0; row
< dstHeightNB
; row
+= 2) {
1538 do_row(datatype
, comps
, 1,
1539 srcPtr
+ (srcWidth
* (row
* 2 + 1)) * bpt
,
1540 srcPtr
+ (srcWidth
* (row
* 2 + 2)) * bpt
,
1541 1, dstPtr
+ (dstWidth
* row
+ 1) * bpt
);
1542 do_row(datatype
, comps
, 1,
1543 srcPtr
+ (srcWidth
* (row
* 2 + 1) + srcWidth
- 1) * bpt
,
1544 srcPtr
+ (srcWidth
* (row
* 2 + 2) + srcWidth
- 1) * bpt
,
1545 1, dstPtr
+ (dstWidth
* row
+ 1 + dstWidth
- 1) * bpt
);
1554 * Down-sample a texture image to produce the next lower mipmap level.
1555 * \param comps components per texel (1, 2, 3 or 4)
1556 * \param srcRowStride stride between source rows, in texels
1557 * \param dstRowStride stride between destination rows, in texels
1560 _mesa_generate_mipmap_level(GLenum target
,
1561 GLenum datatype
, GLuint comps
,
1563 GLint srcWidth
, GLint srcHeight
, GLint srcDepth
,
1564 const GLubyte
*srcData
,
1566 GLint dstWidth
, GLint dstHeight
, GLint dstDepth
,
1571 * We use simple 2x2 averaging to compute the next mipmap level.
1575 make_1d_mipmap(datatype
, comps
, border
,
1580 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
1581 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
1582 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
1583 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
1584 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
1585 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
1586 make_2d_mipmap(datatype
, comps
, border
,
1587 srcWidth
, srcHeight
, srcData
, srcRowStride
,
1588 dstWidth
, dstHeight
, dstData
, dstRowStride
);
1591 make_3d_mipmap(datatype
, comps
, border
,
1592 srcWidth
, srcHeight
, srcDepth
,
1593 srcData
, srcRowStride
,
1594 dstWidth
, dstHeight
, dstDepth
,
1595 dstData
, dstRowStride
);
1597 case GL_TEXTURE_1D_ARRAY_EXT
:
1598 make_1d_stack_mipmap(datatype
, comps
, border
,
1599 srcWidth
, srcData
, srcRowStride
,
1600 dstWidth
, dstHeight
,
1601 dstData
, dstRowStride
);
1603 case GL_TEXTURE_2D_ARRAY_EXT
:
1604 make_2d_stack_mipmap(datatype
, comps
, border
,
1605 srcWidth
, srcHeight
,
1606 srcData
, srcRowStride
,
1607 dstWidth
, dstHeight
,
1608 dstDepth
, dstData
, dstRowStride
);
1610 case GL_TEXTURE_RECTANGLE_NV
:
1611 /* no mipmaps, do nothing */
1614 _mesa_problem(NULL
, "bad dimensions in _mesa_generate_mipmaps");
1621 * compute next (level+1) image size
1622 * \return GL_FALSE if no smaller size can be generated (eg. src is 1x1x1 size)
1625 next_mipmap_level_size(GLenum target
, GLint border
,
1626 GLint srcWidth
, GLint srcHeight
, GLint srcDepth
,
1627 GLint
*dstWidth
, GLint
*dstHeight
, GLint
*dstDepth
)
1629 if (srcWidth
- 2 * border
> 1) {
1630 *dstWidth
= (srcWidth
- 2 * border
) / 2 + 2 * border
;
1633 *dstWidth
= srcWidth
; /* can't go smaller */
1636 if ((srcHeight
- 2 * border
> 1) &&
1637 (target
!= GL_TEXTURE_1D_ARRAY_EXT
)) {
1638 *dstHeight
= (srcHeight
- 2 * border
) / 2 + 2 * border
;
1641 *dstHeight
= srcHeight
; /* can't go smaller */
1644 if ((srcDepth
- 2 * border
> 1) &&
1645 (target
!= GL_TEXTURE_2D_ARRAY_EXT
)) {
1646 *dstDepth
= (srcDepth
- 2 * border
) / 2 + 2 * border
;
1649 *dstDepth
= srcDepth
; /* can't go smaller */
1652 if (*dstWidth
== srcWidth
&&
1653 *dstHeight
== srcHeight
&&
1654 *dstDepth
== srcDepth
) {
1666 * Automatic mipmap generation.
1667 * This is the fallback/default function for ctx->Driver.GenerateMipmap().
1668 * Generate a complete set of mipmaps from texObj's BaseLevel image.
1669 * Stop at texObj's MaxLevel or when we get to the 1x1 texture.
1670 * For cube maps, target will be one of
1671 * GL_TEXTURE_CUBE_MAP_POSITIVE/NEGATIVE_X/Y/Z; never GL_TEXTURE_CUBE_MAP.
1674 _mesa_generate_mipmap(struct gl_context
*ctx
, GLenum target
,
1675 struct gl_texture_object
*texObj
)
1677 const struct gl_texture_image
*srcImage
;
1678 gl_format convertFormat
;
1679 const GLubyte
*srcData
= NULL
;
1680 GLubyte
*dstData
= NULL
;
1681 GLint level
, maxLevels
;
1686 srcImage
= _mesa_select_tex_image(ctx
, texObj
, target
, texObj
->BaseLevel
);
1689 maxLevels
= _mesa_max_texture_levels(ctx
, texObj
->Target
);
1690 ASSERT(maxLevels
> 0); /* bad target */
1692 /* Find convertFormat - the format that do_row() will process */
1694 if (_mesa_is_format_compressed(srcImage
->TexFormat
)) {
1695 /* setup for compressed textures - need to allocate temporary
1696 * image buffers to hold uncompressed images.
1699 GLint components
, size
;
1702 assert(texObj
->Target
== GL_TEXTURE_2D
||
1703 texObj
->Target
== GL_TEXTURE_CUBE_MAP_ARB
);
1705 if (srcImage
->_BaseFormat
== GL_RGB
) {
1706 convertFormat
= MESA_FORMAT_RGB888
;
1709 else if (srcImage
->_BaseFormat
== GL_RGBA
) {
1710 convertFormat
= MESA_FORMAT_RGBA8888
;
1714 _mesa_problem(ctx
, "bad srcImage->_BaseFormat in _mesa_generate_mipmaps");
1718 /* allocate storage for uncompressed GL_RGB or GL_RGBA images */
1719 size
= _mesa_bytes_per_pixel(srcImage
->_BaseFormat
, CHAN_TYPE
)
1720 * srcImage
->Width
* srcImage
->Height
* srcImage
->Depth
+ 20;
1721 /* 20 extra bytes, just be safe when calling last FetchTexel */
1722 srcData
= (GLubyte
*) malloc(size
);
1724 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "generate mipmaps");
1727 dstData
= (GLubyte
*) malloc(size
/ 2); /* 1/4 would probably be OK */
1729 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "generate mipmaps");
1730 free((void *) srcData
);
1734 /* decompress base image here */
1735 dst
= (GLchan
*) srcData
;
1736 for (row
= 0; row
< srcImage
->Height
; row
++) {
1738 for (col
= 0; col
< srcImage
->Width
; col
++) {
1739 srcImage
->FetchTexelc(srcImage
, col
, row
, 0, dst
);
1746 convertFormat
= srcImage
->TexFormat
;
1749 _mesa_format_to_type_and_comps(convertFormat
, &datatype
, &comps
);
1751 for (level
= texObj
->BaseLevel
; level
< texObj
->MaxLevel
1752 && level
< maxLevels
- 1; level
++) {
1753 /* generate image[level+1] from image[level] */
1754 const struct gl_texture_image
*srcImage
;
1755 struct gl_texture_image
*dstImage
;
1756 GLint srcWidth
, srcHeight
, srcDepth
;
1757 GLint dstWidth
, dstHeight
, dstDepth
;
1759 GLboolean nextLevel
;
1761 /* get src image parameters */
1762 srcImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
1764 srcWidth
= srcImage
->Width
;
1765 srcHeight
= srcImage
->Height
;
1766 srcDepth
= srcImage
->Depth
;
1767 border
= srcImage
->Border
;
1769 nextLevel
= next_mipmap_level_size(target
, border
,
1770 srcWidth
, srcHeight
, srcDepth
,
1771 &dstWidth
, &dstHeight
, &dstDepth
);
1774 if (_mesa_is_format_compressed(srcImage
->TexFormat
)) {
1775 free((void *) srcData
);
1781 /* get dest gl_texture_image */
1782 dstImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
+ 1);
1784 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "generating mipmaps");
1788 /* Free old image data */
1790 ctx
->Driver
.FreeTexImageData(ctx
, dstImage
);
1792 /* initialize new image */
1793 _mesa_init_teximage_fields(ctx
, target
, dstImage
, dstWidth
, dstHeight
,
1794 dstDepth
, border
, srcImage
->InternalFormat
,
1795 srcImage
->TexFormat
);
1796 dstImage
->DriverData
= NULL
;
1797 dstImage
->FetchTexelc
= srcImage
->FetchTexelc
;
1798 dstImage
->FetchTexelf
= srcImage
->FetchTexelf
;
1800 /* Alloc new teximage data buffer */
1802 GLuint size
= _mesa_format_image_size(dstImage
->TexFormat
,
1803 dstWidth
, dstHeight
, dstDepth
);
1804 dstImage
->Data
= _mesa_alloc_texmemory(size
);
1805 if (!dstImage
->Data
) {
1806 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "generating mipmaps");
1811 /* Setup src and dest data pointers */
1812 if (_mesa_is_format_compressed(dstImage
->TexFormat
)) {
1813 /* srcData and dstData are already set */
1818 srcData
= (const GLubyte
*) srcImage
->Data
;
1819 dstData
= (GLubyte
*) dstImage
->Data
;
1822 ASSERT(dstImage
->TexFormat
);
1823 ASSERT(dstImage
->FetchTexelc
);
1824 ASSERT(dstImage
->FetchTexelf
);
1826 _mesa_generate_mipmap_level(target
, datatype
, comps
, border
,
1827 srcWidth
, srcHeight
, srcDepth
,
1828 srcData
, srcImage
->RowStride
,
1829 dstWidth
, dstHeight
, dstDepth
,
1830 dstData
, dstImage
->RowStride
);
1833 if (_mesa_is_format_compressed(dstImage
->TexFormat
)) {
1835 /* compress image from dstData into dstImage->Data */
1836 const GLenum srcFormat
= _mesa_get_format_base_format(convertFormat
);
1838 = _mesa_format_row_stride(dstImage
->TexFormat
, dstWidth
);
1839 ASSERT(srcFormat
== GL_RGB
|| srcFormat
== GL_RGBA
);
1841 _mesa_texstore(ctx
, 2, dstImage
->_BaseFormat
,
1842 dstImage
->TexFormat
,
1844 0, 0, 0, /* dstX/Y/Zoffset */
1845 dstRowStride
, 0, /* strides */
1846 dstWidth
, dstHeight
, 1, /* size */
1847 srcFormat
, CHAN_TYPE
,
1848 dstData
, /* src data, actually */
1849 &ctx
->DefaultPacking
);
1851 /* swap src and dest pointers */
1852 temp
= (GLubyte
*) srcData
;
1857 } /* loop over mipmap levels */
1862 * Helper function for drivers which need to rescale texture images to
1863 * certain aspect ratios.
1864 * Nearest filtering only (for broken hardware that can't support
1865 * all aspect ratios). This can be made a lot faster, but I don't
1866 * really care enough...
1869 _mesa_rescale_teximage2d(GLuint bytesPerPixel
,
1870 GLuint srcStrideInPixels
,
1871 GLuint dstRowStride
,
1872 GLint srcWidth
, GLint srcHeight
,
1873 GLint dstWidth
, GLint dstHeight
,
1874 const GLvoid
*srcImage
, GLvoid
*dstImage
)
1878 #define INNER_LOOP( TYPE, HOP, WOP ) \
1879 for ( row = 0 ; row < dstHeight ; row++ ) { \
1880 GLint srcRow = row HOP hScale; \
1881 for ( col = 0 ; col < dstWidth ; col++ ) { \
1882 GLint srcCol = col WOP wScale; \
1883 dst[col] = src[srcRow * srcStrideInPixels + srcCol]; \
1885 dst = (TYPE *) ((GLubyte *) dst + dstRowStride); \
1888 #define RESCALE_IMAGE( TYPE ) \
1890 const TYPE *src = (const TYPE *)srcImage; \
1891 TYPE *dst = (TYPE *)dstImage; \
1893 if ( srcHeight < dstHeight ) { \
1894 const GLint hScale = dstHeight / srcHeight; \
1895 if ( srcWidth < dstWidth ) { \
1896 const GLint wScale = dstWidth / srcWidth; \
1897 INNER_LOOP( TYPE, /, / ); \
1900 const GLint wScale = srcWidth / dstWidth; \
1901 INNER_LOOP( TYPE, /, * ); \
1905 const GLint hScale = srcHeight / dstHeight; \
1906 if ( srcWidth < dstWidth ) { \
1907 const GLint wScale = dstWidth / srcWidth; \
1908 INNER_LOOP( TYPE, *, / ); \
1911 const GLint wScale = srcWidth / dstWidth; \
1912 INNER_LOOP( TYPE, *, * ); \
1917 switch ( bytesPerPixel
) {
1919 RESCALE_IMAGE( GLuint
);
1923 RESCALE_IMAGE( GLushort
);
1927 RESCALE_IMAGE( GLubyte
);
1930 _mesa_problem(NULL
,"unexpected bytes/pixel in _mesa_rescale_teximage2d");
1936 * Upscale an image by replication, not (typical) stretching.
1937 * We use this when the image width or height is less than a
1938 * certain size (4, 8) and we need to upscale an image.
1941 _mesa_upscale_teximage2d(GLsizei inWidth
, GLsizei inHeight
,
1942 GLsizei outWidth
, GLsizei outHeight
,
1943 GLint comps
, const GLchan
*src
, GLint srcRowStride
,
1948 ASSERT(outWidth
>= inWidth
);
1949 ASSERT(outHeight
>= inHeight
);
1951 ASSERT(inWidth
== 1 || inWidth
== 2 || inHeight
== 1 || inHeight
== 2);
1952 ASSERT((outWidth
& 3) == 0);
1953 ASSERT((outHeight
& 3) == 0);
1956 for (i
= 0; i
< outHeight
; i
++) {
1957 const GLint ii
= i
% inHeight
;
1958 for (j
= 0; j
< outWidth
; j
++) {
1959 const GLint jj
= j
% inWidth
;
1960 for (k
= 0; k
< comps
; k
++) {
1961 dest
[(i
* outWidth
+ j
) * comps
+ k
]
1962 = src
[ii
* srcRowStride
+ jj
* comps
+ k
];