too long time without a Fastest something ! so I decided to share another nice code from 3DzzD

the following function enable to filter 4 pixels using two interpolation factors to perform fast/perpixel "
bicubic bilinear/cubic filtering" of an image
the filtering is based on area covered by pixels based on their interpolation factors, and the result is something that look very similar to bicubic filtering :
- make pixels appear rounded when zoomed a lot and antialiased when zoomed out
- you can see such effect in most 3DzzD demo if you get very close of a texture : this enable high quality when texture ar zoomed out (under pixel presicion up to 1/256 with in conjonction with mipmapping enable some kind of 2*2 anisiotropic filtering) and also zoomed in that make pixels blend nice and appear rounded.
NB: for readability it is adapted from the original version wich is a little different
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
|
public int interpolate(int c1,int c2,int c3,int c4,int bX, int bY) { int f24=(bX*bY)>>8; int f23=bX-f24; int f14=bY-f24; int f13=((256-bX)*(256-bY))>>8; return ((((c1&0xFF00FF)*f13+(c2&0xFF00FF)*f23+(c3&0xFF00FF)*f14+(c4&0xFF00FF)*f24)&0xFF00FF00)| (((c1&0x00FF00)*f13+(c2&0x00FF00)*f23+(c3&0x00FF00)*f14+(c4&0x00FF00)*f24)&0x00FF0000))>>>8; }
|
EDIT: correction missnamed : bilinear/cubic rather than bicubic...