i googled it and find this. sry its too long but i really dont understand any sh.t bout this:
================
240 ResampleTexture
241
242 Used to resample images in a more general than quartering fashion.
243
244 This will only be filtered properly if the resampled size
245 is greater than half the original size.
246
247 If a larger shrinking is needed, use the mipmap function
248 before or after.
249 ================
250 */
251 static void ResampleTexture( unsigned *in, int inwidth, int inheight, unsigned *out,
252 int outwidth, int outheight ) {
253 int i, j;
254 unsigned *inrow, *inrow2;
255 unsigned frac, fracstep;
256 unsigned p1[2048], p2[2048];
257 byte *pix1, *pix2, *pix3, *pix4;
258
259 if (outwidth>2048)
260
ri.Error(ERR_DROP, "ResampleTexture: max width");
261
262 fracstep = inwidth*0x10000/outwidth;
263
264 frac = fracstep>>2;
265 for ( i=0 ; i<outwidth ; i++ ) {
266 p1[i] = 4*(frac>>16);
267 frac += fracstep;
268 }
269 frac = 3*(fracstep>>2);
270 for ( i=0 ; i<outwidth ; i++ ) {
271 p2[i] = 4*(frac>>16);
272 frac += fracstep;
273 }
274
275 for (i=0 ; i<outheight ; i++, out += outwidth) {
276 inrow = in + inwidth*(int)((i+0.25)*inheight/outheight);
277 inrow2 = in + inwidth*(int)((i+0.75)*inheight/outheight);
278 frac = fracstep >> 1;
279 for (j=0 ; j<outwidth ; j++) {
280 pix1 = (byte *)inrow + p1[j];
281 pix2 = (byte *)inrow + p2[j];
282 pix3 = (byte *)inrow2 + p1[j];
283 pix4 = (byte *)inrow2 + p2[j];
284 ((byte *)(out+j))[0] = (pix1[0] + pix2[0] + pix3[0] + pix4[0])>>2;
285 ((byte *)(out+j))[1] = (pix1[1] + pix2[1] + pix3[1] + pix4[1])>>2;
286 ((byte *)(out+j))[2] = (pix1[2] + pix2[2] + pix3[2] + pix4[2])>>2;
287 ((byte *)(out+j))[3] = (pix1[3] + pix2[3] + pix3[3] + pix4[3])>>2;
This post has been edited by Moldar: 01 May 2010 - 05:10 PM