Advertisement
Guest User

Untitled

a guest
Oct 20th, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. Image img;
  2.  
  3. private int getBilinearColor(double x, double y)
  4. {
  5. int x1 = (int)Math.floor(x);
  6. int x2 = (int)Math.ceil(x);
  7. x1 = x1 < 0 ? 0 : x1;
  8. x1 = x1 >= image.getWidth() ? image.getWidth()-1 : x1;
  9. x2 = x2 < 0 ? 0 : x1;
  10. x2 = x2 >= image.getWidth() ? x1 : x2;
  11. double a = x-x1;
  12.  
  13. int y1 = (int)Math.floor(y);
  14. int y2 = (int)Math.ceil(y);
  15.  
  16. y1 = y1 < 0 ? 0 : y1;
  17. y1 = y1 >= image.getHeight() ? image.getHeight() - 1 : y1;
  18. y2 = y2 < 0 ? 0 : y2;
  19. y2 = y2 >= image.getHeight() ? y1 : y2;
  20.  
  21. int[] c1 = Utils.RGB2int(image.getRGB(x1, y1));
  22. int[] c2 = Utils.RGB2int(image.getRGB(x2, y1));
  23. 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]));
  24.  
  25. c1 = Utils.RGB2int(image.getRGB(x1, y1));
  26. c2 = Utils.RGB2int(image.getRGB(x1, y2));
  27. 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]));
  28.  
  29. double b = y-y1;
  30.  
  31. c1 = Utils.RGB2int(kA);
  32. c2 = Utils.RGB2int(kB);
  33. 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]));
  34.  
  35. return kC;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement