Add support for JPEG encoding option for HDMaps
This commit is contained in:
parent
49b38c10b7
commit
d008548306
11 changed files with 72 additions and 33 deletions
|
|
@ -19,6 +19,7 @@ import org.dynmap.utils.MapChunkCache;
|
|||
import org.json.simple.JSONObject;
|
||||
|
||||
public class HDMap extends MapType {
|
||||
|
||||
private String name;
|
||||
private String prefix;
|
||||
private HDPerspective perspective;
|
||||
|
|
@ -26,6 +27,11 @@ public class HDMap extends MapType {
|
|||
private HDLighting lighting;
|
||||
private ConfigurationNode configuration;
|
||||
private int mapzoomout;
|
||||
private MapType.ImageFormat imgformat;
|
||||
|
||||
public static final String IMGFORMAT_PNG = "png";
|
||||
public static final String IMGFORMAT_JPG = "jpg";
|
||||
|
||||
|
||||
public HDMap(ConfigurationNode configuration) {
|
||||
name = configuration.getString("name", null);
|
||||
|
|
@ -83,6 +89,12 @@ public class HDMap extends MapType {
|
|||
mapzoomout++;
|
||||
scale = scale / 2.0;
|
||||
}
|
||||
String fmt = configuration.getString("image-format", "png");
|
||||
/* Only allow png or jpg */
|
||||
if(fmt.equals(IMGFORMAT_PNG))
|
||||
imgformat = ImageFormat.FORMAT_PNG;
|
||||
else
|
||||
imgformat = ImageFormat.FORMAT_JPG;
|
||||
}
|
||||
|
||||
public HDShader getShader() { return shader; }
|
||||
|
|
@ -104,14 +116,6 @@ public class HDMap extends MapType {
|
|||
return perspective.getRequiredChunks(tile);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean render(MapChunkCache cache, MapTile tile, File bogus) {
|
||||
if(tile instanceof HDMapTile)
|
||||
return perspective.render(cache, (HDMapTile)tile);
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> baseZoomFilePrefixes() {
|
||||
ArrayList<String> s = new ArrayList<String>();
|
||||
|
|
@ -181,6 +185,8 @@ public class HDMap extends MapType {
|
|||
return lst;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImageFormat getImageFormat() { return imgformat; }
|
||||
|
||||
@Override
|
||||
public void buildClientConfiguration(JSONObject worldObject, DynmapWorld world) {
|
||||
|
|
@ -197,6 +203,7 @@ public class HDMap extends MapType {
|
|||
s(o, "bigmap", true);
|
||||
s(o, "mapzoomout", (world.getExtraZoomOutLevels()+mapzoomout));
|
||||
s(o, "mapzoomin", c.getInteger("mapzoomin", 2));
|
||||
s(o, "image-format", imgformat.getFileExt());
|
||||
perspective.addClientConfiguration(o);
|
||||
shader.addClientConfiguration(o);
|
||||
lighting.addClientConfiguration(o);
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package org.dynmap.hdmap;
|
|||
import org.dynmap.DynmapChunk;
|
||||
import org.dynmap.DynmapWorld;
|
||||
import org.dynmap.MapManager;
|
||||
import org.dynmap.MapType;
|
||||
|
||||
import java.util.List;
|
||||
import org.dynmap.MapTile;
|
||||
|
|
@ -21,20 +22,20 @@ public class HDMapTile extends MapTile {
|
|||
|
||||
@Override
|
||||
public String getFilename() {
|
||||
return getFilename("hdmap");
|
||||
return getFilename("hdmap", MapType.ImageFormat.FORMAT_PNG);
|
||||
}
|
||||
|
||||
public String getFilename(String prefix) {
|
||||
return prefix + "/" + (tx >> 5) + '_' + (ty >> 5) + '/' + tx + "_" + ty + ".png";
|
||||
public String getFilename(String prefix, MapType.ImageFormat format) {
|
||||
return prefix + "/" + (tx >> 5) + '_' + (ty >> 5) + '/' + tx + "_" + ty + "." + format.getFileExt();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDayFilename() {
|
||||
return getDayFilename("hdmap");
|
||||
return getDayFilename("hdmap", MapType.ImageFormat.FORMAT_PNG);
|
||||
}
|
||||
|
||||
public String getDayFilename(String prefix) {
|
||||
return prefix + "_day/" + (tx >> 5) + '_' + (ty >> 5) + '/' + tx + "_" + ty + ".png";
|
||||
public String getDayFilename(String prefix, MapType.ImageFormat format) {
|
||||
return prefix + "_day/" + (tx >> 5) + '_' + (ty >> 5) + '/' + tx + "_" + ty + "." + format.getFileExt();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ import org.dynmap.DynmapChunk;
|
|||
import org.dynmap.Log;
|
||||
import org.dynmap.MapManager;
|
||||
import org.dynmap.MapTile;
|
||||
import org.dynmap.MapType;
|
||||
import org.dynmap.TileHashManager;
|
||||
import org.dynmap.debug.Debug;
|
||||
import org.dynmap.utils.MapIterator.BlockStep;
|
||||
|
|
@ -967,7 +968,8 @@ public class IsoHDPerspective implements HDPerspective {
|
|||
String prefix = shaderstate[i].getMap().getPrefix();
|
||||
if(rendered[i]) {
|
||||
renderone = true;
|
||||
String fname = tile.getFilename(prefix);
|
||||
MapType.ImageFormat fmt = shaderstate[i].getMap().getImageFormat();
|
||||
String fname = tile.getFilename(prefix, fmt);
|
||||
File f = new File(tile.getDynmapWorld().worldtilepath, fname);
|
||||
FileLockManager.getWriteLock(f);
|
||||
try {
|
||||
|
|
@ -977,7 +979,7 @@ public class IsoHDPerspective implements HDPerspective {
|
|||
if(!f.getParentFile().exists())
|
||||
f.getParentFile().mkdirs();
|
||||
try {
|
||||
FileLockManager.imageIOWrite(im[i].buf_img, "png", f);
|
||||
FileLockManager.imageIOWrite(im[i].buf_img, fmt.getFileExt(), f);
|
||||
} catch (IOException e) {
|
||||
Debug.error("Failed to save image: " + f.getPath(), e);
|
||||
} catch (java.lang.NullPointerException e) {
|
||||
|
|
@ -998,7 +1000,7 @@ public class IsoHDPerspective implements HDPerspective {
|
|||
MapManager.mapman.updateStatistics(tile, prefix, true, tile_update, !rendered[i]);
|
||||
/* Handle day image, if needed */
|
||||
if(dayim[i] != null) {
|
||||
fname = tile.getDayFilename(prefix);
|
||||
fname = tile.getDayFilename(prefix, fmt);
|
||||
f = new File(tile.getDynmapWorld().worldtilepath, fname);
|
||||
FileLockManager.getWriteLock(f);
|
||||
prefix = prefix+"_day";
|
||||
|
|
@ -1010,7 +1012,7 @@ public class IsoHDPerspective implements HDPerspective {
|
|||
if(!f.getParentFile().exists())
|
||||
f.getParentFile().mkdirs();
|
||||
try {
|
||||
FileLockManager.imageIOWrite(dayim[i].buf_img, "png", f);
|
||||
FileLockManager.imageIOWrite(dayim[i].buf_img, fmt.getFileExt(), f);
|
||||
} catch (IOException e) {
|
||||
Debug.error("Failed to save image: " + f.getPath(), e);
|
||||
} catch (java.lang.NullPointerException e) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue