Program: 26233
Project: 26233
Buggy source:
/** 
 * fromCurrent=true  --> The interpolation is prepared to be done from the current image in the pyramid. fromCurrent=false --> The interpolation is prepared to be done from the original image.
 * @param x x- point coordinate
 * @param y y- point coordinate
 * @param fromCurrent flag to determine the image to do the interpolation from
 */
public void prepareForInterpolation(double x,double y,boolean fromCurrent){
  this.x=x;
  this.y=y;
  this.fromCurrent=fromCurrent;
  if (fromCurrent) {
    widthToUse=currentWidth;
    heightToUse=currentHeight;
  }
 else {
    widthToUse=width;
    heightToUse=height;
  }
  int ix=(int)x;
  int iy=(int)y;
  int twiceWidthToUse=2 * widthToUse;
  int twiceHeightToUse=2 * heightToUse;
  int p=(0.0 <= x) ? (ix + 2) : (ix + 1);
  for (int k=0; k < 4; p--, k++) {
    if (coefficientsAreMirrored) {
      int q=(p < 0) ? (-1 - p) : (p);
      if (twiceWidthToUse <= q)       q-=twiceWidthToUse * (q / twiceWidthToUse);
      xIndex[k]=(widthToUse <= q) ? (twiceWidthToUse - 1 - q) : (q);
    }
 else     xIndex[k]=(p < 0 || p >= widthToUse) ? (-1) : (p);
  }
  p=(0.0 <= y) ? (iy + 2) : (iy + 1);
  for (int k=0; k < 4; p--, k++) {
    if (coefficientsAreMirrored) {
      int q=(p < 0) ? (-1 - p) : (p);
      if (twiceHeightToUse <= q)       q-=twiceHeightToUse * (q / twiceHeightToUse);
      yIndex[k]=(heightToUse <= q) ? (twiceHeightToUse - 1 - q) : (q);
    }
 else     yIndex[k]=(p < 0 || p >= heightToUse) ? (-1) : (p);
  }
  double ex=x - ((0.0 <= x) ? (ix) : (ix - 1));
  double ey=y - ((0.0 <= y) ? (iy) : (iy - 1));
  double s=1.0F - ex;
  dxWeight[0]=0.5F * ex * ex;
  xWeight[0]=ex * dxWeight[0] / 3.0F;
  dxWeight[3]=-0.5F * s * s;
  xWeight[3]=s * dxWeight[3] / -3.0F;
  dxWeight[1]=1.0F - 2.0F * dxWeight[0] + dxWeight[3];
  xWeight[1]=MathTools.Bspline03(x - ix - 1);
  dxWeight[2]=1.5F * ex * (ex - 4.0F / 3.0F);
  xWeight[2]=2.0F / 3.0F - (2.0F - ex) * dxWeight[0];
  d2xWeight[0]=ex;
  d2xWeight[1]=s - 2 * ex;
  d2xWeight[2]=ex - 2 * s;
  d2xWeight[3]=s;
  double t=1.0F - ey;
  dyWeight[0]=0.5F * ey * ey;
  yWeight[0]=ey * dyWeight[0] / 3.0F;
  dyWeight[3]=-0.5F * t * t;
  yWeight[3]=t * dyWeight[3] / -3.0F;
  dyWeight[1]=1.0F - 2.0F * dyWeight[0] + dyWeight[3];
  yWeight[1]=2.0F / 3.0F + (1.0F + ey) * dyWeight[3];
  dyWeight[2]=1.5F * ey * (ey - 4.0F / 3.0F);
  yWeight[2]=2.0F / 3.0F - (2.0F - ey) * dyWeight[0];
  d2yWeight[0]=ey;
  d2yWeight[1]=t - 2 * ey;
  d2yWeight[2]=ey - 2 * t;
  d2yWeight[3]=t;
}

Fixed version (ground truth):
/** 
 * fromCurrent=true  --> The interpolation is prepared to be done from the current image in the pyramid. fromCurrent=false --> The interpolation is prepared to be done from the original image.
 * @param x x- point coordinate
 * @param y y- point coordinate
 * @param fromCurrent flag to determine the image to do the interpolation from
 */
public void prepareForInterpolation(double x,double y,boolean fromCurrent){
  this.fromCurrent=fromCurrent;
  if (fromCurrent) {
    widthToUse=currentWidth;
    heightToUse=currentHeight;
  }
 else {
    widthToUse=width;
    heightToUse=height;
  }
  int ix=(int)x;
  int iy=(int)y;
  int twiceWidthToUse=2 * widthToUse;
  int twiceHeightToUse=2 * heightToUse;
  int p=(0.0 <= x) ? (ix + 2) : (ix + 1);
  for (int k=0; k < 4; p--, k++) {
    if (coefficientsAreMirrored) {
      int q=(p < 0) ? (-1 - p) : (p);
      if (twiceWidthToUse <= q)       q-=twiceWidthToUse * (q / twiceWidthToUse);
      xIndex[k]=(widthToUse <= q) ? (twiceWidthToUse - 1 - q) : (q);
    }
 else     xIndex[k]=(p < 0 || p >= widthToUse) ? (-1) : (p);
  }
  p=(0.0 <= y) ? (iy + 2) : (iy + 1);
  for (int k=0; k < 4; p--, k++) {
    if (coefficientsAreMirrored) {
      int q=(p < 0) ? (-1 - p) : (p);
      if (twiceHeightToUse <= q)       q-=twiceHeightToUse * (q / twiceHeightToUse);
      yIndex[k]=(heightToUse <= q) ? (twiceHeightToUse - 1 - q) : (q);
    }
 else     yIndex[k]=(p < 0 || p >= heightToUse) ? (-1) : (p);
  }
  double ex=x - ((0.0 <= x) ? (ix) : (ix - 1));
  double ey=y - ((0.0 <= y) ? (iy) : (iy - 1));
  double s=1.0F - ex;
  dxWeight[0]=0.5F * ex * ex;
  xWeight[0]=ex * dxWeight[0] / 3.0F;
  dxWeight[3]=-0.5F * s * s;
  xWeight[3]=s * dxWeight[3] / -3.0F;
  dxWeight[1]=1.0F - 2.0F * dxWeight[0] + dxWeight[3];
  xWeight[1]=MathTools.Bspline03(x - ix - 1);
  dxWeight[2]=1.5F * ex * (ex - 4.0F / 3.0F);
  xWeight[2]=2.0F / 3.0F - (2.0F - ex) * dxWeight[0];
  d2xWeight[0]=ex;
  d2xWeight[1]=s - 2 * ex;
  d2xWeight[2]=ex - 2 * s;
  d2xWeight[3]=s;
  double t=1.0F - ey;
  dyWeight[0]=0.5F * ey * ey;
  yWeight[0]=ey * dyWeight[0] / 3.0F;
  dyWeight[3]=-0.5F * t * t;
  yWeight[3]=t * dyWeight[3] / -3.0F;
  dyWeight[1]=1.0F - 2.0F * dyWeight[0] + dyWeight[3];
  yWeight[1]=2.0F / 3.0F + (1.0F + ey) * dyWeight[3];
  dyWeight[2]=1.5F * ey * (ey - 4.0F / 3.0F);
  yWeight[2]=2.0F / 3.0F - (2.0F - ey) * dyWeight[0];
  d2yWeight[0]=ey;
  d2yWeight[1]=t - 2 * ey;
  d2yWeight[2]=ey - 2 * t;
  d2yWeight[3]=t;
}