/*******************************************
*
* bilinear_interpolate(..
*
* This routine performs bi-linear
* interpolation.
*
* If x or y is out of range, i.e. less
* than zero or greater than ROWS or COLS,
* this routine returns a zero.
*
* If x and y are both in range, this
* routine interpolates in the horizontal
* and vertical directions and returns
* the proper gray level.
*
*******************************************/
bilinear_interpolate(the_image, x, y)
double x, y;
short the_image[ROWS][COLS];
{
double fraction_x, fraction_y,
one_minus_x, one_minus_y,
tmp_double;
int ceil_x, ceil_y, floor_x, floor_y;
short p1, p2, p3, result = FILL;
/******************************
*
* If x or y is out of range,
* return a FILL.
*
******************************/
if(x < 0.0 ||
x >= (double)(COLS) ||
y < 0.0 ||
y >= (double)(ROWS))
return(result);
tmp_double = floor(x);
floor_x = tmp_double;
tmp_double = floor(y);
floor_y = tmp_double;
tmp_double = ceil(x);
ceil_x = tmp_double;
tmp_double = ceil(y);
ceil_y = tmp_double;
fraction_x = x - floor(x);
fraction_y = y - floor(y);
one_minus_x = 1.0 - fraction_x;
one_minus_y = 1.0 - fraction_y;
tmp_double = one_minus_x *
(double)(the_image[floor_y][floor_x]) +
fraction_x *
(double)(the_image[floor_y][ceil_x]);
p1 = tmp_double;
tmp_double = one_minus_x *
(double)(the_image[ceil_y][floor_x]) +
fraction_x *
(double)(the_image[ceil_y][ceil_x]);
p2 = tmp_double;
tmp_double = one_minus_y * (double)(p1) +
fraction_y * (double)(p2);
p3 = tmp_double;
return(p3);
} /* ends bilinear_interpolate */
/* End of File */