Advertisement
Guest User

Remove Orc Head

a guest
May 5th, 2013
376
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.67 KB | None | 0 0
  1.     private static class Pos {
  2.         public int x, y; public Pos(int _x, int _y){x = _x; y = _y;}
  3.     }
  4.     private static Pos getStart(BufferedImage img, int x, int y){
  5.         for(int y2=y; y2<y+TILE; y2++){
  6.             for(int x2=x; x2<x+TILE; x2++) if(((img.getRGB(x2, y2)>>24)&0xFF) != 0) return new Pos(x2,y2);
  7.         } return null;
  8.     }
  9.     private static void removeOrcHead(int i, BufferedImage img, BufferedImage ret, BufferedImage head) throws Exception {
  10.         int x = (i%ROW_WIDTH)*TILE, y = (i/ROW_WIDTH)*TILE; Pos p=getStart(img,x,y), p2=getStart(head,0,0);
  11.         if(p == null || p2 == null) return; p.x -= p2.x;
  12.         int ex = p.x+head.getWidth(), ey=p.y+head.getHeight(); //System.out.println(x+" "+y+" "+p.x+" "+p.y+" "+ex+" "+ey);
  13.         for(int y2=p.y; y2<ey; y2++){
  14.             for(int x2=p.x; x2<ex; x2++){
  15.                 int c = head.getRGB(x2-p.x,y2-p.y); if(img.getRGB(x2, y2) == c){
  16.                     img.setRGB(x2, y2, 0); ret.setRGB(x2, y2, c);
  17.                 }
  18.             }
  19.         }
  20.     }
  21.     private static BufferedImage flipH(BufferedImage img) throws Exception {
  22.         int w = img.getWidth(), h = img.getHeight(); BufferedImage ret = new BufferedImage(w, h, img.getType());
  23.         for(int y=0; y<h; y++){
  24.             for(int x=0; x<w; x++){
  25.                 ret.setRGB(w-x-1, y, img.getRGB(x,y));
  26.             }
  27.         } return ret;
  28.     }
  29.     public static BufferedImage removeOrcHead(BufferedImage img) throws Exception {
  30.         BufferedImage ret = new BufferedImage(img.getWidth(), img.getHeight(), img.getType());
  31.         BufferedImage head = ImageIO.read(new File(FOLDER+"head/orc.png"));
  32.         for(int f=9; f<18; f++) removeOrcHead(f,img, ret, head);
  33.         for(int f=36; f<70; f++) removeOrcHead(f,img, ret, head);
  34.         BufferedImage head2 = flipH(head); for(int f=27; f<36; f++) removeOrcHead(f,img, ret, head2);
  35.         return ret;
  36.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement