public static int bilinearInterpolate ( float x , float y , int nw , int ne , int sw , int se ) { float m0 , m1 ; int a0 = ( nw >> 24 ) & 0xff ; int r0 = ( nw >> 16 ) & 0xff ; int g0 = ( nw >> 8 ) & 0xff ; int b0 = nw & 0xff ; int a1 = ( ne >> 24 ) & 0xff ; int r1 = ( ne >> 16 ) & 0xff ; int g1 = ( ne >> 8 ) & 0xff ; int b1 = ne & 0xff ; int a2 = ( sw >> 24 ) & 0xff ; int r2 = ( sw >> 16 ) & 0xff ; int g2 = ( sw >> 8 ) & 0xff ; int b2 = sw & 0xff ; int a3 = ( se >> 24 ) & 0xff ; int r3 = ( se >> 16 ) & 0xff ; int g3 = ( se >> 8 ) & 0xff ; int b3 = se & 0xff ; float cx = 1.0f - x ; float cy = 1.0f - y ; m0 = cx * a0 + x * a1 ; m1 = cx * a2 + x * a3 ; int a = ( int ) ( cy * m0 + y * m1 ) ; m0 = cx * r0 + x * r1 ; m1 = cx * r2 + x * r3 ; int r = ( int ) ( cy * m0 + y * m1 ) ; m0 = cx * g0 + x * g1 ; m1 = cx * g2 + x * g3 ; int g = ( int ) ( cy * m0 + y * m1 ) ; m0 = cx * b0 + x * b1 ; m1 = cx * b2 + x * b3 ; int b = ( int ) ( cy * m0 + y * m1 ) ; return ( a << 24 ) | ( r << 16 ) | ( g << 8 ) | b ; }
Bilinear interpolation of ARGB values .