Skip to content

Commit

Permalink
feat: Adjust mapview size to match official export, raw->png conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
Pazaz committed May 1, 2024
1 parent 118222f commit c34a919
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 4 deletions.
11 changes: 7 additions & 4 deletions mapview/src/main/java/mapview.java
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand Down
55 changes: 55 additions & 0 deletions tools/src/main/java/lostcity/tools/MapviewConvert.java
Original file line number Diff line number Diff line change
@@ -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 <filename>");
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);
}
}
}

0 comments on commit c34a919

Please sign in to comment.