Skip to content

Instantly share code, notes, and snippets.

@mrkn
Created July 6, 2009 06:52
Show Gist options
  • Save mrkn/141296 to your computer and use it in GitHub Desktop.
Save mrkn/141296 to your computer and use it in GitHub Desktop.
public int getPixelBilinear(double x, double y)
{
// 座標値を画像の中に収める
if (x < 0) x = 0.0;
if (x >= this.getWidth()) x = this.getWidth() - 1.0;
if (y < 0) y = 0.0;
if (y >= this.getHeight()) y = this.getHeight() - 1.0;
int x1 = (int)x; // x - x1 == p
int y1 = (int)y; // y - y1 == q
double p = x - (int)x;
double q = y - (int)y;
int fx1 = getPixel(x1, y1);
int fx2 = getPixel(x1 + 1, y1);
int fx = bilinearColorInterpolate(fx1, fx2, p);
int fy1 = fx1;
int fy2 = getPixel(x1, y1 + 1);
int fx = bilinearColorInterpolate(fy1, fy2, q);
return bilinearColorInterpolate(fx, fy, 0.5);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment