Advertisement
Guest User

ConvertLPCSprites

a guest
May 5th, 2013
174
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.awt.Graphics;
  2. import java.awt.image.BufferedImage;
  3. import java.io.File;
  4.  
  5. import javax.imageio.ImageIO;
  6.  
  7. public class CovertLPCSprites {
  8.     public static int TILE=64, ROW_WIDTH=19, ROW_HEIGHT=4, WEAPON_FRAMES=8, WEAPON_TILE=64;
  9.     public static int copyRow(Graphics g, BufferedImage img, int i, int row, int w, int tile){
  10.         int x = i%ROW_WIDTH, y = i/ROW_WIDTH; if(x+w > ROW_WIDTH){
  11.             int w2 = ROW_WIDTH-x; g.drawImage(img, x*tile, y*tile, (x+w2)*tile, (y+1)*tile, 0, tile*row, w2*tile, tile*(row+1), null);
  12.             y++; x = 0; g.drawImage(img, x*tile, y*tile, (x+(w-w2))*tile, (y+1)*tile, w2*tile, tile*row, w*tile, tile*(row+1), null);
  13.         } else g.drawImage(img, x*tile, y*tile, (x+w)*tile, (y+1)*tile, 0, tile*row, w*tile, tile*(row+1), null);
  14.         return i+w;
  15.     }
  16.     public static int copyRow(Graphics g, BufferedImage img, int i, int row, int w){return copyRow(g,img,i,row,w,TILE);}
  17.     public static BufferedImage convertSheet(BufferedImage img){return convertSheet(img,null);}
  18.     public static BufferedImage convertSheet(BufferedImage img, BufferedImage ret){
  19.         if(ret == null) ret = new BufferedImage(ROW_WIDTH*TILE, ROW_HEIGHT*TILE, BufferedImage.TYPE_INT_ARGB); Graphics g = ret.createGraphics();
  20.         //WALK_UP 9, WALK_LEFT 9, WALK_DOWN 9, WALK_RIGHT 9, SLASH 6, THRUST 8, BOW 13, CAST 7, DEATH 6
  21.         int i=copyRow(g,img,0,8,9); i=copyRow(g,img,i,9,9); i=copyRow(g,img,i,10,9);i=copyRow(g,img,i,11,9); i=copyRow(g,img,i,13,6);
  22.         i=copyRow(g,img,i,5,8); i=copyRow(g,img,i,17,13); i=copyRow(g,img,i,1,7); i=copyRow(g,img,i,20,6); return ret;
  23.     }
  24.     public static BufferedImage convertWeaponSheet(BufferedImage img){
  25.         BufferedImage ret = new BufferedImage(WEAPON_FRAMES*WEAPON_TILE, WEAPON_TILE, BufferedImage.TYPE_INT_ARGB);
  26.         Graphics g = ret.createGraphics(); copyRow(g,img,0,1,WEAPON_FRAMES,WEAPON_TILE); return ret;
  27.     }
  28.     private static String FOLDER = "C:/Games/LPC/Universal Spritesheet/", OUT = "C:/Haxe/MusicRPG2/assets/lib/";
  29.     private static int EYE_WHITE = 0xfff2f8f9;
  30.     public static void getEyeWhites(BufferedImage img){
  31.         for (int y = 0; y < img.getHeight(); ++y){
  32.             for (int x = 0; x < img.getWidth(); ++x){
  33.                 int argb = img.getRGB(x, y); if(argb != EYE_WHITE) img.setRGB(x, y, 0);
  34.             }
  35.         }
  36.     }
  37.     private static class Pos {
  38.         public int x, y; public Pos(int _x, int _y){x = _x; y = _y;}
  39.     }
  40.     private static Pos getStart(BufferedImage img, int x, int y){
  41.         for(int y2=y; y2<y+TILE; y2++){
  42.             for(int x2=x; x2<x+TILE; x2++) if(((img.getRGB(x2, y2)>>24)&0xFF) != 0) return new Pos(x2,y2);
  43.         } return null;
  44.     }
  45.     private static void removeOrcHead(int i, BufferedImage img, BufferedImage ret, BufferedImage head) throws Exception {
  46.         int x = (i%ROW_WIDTH)*TILE, y = (i/ROW_WIDTH)*TILE; Pos p=getStart(img,x,y), p2=getStart(head,0,0);
  47.         if(p == null || p2 == null) return; p.x -= p2.x;
  48.         int ex = p.x+head.getWidth(), ey=p.y+head.getHeight(); //System.out.println(x+" "+y+" "+p.x+" "+p.y+" "+ex+" "+ey);
  49.         for(int y2=p.y; y2<ey; y2++){
  50.             for(int x2=p.x; x2<ex; x2++){
  51.                 int c = head.getRGB(x2-p.x,y2-p.y); if(img.getRGB(x2, y2) == c){
  52.                     img.setRGB(x2, y2, 0); ret.setRGB(x2, y2, c);
  53.                 }
  54.             }
  55.         }
  56.     }
  57.     private static BufferedImage flipH(BufferedImage img) throws Exception {
  58.         int w = img.getWidth(), h = img.getHeight(); BufferedImage ret = new BufferedImage(w, h, img.getType());
  59.         for(int y=0; y<h; y++){
  60.             for(int x=0; x<w; x++){
  61.                 ret.setRGB(w-x-1, y, img.getRGB(x,y));
  62.             }
  63.         } return ret;
  64.     }
  65.     public static BufferedImage removeOrcHead(BufferedImage img) throws Exception {
  66.         BufferedImage ret = new BufferedImage(img.getWidth(), img.getHeight(), img.getType());
  67.         BufferedImage head = ImageIO.read(new File(FOLDER+"head/orc.png"));
  68.         for(int f=9; f<18; f++) removeOrcHead(f,img, ret, head);
  69.         for(int f=36; f<70; f++) removeOrcHead(f,img, ret, head);
  70.         BufferedImage head2 = flipH(head); for(int f=27; f<36; f++) removeOrcHead(f,img, ret, head2);
  71.         return ret;
  72.     }
  73.     public static void convertBody() throws Exception {
  74.         BufferedImage img = ImageIO.read(new File(FOLDER+"body/female/light.png"));
  75.         ImageIO.write(convertSheet(img), "png", new File(OUT+"body_f.png"));
  76.         img = ImageIO.read(new File(FOLDER+"body/male/light.png"));
  77.         ImageIO.write(convertSheet(img), "png", new File(OUT+"body_m.png"));
  78.         img = convertSheet(ImageIO.read(new File(FOLDER+"body/male/orc.png")));
  79.         ImageIO.write(removeOrcHead(img), "png", new File(OUT+"head_o.png"));
  80.         ImageIO.write(img, "png", new File(OUT+"body_o.png"));
  81.         img = ImageIO.read(new File(FOLDER+"body/male/skeleton.png"));
  82.         ImageIO.write(convertSheet(img), "png", new File(OUT+"body_s.png"));
  83.         img = ImageIO.read(new File(FOLDER+"body/female/eyes/blue.png"));
  84.         ImageIO.write(convertSheet(img), "png", new File(OUT+"eyes_f.png"));
  85.         img = ImageIO.read(new File(FOLDER+"body/male/eyes/blue.png"));
  86.         ImageIO.write(convertSheet(img), "png", new File(OUT+"eyes_m.png"));
  87.     }
  88.     public static void convertHairF() throws Exception {
  89.         BufferedImage img = ImageIO.read(new File(FOLDER+"hair/female/bangslong.png"));
  90.         ImageIO.write(convertSheet(img), "png", new File(OUT+"hair0_f.png"));
  91.         img = ImageIO.read(new File(FOLDER+"hair/female/bangsshort.png"));
  92.         ImageIO.write(convertSheet(img), "png", new File(OUT+"hair1_f.png"));
  93.         img = ImageIO.read(new File(FOLDER+"hair/female/unkempt.png"));
  94.         ImageIO.write(convertSheet(img), "png", new File(OUT+"hair2_f.png"));
  95.         img = ImageIO.read(new File(FOLDER+"hair/female/pixie.png"));
  96.         ImageIO.write(convertSheet(img), "png", new File(OUT+"hair3_f.png"));
  97.         img = ImageIO.read(new File(FOLDER+"hair/female/ponytail.png"));
  98.         ImageIO.write(convertSheet(img), "png", new File(OUT+"hair4_f.png"));
  99.         img = ImageIO.read(new File(FOLDER+"hair/female/princess.png"));
  100.         ImageIO.write(convertSheet(img), "png", new File(OUT+"hair5_f.png"));
  101.         img = ImageIO.read(new File(FOLDER+"hair/female/swoop.png"));
  102.         ImageIO.write(convertSheet(img), "png", new File(OUT+"hair6_f.png"));
  103.         img = ImageIO.read(new File(FOLDER+"hair/female/loose.png"));
  104.         ImageIO.write(convertSheet(img), "png", new File(OUT+"hair7_f.png"));
  105.     }
  106.     public static void convertHairM() throws Exception {
  107.         BufferedImage img = ImageIO.read(new File(FOLDER+"hair/male/bangs.png"));
  108.         ImageIO.write(convertSheet(img), "png", new File(OUT+"hair0_m.png"));
  109.         img = ImageIO.read(new File(FOLDER+"hair/male/bedhead.png"));
  110.         ImageIO.write(convertSheet(img), "png", new File(OUT+"hair1_m.png"));
  111.         img = ImageIO.read(new File(FOLDER+"hair/male/long.png"));
  112.         ImageIO.write(convertSheet(img), "png", new File(OUT+"hair2_m.png"));
  113.         img = ImageIO.read(new File(FOLDER+"hair/male/messy1.png"));
  114.         ImageIO.write(convertSheet(img), "png", new File(OUT+"hair3_m.png"));
  115.         img = ImageIO.read(new File(FOLDER+"hair/male/messy2.png"));
  116.         ImageIO.write(convertSheet(img), "png", new File(OUT+"hair4_m.png"));
  117.         img = ImageIO.read(new File(FOLDER+"hair/male/mohawk.png"));
  118.         ImageIO.write(convertSheet(img), "png", new File(OUT+"hair5_m.png"));
  119.         img = ImageIO.read(new File(FOLDER+"hair/male/page.png"));
  120.         ImageIO.write(convertSheet(img), "png", new File(OUT+"hair6_m.png"));
  121.         img = ImageIO.read(new File(FOLDER+"hair/male/parted.png"));
  122.         ImageIO.write(convertSheet(img), "png", new File(OUT+"hair7_m.png"));
  123.     }
  124.     public static void convertCharacter() throws Exception {
  125.         convertBody();
  126.         convertHairF();
  127.         convertHairM();
  128.     }
  129.     public static void convertHelms() throws Exception {
  130.         BufferedImage img = ImageIO.read(new File(FOLDER+"head/leather_cap_female.png"));
  131.         ImageIO.write(convertSheet(img), "png", new File(OUT+"equipment/cap_f.png"));
  132.         img = ImageIO.read(new File(FOLDER+"head/leather_cap_male.png"));
  133.         ImageIO.write(convertSheet(img), "png", new File(OUT+"equipment/cap_m.png"));
  134.         img = ImageIO.read(new File(FOLDER+"head/cloth_hood_female.png"));
  135.         ImageIO.write(convertSheet(img), "png", new File(OUT+"equipment/clothhood_f.png"));
  136.         img = ImageIO.read(new File(FOLDER+"head/cloth_hood_male.png"));
  137.         ImageIO.write(convertSheet(img), "png", new File(OUT+"equipment/clothhood_m.png"));
  138.         img = ImageIO.read(new File(FOLDER+"head/chainhat_female.png"));
  139.         ImageIO.write(convertSheet(img), "png", new File(OUT+"equipment/skullcap_f.png"));
  140.         img = ImageIO.read(new File(FOLDER+"head/chainhat_male.png"));
  141.         ImageIO.write(convertSheet(img), "png", new File(OUT+"equipment/skullcap_m.png"));
  142.         img = ImageIO.read(new File(FOLDER+"head/chain_hood_female.png"));
  143.         ImageIO.write(convertSheet(img), "png", new File(OUT+"equipment/chainhood_f.png"));
  144.         img = ImageIO.read(new File(FOLDER+"head/chain_hood_male.png"));
  145.         ImageIO.write(convertSheet(img), "png", new File(OUT+"equipment/chainhood_m.png"));
  146.         img = ImageIO.read(new File(FOLDER+"head/metal_helm_female.png"));
  147.         ImageIO.write(convertSheet(img), "png", new File(OUT+"equipment/helm_f.png"));
  148.         img = ImageIO.read(new File(FOLDER+"head/metal_helm_male.png"));
  149.         ImageIO.write(convertSheet(img), "png", new File(OUT+"equipment/helm_m.png"));
  150.         img = ImageIO.read(new File(FOLDER+"head/golden_helm_female.png"));
  151.         ImageIO.write(convertSheet(img), "png", new File(OUT+"equipment/goldhelm_f.png"));
  152.         img = ImageIO.read(new File(FOLDER+"head/golden_helm_male.png"));
  153.         ImageIO.write(convertSheet(img), "png", new File(OUT+"equipment/goldhelm_m.png"));
  154.     }
  155.     public static void convertShirts() throws Exception {
  156.         BufferedImage img = ImageIO.read(new File(FOLDER+"torso/white_shirt_female.png"));
  157.         ImageIO.write(convertSheet(img), "png", new File(OUT+"equipment/shirt_f.png"));
  158.         img = ImageIO.read(new File(FOLDER+"torso/white_shirt_male.png"));
  159.         ImageIO.write(convertSheet(img), "png", new File(OUT+"equipment/shirt_m.png"));
  160.         img = ImageIO.read(new File(FOLDER+"torso/leather/chest_female.png"));
  161.         BufferedImage img2 = ImageIO.read(new File(FOLDER+"torso/leather/shoulders_female.png"));
  162.         BufferedImage img3 = ImageIO.read(new File(FOLDER+"torso/leather/bracers_female.png"));
  163.         ImageIO.write(convertSheet(img3, convertSheet(img2, convertSheet(img))), "png", new File(OUT+"equipment/leather_f.png"));
  164.         img = ImageIO.read(new File(FOLDER+"torso/leather/chest_male.png"));
  165.         img2 = ImageIO.read(new File(FOLDER+"torso/leather/shoulders_male.png"));
  166.         img3 = ImageIO.read(new File(FOLDER+"torso/leather/bracers_male.png"));
  167.         ImageIO.write(convertSheet(img3, convertSheet(img2, convertSheet(img))), "png", new File(OUT+"equipment/leather_m.png"));
  168.         img = ImageIO.read(new File(FOLDER+"torso/chain/mail_female.png"));
  169.         img2 = ImageIO.read(new File(FOLDER+"belt/leather_female.png"));
  170.         ImageIO.write(convertSheet(img2, convertSheet(img)), "png", new File(OUT+"equipment/chain_f.png"));
  171.         img = ImageIO.read(new File(FOLDER+"torso/chain/mail_male.png"));
  172.         img2 = ImageIO.read(new File(FOLDER+"belt/leather_male.png"));
  173.         ImageIO.write(convertSheet(img2, convertSheet(img)), "png", new File(OUT+"equipment/chain_m.png"));
  174.         img = ImageIO.read(new File(FOLDER+"torso/plate/chest_female.png"));
  175.         img2 = ImageIO.read(new File(FOLDER+"torso/plate/arms_female.png"));
  176.         img3 = ImageIO.read(new File(FOLDER+"hands/metal_gloves_female.png"));
  177.         ImageIO.write(convertSheet(img3, convertSheet(img2, convertSheet(img))), "png", new File(OUT+"equipment/plate_f.png"));
  178.         img = ImageIO.read(new File(FOLDER+"torso/plate/chest_male.png"));
  179.         img2 = ImageIO.read(new File(FOLDER+"torso/plate/arms_male.png"));
  180.         img3 = ImageIO.read(new File(FOLDER+"hands/metal_gloves_male.png"));
  181.         ImageIO.write(convertSheet(img3, convertSheet(img2, convertSheet(img))), "png", new File(OUT+"equipment/plate_m.png"));
  182.         img = ImageIO.read(new File(FOLDER+"torso/gold/chest_female.png"));
  183.         img2 = ImageIO.read(new File(FOLDER+"torso/gold/arms_female.png"));
  184.         img3 = ImageIO.read(new File(FOLDER+"hands/golden_gloves_female.png"));
  185.         ImageIO.write(convertSheet(img3, convertSheet(img2, convertSheet(img))), "png", new File(OUT+"equipment/gold_f.png"));
  186.         img = ImageIO.read(new File(FOLDER+"torso/gold/chest_male.png"));
  187.         img2 = ImageIO.read(new File(FOLDER+"torso/gold/arms_male.png"));
  188.         img3 = ImageIO.read(new File(FOLDER+"hands/golden_gloves_male.png"));
  189.         ImageIO.write(convertSheet(img3, convertSheet(img2, convertSheet(img))), "png", new File(OUT+"equipment/gold_m.png"));
  190.         img = ImageIO.read(new File(FOLDER+"torso/brown_shirt_male.png"));
  191.         img2 = ImageIO.read(new File(FOLDER+"belt/rope_male.png"));
  192.         ImageIO.write(convertSheet(img2, convertSheet(img)), "png", new File(OUT+"equipment/robes_m.png"));
  193.     }
  194.     public static void convertPants() throws Exception {
  195.         BufferedImage img = ImageIO.read(new File(FOLDER+"legs/green_pants_female.png"));
  196.         ImageIO.write(convertSheet(img), "png", new File(OUT+"equipment/pants_f.png"));
  197.         BufferedImage img2 = ImageIO.read(new File(FOLDER+"feet/brown_shoes_female.png"));
  198.         ImageIO.write(convertSheet(img2, convertSheet(img)), "png", new File(OUT+"equipment/boots_f.png"));
  199.         img2 = ImageIO.read(new File(FOLDER+"feet/black_shoes_female.png"));
  200.         ImageIO.write(convertSheet(img2, convertSheet(img)), "png", new File(OUT+"equipment/metalboots_f.png"));
  201.         img = ImageIO.read(new File(FOLDER+"legs/green_pants_male.png"));
  202.         ImageIO.write(convertSheet(img), "png", new File(OUT+"equipment/pants_m.png"));
  203.         img2 = ImageIO.read(new File(FOLDER+"feet/brown_shoes_male.png"));
  204.         ImageIO.write(convertSheet(img2, convertSheet(img)), "png", new File(OUT+"equipment/boots_m.png"));
  205.         img2 = ImageIO.read(new File(FOLDER+"feet/black_shoes_male.png"));
  206.         ImageIO.write(convertSheet(img2, convertSheet(img)), "png", new File(OUT+"equipment/metalboots_m.png"));
  207.         img = ImageIO.read(new File(FOLDER+"legs/metal_pants_female.png"));
  208.         img2 = ImageIO.read(new File(FOLDER+"feet/metal_boots_female.png"));
  209.         ImageIO.write(convertSheet(img2, convertSheet(img)), "png", new File(OUT+"equipment/greaves_f.png"));
  210.         img = ImageIO.read(new File(FOLDER+"legs/metal_pants_male.png"));
  211.         img2 = ImageIO.read(new File(FOLDER+"feet/metal_boots_male.png"));
  212.         ImageIO.write(convertSheet(img2, convertSheet(img)), "png", new File(OUT+"equipment/greaves_m.png"));
  213.         img = ImageIO.read(new File(FOLDER+"legs/golden_greaves_female.png"));
  214.         img2 = ImageIO.read(new File(FOLDER+"feet/golden_boots_female.png"));
  215.         ImageIO.write(convertSheet(img2, convertSheet(img)), "png", new File(OUT+"equipment/goldgreaves_f.png"));
  216.         img = ImageIO.read(new File(FOLDER+"legs/golden_greaves_male.png"));
  217.         img2 = ImageIO.read(new File(FOLDER+"feet/golden_boots_male.png"));
  218.         ImageIO.write(convertSheet(img2, convertSheet(img)), "png", new File(OUT+"equipment/goldgreaves_m.png"));
  219.         img = ImageIO.read(new File(FOLDER+"legs/robe_skirt_male.png"));
  220.         ImageIO.write(convertSheet(img), "png", new File(OUT+"equipment/robeskirt_m.png"));
  221.     }
  222.     public static void convertEquipment() throws Exception {
  223.         convertHelms();
  224.         convertShirts();
  225.         convertPants();
  226.     }
  227.     public static void main(String[] args) {
  228.         try{
  229.             convertCharacter();
  230.             convertEquipment();
  231.             //BufferedImage img = ImageIO.read(new File("C:/Games/lpc_entry/head/cloth_hood_male.png"));
  232.             //JFrame f = new JFrame(); f.setContentPane(new JScrollPane(new JLabel(new ImageIcon(convertSheet(img)))));
  233.             //f.setSize(new Dimension(800,600)); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setVisible(true);
  234.             //ImageIO.write(convertSheet(img), "png", new File("C:/Haxe/MusicRPG2/assets/lib/equipment/clothhood_m2.png"));
  235.             //ImageIO.write(convertWeaponSheet(img), "png", new File("C:/Haxe/MusicRPG/lib/equipment/staff.png"));
  236.         }catch(Exception e){e.printStackTrace();}
  237.     }
  238.  
  239. }
Advertisement
RAW Paste Data Copied
Advertisement