Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Image img;
- private int getBilinearColor(double x, double y)
- {
- int x1 = (int)Math.floor(x);
- int x2 = (int)Math.ceil(x);
- x1 = x1 < 0 ? 0 : x1;
- x1 = x1 >= image.getWidth() ? image.getWidth()-1 : x1;
- x2 = x2 < 0 ? 0 : x1;
- x2 = x2 >= image.getWidth() ? x1 : x2;
- double a = x-x1;
- int y1 = (int)Math.floor(y);
- int y2 = (int)Math.ceil(y);
- y1 = y1 < 0 ? 0 : y1;
- y1 = y1 >= image.getHeight() ? image.getHeight() - 1 : y1;
- y2 = y2 < 0 ? 0 : y2;
- y2 = y2 >= image.getHeight() ? y1 : y2;
- int[] c1 = Utils.RGB2int(image.getRGB(x1, y1));
- int[] c2 = Utils.RGB2int(image.getRGB(x2, y1));
- int kA = Utils.int2RGB((int)((1-a)*c1[0] + a*c2[0]), (int)((1-a)*c1[1] + a*c2[1]), (int)((1-a)*c1[2] + a*c2[2]));
- c1 = Utils.RGB2int(image.getRGB(x1, y1));
- c2 = Utils.RGB2int(image.getRGB(x1, y2));
- int kB = Utils.int2RGB((int)((1-a)*c1[0] + a*c2[0]), (int)((1-a)*c1[1] + a*c2[1]), (int)((1-a)*c1[2] + a*c2[2]));
- double b = y-y1;
- c1 = Utils.RGB2int(kA);
- c2 = Utils.RGB2int(kB);
- int kC = Utils.int2RGB((int)((1-b)*c1[0] + b*c2[0]), (int)((1-b)*c1[1] + b*c2[1]), (int)((1-b)*c1[2] + b*c2[2]));
- return kC;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement