hmm, no tutorial link here, but bilinear won't help you very much with scale <0.5 and >2.0 (sure, it will look way better then without it, but in many cases will still look bad when you use a scale like 4.1 or 0.2)
What biliear does is this:
if you have got 10 points (0..9) and you want to rescale them to 11 points (0..10) you want to take point 0,0.9,1.8,2.7,3.6,4.5,5.4,6.3,7.2,8.1,9.0 and draw them as points 0,1,2,3,4,5,6,7,8,9,10 on the new texture.
So what bilinear does (in 1D) is:
for 0 =pixel0*1.0f+pixel1*0.0f
for 0.9=pixel0*0.1f+pixel1*0.9f
for 1.8=pixel1*0.2f+pixel2*0.8f
etc
The same goes for 2d (but you obviously take 4 pixels)
So in short it gets the pixel color by linearly calculating a color between 4 pixels
So your resize in 1d would look like
we have: width (originalwidth,newwidth) and 1d data (from,to)
float scale=originalwidth/newwidth;
float originalx=0;
for (int newx=0;newx<newwidth;newx++)
{
int originalx2=(int)originalx;
float pos=originalx=originalx-(float)originalx2; (so if originalx=2.3 pos=0.3)
*to[newx]=*from[originalx2]*(1.0f-pos)+*from[originalx2+1]*(pos);
originalx+=scale;
}
That's about how it works in 1d (you should obviously use fixedpoint math if you care for speed)


Reply With Quote
