use of com.bergerkiller.bukkit.common.map.color.MCSDBubbleFormat in project BKCommonLib by bergerhealer.
the class MapColorPaletteTest method generateColorMap.
@Ignore
@Test
public void generateColorMap() {
// Minecraft version to generate the data for
String version = "1.17";
// Whether to regenerate the highly compressed bubble format file
boolean regenerate_bubble_format = false;
// Whether to display the final results in a debugging window
boolean debug_display = true;
// Sets compression versus compression time
int max_iterations = 2000000;
try {
// First generate a flat format file that can be quickly read again
// This helps when debugging the slower compression methods later
// To regenerate it, simply delete the file from the ./misc directory
String flat_filename = "misc/map_" + version.replace('.', '_') + "_flat.dat";
if (!new File(flat_filename).exists()) {
MCSDGenCiede2000 generated = new MCSDGenCiede2000(version);
generated.generate();
MCSDFlat flat = new MCSDFlat();
flat.readFrom(generated);
flat.writeTo(new FileOutputStream(flat_filename));
}
// Read the flat file format
Logging.LOGGER_MAPDISPLAY.info("Loading flat color space data...");
MCSDFlat flat = new MCSDFlat();
flat.readFrom(new FileInputStream(flat_filename));
// Generate a highly compressed 'bubble format' file that will be compiled with the application
String bubble_filename = "src/main/resources/com/bergerkiller/bukkit/common/internal/resources/map/" + "map_" + version.replace('.', '_') + ".bub";
if (regenerate_bubble_format || !new File(bubble_filename).exists()) {
MCSDBubbleFormat originalGrid = new MCSDBubbleFormat();
originalGrid.setMaxIterations(max_iterations);
originalGrid.readFrom(flat);
originalGrid.writeTo(new FileOutputStream(bubble_filename));
}
// Read the highly compressed 'bubble format'
Logging.LOGGER_MAPDISPLAY.info("Loading bubble format data...");
MCSDBubbleFormat bubble = new MCSDBubbleFormat();
bubble.readFrom(new FileInputStream(bubble_filename));
Logging.LOGGER_MAPDISPLAY.info("Finished loading all color map data!");
// Verify the data we read is the same as the original flatfile data
try {
assertColorSpaceEqual(flat, bubble);
} catch (Throwable t) {
System.out.println(t.getMessage());
}
// Debug display the results
if (debug_display) {
MapTexture map = MapTexture.createEmpty(256, 256);
MapDebugWindow window = MapDebugWindow.showMap(map);
do {
int z = window.x(0, 255);
byte[] slice = new byte[256 * 256];
if (window.y() >= 128) {
// Original flat data
int i = 0;
for (int y = 0; y < 256; y++) {
for (int x = 0; x < 256; x++) {
slice[i++] = flat.get(x, y, z);
}
}
} else if (window.y() >= 64) {
// Generated bubble format data
int i = 0;
for (int y = 0; y < 256; y++) {
for (int x = 0; x < 256; x++) {
slice[i++] = bubble.get(x, y, z);
}
}
} else {
// Bubble format webbing strands only
for (int i = 0; i < slice.length; i++) {
slice[i] = bubble.strands[z][i] ? MapColorPalette.COLOR_RED : MapColorPalette.COLOR_BLACK;
}
}
map.writePixels(0, 0, 256, 256, slice);
} while (window.waitNext());
}
} catch (IOException ex) {
ex.printStackTrace();
}
}
Aggregations