Create a png converter that attempts to index png images. Just in case

Co-authored-by: r3cp3ct <45179536+r3cp3ct@users.noreply.github.com>
Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
main
Nic0Nic0Nii 3 years ago
parent b22098febf
commit ea5684fc60
  1. BIN
      sprites/maptileinfo-1.png.png
  2. 8
      src/sig/RabiClone.java
  3. 39
      src/sig/engine/Sprite.java

Binary file not shown.

After

Width:  |  Height:  |  Size: 426 B

@ -35,11 +35,11 @@ public class RabiClone{
public static Maps CURRENT_MAP = Maps.WORLD1;
public static void main(String[] args) {
f = new JFrame(PROGRAM_NAME);
/*f = new JFrame(PROGRAM_NAME);
f.setResizable(false);
f.setUndecorated(true);
f.setSize(BASE_WIDTH,BASE_HEIGHT); //1024x576 (64x64)
ChooseBestRatio();
ChooseBestRatio();*/
p = new Panel(f);
@ -47,11 +47,11 @@ public class RabiClone{
p.init();
f.add(p);
/*f.add(p);
f.addKeyListener(p);
f.setLocation((int)((Toolkit.getDefaultToolkit().getScreenSize().getWidth()-f.getWidth())/2), (int)((Toolkit.getDefaultToolkit().getScreenSize().getHeight()-f.getHeight())/2));
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
f.setVisible(true);*/
OBJ.add(level_renderer = new LevelRenderer(p));
OBJ.add(player = new Player(p));

@ -13,7 +13,7 @@ public enum Sprite{
NANA(new File(new File("..","sprites"),"3x.png")),
NANA_SMALL(new File(new File("..","sprites"),"1x.gif")),
TILE_SHEET(new File(new File("..","sprites"),"tiles.gif")),
MAP_TILE_INFO(new File(new File("..","sprites"),"maptileinfo.gif")),
MAP_TILE_INFO(new File(new File("..","sprites"),"maptileinfo-1.png.png")),
;
@ -28,7 +28,42 @@ public enum Sprite{
BufferedImage img = ImageIO.read(filename);
this.width=img.getWidth();
this.height=img.getHeight();
bi_array = ((DataBufferByte)(img.getRaster().getDataBuffer())).getData();
if (filename.getName().endsWith(".png")) {
System.out.println(" WARNING! PNGs are not officially supported! Will attempt to convert anyways.");
bi_array=new byte[width*height];
for (int y=0;y<height;y++) {
for (int x=0;x<width;x++) {
int col = img.getRGB(x, y);
int r = (col&0xff0000)>>>16;
int g = (col&0xff00)>>>8;
int b = col&0xff;
boolean found=false;
for (int c=0;c<Panel.generalPalette.length;c+=3) {
if (Panel.generalPalette[c]==(byte)r&&
Panel.generalPalette[c+1]==(byte)g&&
Panel.generalPalette[c+2]==(byte)b) {
System.out.println(" Matched color index["+((byte)(c/3))+"]");
bi_array[y*width+x]=(byte)(c/3);
found=true;
break;
}
if ((byte)0xff==(byte)r&&(byte)0x0==(byte)g&&(byte)0xff==(byte)b) {
System.out.println(" Matched color index[32]");
bi_array[y*width+x]=32;
found=true;
break;
}
}
if (!found) {
System.out.println(" COLOR NOT FOUND! USING TRANSPARENCY BY DEFAULT. ("+r+","+g+","+b+")");
bi_array[y*width+x]=32;
}
}
}
} else {
bi_array = ((DataBufferByte)(img.getRaster().getDataBuffer())).getData();
}
if (this.ordinal()==3) {
System.out.println(Arrays.toString(bi_array));
}

Loading…
Cancel
Save