Created
June 6, 2018 03:10
-
-
Save hikilaka/5e088d70977f8c7413c713eaf409c071 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void dump_sprite_image(int sprite_id, String name, int count) { | |
try { | |
for (int i = 0; i < count; i++) { | |
int id = sprite_id + i; | |
Path path = Paths.get("sprite_dump", name + "-" + i + ".png"); | |
if (!Files.exists(path.getParent())) { | |
Files.createDirectories(path.getParent()); | |
} | |
BufferedImage image = new BufferedImage(screen.sprite_width[id] + screen.sprite_trans_x[id], | |
screen.sprite_height[id] + screen.sprite_trans_y[id], | |
BufferedImage.TYPE_INT_ARGB); | |
for (int y = screen.sprite_trans_y[id]; y < image.getHeight(); y++) { | |
for (int x = screen.sprite_trans_x[id]; x < image.getWidth(); x++) { | |
int dx = x - screen.sprite_trans_x[id]; | |
int dy = y - screen.sprite_trans_y[id]; | |
int color = Surface.MAGENTA; | |
if (screen.sprite_pixels[id] == null) { | |
color = screen.sprite_palette[id][screen.sprite_raster[id][dx + (dy * screen.sprite_width[id])]]; | |
} else { | |
color = screen.sprite_pixels[id][dx + (dy * screen.sprite_width[id])]; | |
} | |
// convert color from RBG to ARGB color space | |
if (color == Surface.MAGENTA) { | |
color = 0x00000000; | |
} else { | |
color |= 0xFF000000; | |
} | |
image.setRGB(x, y, color); | |
} | |
} | |
ImageIO.write(image, "png", path.toFile()); | |
} | |
} catch (Exception e) { | |
System.err.println("error processing " + name); | |
e.printStackTrace(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment