From c34a91939ec7dd44a04a6b95068699a22b2db9d1 Mon Sep 17 00:00:00 2001 From: Pazaz Date: Wed, 1 May 2024 14:58:15 -0400 Subject: [PATCH] feat: Adjust mapview size to match official export, raw->png conversion --- mapview/src/main/java/mapview.java | 11 ++-- .../java/lostcity/tools/MapviewConvert.java | 55 +++++++++++++++++++ 2 files changed, 62 insertions(+), 4 deletions(-) create mode 100644 tools/src/main/java/lostcity/tools/MapviewConvert.java diff --git a/mapview/src/main/java/mapview.java b/mapview/src/main/java/mapview.java index 6c3b5d79..ee1a677c 100644 --- a/mapview/src/main/java/mapview.java +++ b/mapview/src/main/java/mapview.java @@ -264,18 +264,21 @@ protected void load() { // originX = local16.g2(); // originY = local16.g2(); //} - // 2004 worldmap.jag has no size.dat, so we use feb 2005's info til we have an original applet to compare + + // 2004 worldmap.jag has no size.dat, so I matched based on the official worldmap renders of the time centerX = 2112; - centerY = 2624; - originX = 1536; - originY = 1408; + centerY = 2816; + originX = 1472; + originY = 1216; offsetX = 3200 - centerX; offsetY = centerY + originY - 3200; + this.imageOverviewHeight = 180; this.imageOverviewWidth = originX * this.imageOverviewHeight / originY; this.overviewX = 635 - this.imageOverviewWidth - 5; this.overviewY = 503 - this.imageOverviewHeight - 20; + @Pc(73) Packet local73 = new Packet(local4.read("labels.dat", null)); this.labelCount = local73.g2(); for (@Pc(79) int local79 = 0; local79 < this.labelCount; local79++) { diff --git a/tools/src/main/java/lostcity/tools/MapviewConvert.java b/tools/src/main/java/lostcity/tools/MapviewConvert.java new file mode 100644 index 00000000..809c64b2 --- /dev/null +++ b/tools/src/main/java/lostcity/tools/MapviewConvert.java @@ -0,0 +1,55 @@ +package lostcity.tools; + +import javax.imageio.ImageIO; +import java.awt.image.BufferedImage; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.security.MessageDigest; + +public class MapviewConvert { + public static void main(String[] args) { + // read in a file named "map-$width-$height-rgb.raw" + // convert it to a file named "map-$width-$height.png" + // we can extract the dimensions from the file name + // the rgb indicates it's already in a 24-bit format so we don't have to do any conversion + + if (args.length != 1) { + System.err.println("Usage: MapviewConvert "); + System.exit(1); + } + + String filename = args[0]; + String[] parts = filename.split("-"); + if (parts.length != 4) { + System.err.println("Filename must be of the form map-$width-$height-rgb.raw"); + System.exit(1); + } + + int width = Integer.parseInt(parts[1]); + int height = Integer.parseInt(parts[2]); + + System.out.println("Converting " + filename + " to map-" + width + "-" + height + ".png"); + + try { + byte[] src = Files.readAllBytes(Paths.get(filename)); + BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); + + int index = 0; + for (int y = 0; y < height; y++) { + for (int x = 0; x < width; x++) { + int r = src[index++] & 0xFF; + int g = src[index++] & 0xFF; + int b = src[index++] & 0xFF; + int rgb = (r << 16) | (g << 8) | b; + img.setRGB(x, y, rgb); + } + } + + ImageIO.write(img, "png", Paths.get("map-" + width + "-" + height + ".png").toFile()); + } catch (IOException ex) { + ex.printStackTrace(); + System.exit(1); + } + } +} \ No newline at end of file