- if (resamplerowsize < outwidth*4)
- {
- if (resamplerow1)
- Mem_Free(resamplerow1);
- if (resamplerow2)
- Mem_Free(resamplerow2);
- resamplerowsize = outwidth*4;
- resamplerow1 = Mem_Alloc(texturemempool, resamplerowsize);
- resamplerow2 = Mem_Alloc(texturemempool, resamplerowsize);
- }
-#define row1 resamplerow1
-#define row2 resamplerow2
- if (bytesperpixel == 4)
- {
- if (r_lerpimages.integer)
- {
- int i, j, yi, oldy, f, fstep, lerp, endy = (inheight-1), inwidth4 = inwidth*4, outwidth4 = outwidth*4;
- byte *inrow, *out;
- out = outdata;
- fstep = (int) (inheight*65536.0f/outheight);
-
- inrow = indata;
- oldy = 0;
- R_ResampleTextureLerpLine (inrow, row1, inwidth, outwidth, bytesperpixel);
- R_ResampleTextureLerpLine (inrow + inwidth4, row2, inwidth, outwidth, bytesperpixel);
- for (i = 0, f = 0;i < outheight;i++,f += fstep)
- {
- yi = f >> 16;
- if (yi < endy)
- {
- lerp = f & 0xFFFF;
- if (yi != oldy)
- {
- inrow = (byte *)indata + inwidth4*yi;
- if (yi == oldy+1)
- memcpy(row1, row2, outwidth4);
- else
- R_ResampleTextureLerpLine (inrow, row1, inwidth, outwidth, bytesperpixel);
- R_ResampleTextureLerpLine (inrow + inwidth4, row2, inwidth, outwidth, bytesperpixel);
- oldy = yi;
- }
- j = outwidth - 4;
- while(j >= 0)
- {
-#define LERPBYTE(i) out[i] = (byte) ((((row2[i] - row1[i]) * lerp) >> 16) + row1[i])
- LERPBYTE( 0);
- LERPBYTE( 1);
- LERPBYTE( 2);
- LERPBYTE( 3);
- LERPBYTE( 4);
- LERPBYTE( 5);
- LERPBYTE( 6);
- LERPBYTE( 7);
- LERPBYTE( 8);
- LERPBYTE( 9);
- LERPBYTE(10);
- LERPBYTE(11);
- LERPBYTE(12);
- LERPBYTE(13);
- LERPBYTE(14);
- LERPBYTE(15);
- out += 16;
- row1 += 16;
- row2 += 16;
- j -= 4;
- }
- if (j & 2)
- {
- LERPBYTE( 0);
- LERPBYTE( 1);
- LERPBYTE( 2);
- LERPBYTE( 3);
- LERPBYTE( 4);
- LERPBYTE( 5);
- LERPBYTE( 6);
- LERPBYTE( 7);
- out += 8;
- row1 += 8;
- row2 += 8;
- }
- if (j & 1)
- {
- LERPBYTE( 0);
- LERPBYTE( 1);
- LERPBYTE( 2);
- LERPBYTE( 3);
- out += 4;
- row1 += 4;
- row2 += 4;
- }
- row1 -= outwidth4;
- row2 -= outwidth4;
- }
- else
- {
- if (yi != oldy)
- {
- inrow = (byte *)indata + inwidth4*yi;
- if (yi == oldy+1)
- memcpy(row1, row2, outwidth4);
- else
- R_ResampleTextureLerpLine (inrow, row1, inwidth, outwidth, bytesperpixel);
- oldy = yi;
- }
- memcpy(out, row1, outwidth4);
- }
- }
- }
- else
- {
- int i, j;
- unsigned frac, fracstep;
- // relies on int being 4 bytes
- int *inrow, *out;
- out = outdata;
-
- fracstep = inwidth*0x10000/outwidth;
- for (i = 0;i < outheight;i++)
- {
- inrow = (int *)indata + inwidth*(i*inheight/outheight);
- frac = fracstep >> 1;
- j = outwidth - 4;
- while (j >= 0)
- {
- out[0] = inrow[frac >> 16];frac += fracstep;
- out[1] = inrow[frac >> 16];frac += fracstep;
- out[2] = inrow[frac >> 16];frac += fracstep;
- out[3] = inrow[frac >> 16];frac += fracstep;
- out += 4;
- j -= 4;
- }
- if (j & 2)
- {
- out[0] = inrow[frac >> 16];frac += fracstep;
- out[1] = inrow[frac >> 16];frac += fracstep;
- out += 2;
- }
- if (j & 1)
- {
- out[0] = inrow[frac >> 16];frac += fracstep;
- out += 1;
- }
- }
- }
- }
- else if (bytesperpixel == 3)