Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private static class Pos {
- public int x, y; public Pos(int _x, int _y){x = _x; y = _y;}
- }
- private static Pos getStart(BufferedImage img, int x, int y){
- for(int y2=y; y2<y+TILE; y2++){
- for(int x2=x; x2<x+TILE; x2++) if(((img.getRGB(x2, y2)>>24)&0xFF) != 0) return new Pos(x2,y2);
- } return null;
- }
- private static void removeOrcHead(int i, BufferedImage img, BufferedImage ret, BufferedImage head) throws Exception {
- int x = (i%ROW_WIDTH)*TILE, y = (i/ROW_WIDTH)*TILE; Pos p=getStart(img,x,y), p2=getStart(head,0,0);
- if(p == null || p2 == null) return; p.x -= p2.x;
- int ex = p.x+head.getWidth(), ey=p.y+head.getHeight(); //System.out.println(x+" "+y+" "+p.x+" "+p.y+" "+ex+" "+ey);
- for(int y2=p.y; y2<ey; y2++){
- for(int x2=p.x; x2<ex; x2++){
- int c = head.getRGB(x2-p.x,y2-p.y); if(img.getRGB(x2, y2) == c){
- img.setRGB(x2, y2, 0); ret.setRGB(x2, y2, c);
- }
- }
- }
- }
- private static BufferedImage flipH(BufferedImage img) throws Exception {
- int w = img.getWidth(), h = img.getHeight(); BufferedImage ret = new BufferedImage(w, h, img.getType());
- for(int y=0; y<h; y++){
- for(int x=0; x<w; x++){
- ret.setRGB(w-x-1, y, img.getRGB(x,y));
- }
- } return ret;
- }
- public static BufferedImage removeOrcHead(BufferedImage img) throws Exception {
- BufferedImage ret = new BufferedImage(img.getWidth(), img.getHeight(), img.getType());
- BufferedImage head = ImageIO.read(new File(FOLDER+"head/orc.png"));
- for(int f=9; f<18; f++) removeOrcHead(f,img, ret, head);
- for(int f=36; f<70; f++) removeOrcHead(f,img, ret, head);
- BufferedImage head2 = flipH(head); for(int f=27; f<36; f++) removeOrcHead(f,img, ret, head2);
- return ret;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement