mirror of
https://github.com/webbukkit/dynmap.git
synced 2024-12-01 06:33:38 +01:00
Support applying background color to JPG tiles (since no transparency)
This commit is contained in:
parent
f371cff011
commit
b9170db1c1
@ -28,6 +28,8 @@ public class HDMap extends MapType {
|
|||||||
private ConfigurationNode configuration;
|
private ConfigurationNode configuration;
|
||||||
private int mapzoomout;
|
private int mapzoomout;
|
||||||
private MapType.ImageFormat imgformat;
|
private MapType.ImageFormat imgformat;
|
||||||
|
private int bgcolornight;
|
||||||
|
private int bgcolorday;
|
||||||
|
|
||||||
public static final String IMGFORMAT_PNG = "png";
|
public static final String IMGFORMAT_PNG = "png";
|
||||||
public static final String IMGFORMAT_JPG = "jpg";
|
public static final String IMGFORMAT_JPG = "jpg";
|
||||||
@ -101,6 +103,19 @@ public class HDMap extends MapType {
|
|||||||
Log.severe("HDMap '"+name+"' set invalid image-format: " + fmt);
|
Log.severe("HDMap '"+name+"' set invalid image-format: " + fmt);
|
||||||
imgformat = ImageFormat.FORMAT_PNG;
|
imgformat = ImageFormat.FORMAT_PNG;
|
||||||
}
|
}
|
||||||
|
/* Get color info */
|
||||||
|
String c = configuration.getString("background");
|
||||||
|
if(c != null) {
|
||||||
|
bgcolorday = bgcolornight = parseColor(c);
|
||||||
|
}
|
||||||
|
c = configuration.getString("backgroundday");
|
||||||
|
if(c != null) {
|
||||||
|
bgcolorday = parseColor(c);
|
||||||
|
}
|
||||||
|
c = configuration.getString("backgroundnight");
|
||||||
|
if(c != null) {
|
||||||
|
bgcolornight = parseColor(c);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public HDShader getShader() { return shader; }
|
public HDShader getShader() { return shader; }
|
||||||
@ -222,4 +237,36 @@ public class HDMap extends MapType {
|
|||||||
a(worldObject, "maps", o);
|
a(worldObject, "maps", o);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static int parseColor(String c) {
|
||||||
|
int v = 0;
|
||||||
|
if(c.startsWith("#")) {
|
||||||
|
c = c.substring(1);
|
||||||
|
if(c.length() == 3) { /* #rgb */
|
||||||
|
try {
|
||||||
|
v = Integer.valueOf(c, 16);
|
||||||
|
} catch (NumberFormatException nfx) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
v = 0xFF000000 | ((v & 0xF00) << 12) | ((v & 0x0F0) << 8) | ((v & 0x00F) << 4);
|
||||||
|
}
|
||||||
|
else if(c.length() == 6) { /* #rrggbb */
|
||||||
|
try {
|
||||||
|
v = Integer.valueOf(c, 16);
|
||||||
|
} catch (NumberFormatException nfx) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
v = 0xFF000000 | (v & 0xFFFFFF);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getBackgroundARGBDay() {
|
||||||
|
return bgcolorday;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getBackgroundARGBNight() {
|
||||||
|
return bgcolornight;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,7 @@ import org.dynmap.Log;
|
|||||||
import org.dynmap.MapManager;
|
import org.dynmap.MapManager;
|
||||||
import org.dynmap.MapTile;
|
import org.dynmap.MapTile;
|
||||||
import org.dynmap.MapType;
|
import org.dynmap.MapType;
|
||||||
|
import org.dynmap.MapType.ImageFormat;
|
||||||
import org.dynmap.TileHashManager;
|
import org.dynmap.TileHashManager;
|
||||||
import org.dynmap.debug.Debug;
|
import org.dynmap.debug.Debug;
|
||||||
import org.dynmap.utils.MapIterator.BlockStep;
|
import org.dynmap.utils.MapIterator.BlockStep;
|
||||||
@ -971,6 +972,9 @@ public class IsoHDPerspective implements HDPerspective {
|
|||||||
DynmapBufferedImage dayim[] = new DynmapBufferedImage[numshaders];
|
DynmapBufferedImage dayim[] = new DynmapBufferedImage[numshaders];
|
||||||
int[][] argb_buf = new int[numshaders][];
|
int[][] argb_buf = new int[numshaders][];
|
||||||
int[][] day_argb_buf = new int[numshaders][];
|
int[][] day_argb_buf = new int[numshaders][];
|
||||||
|
boolean isjpg[] = new boolean[numshaders];
|
||||||
|
int bgday[] = new int[numshaders];
|
||||||
|
int bgnight[] = new int[numshaders];
|
||||||
|
|
||||||
for(int i = 0; i < numshaders; i++) {
|
for(int i = 0; i < numshaders; i++) {
|
||||||
HDShader shader = shaderstate[i].getShader();
|
HDShader shader = shaderstate[i].getShader();
|
||||||
@ -985,6 +989,9 @@ public class IsoHDPerspective implements HDPerspective {
|
|||||||
dayim[i] = DynmapBufferedImage.allocateBufferedImage(tileWidth, tileHeight);
|
dayim[i] = DynmapBufferedImage.allocateBufferedImage(tileWidth, tileHeight);
|
||||||
day_argb_buf[i] = dayim[i].argb_buf;
|
day_argb_buf[i] = dayim[i].argb_buf;
|
||||||
}
|
}
|
||||||
|
isjpg[i] = shaderstate[i].getMap().getImageFormat() != ImageFormat.FORMAT_PNG;
|
||||||
|
bgday[i] = shaderstate[i].getMap().getBackgroundARGBDay();
|
||||||
|
bgnight[i] = shaderstate[i].getMap().getBackgroundARGBNight();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Create perspective state object */
|
/* Create perspective state object */
|
||||||
@ -996,6 +1003,7 @@ public class IsoHDPerspective implements HDPerspective {
|
|||||||
double ybase = tile.ty * tileHeight;
|
double ybase = tile.ty * tileHeight;
|
||||||
boolean shaderdone[] = new boolean[numshaders];
|
boolean shaderdone[] = new boolean[numshaders];
|
||||||
boolean rendered[] = new boolean[numshaders];
|
boolean rendered[] = new boolean[numshaders];
|
||||||
|
|
||||||
for(int x = 0; x < tileWidth; x++) {
|
for(int x = 0; x < tileWidth; x++) {
|
||||||
ps.px = x;
|
ps.px = x;
|
||||||
for(int y = 0; y < tileHeight; y++) {
|
for(int y = 0; y < tileHeight; y++) {
|
||||||
@ -1018,14 +1026,24 @@ public class IsoHDPerspective implements HDPerspective {
|
|||||||
rendered[i] = true;
|
rendered[i] = true;
|
||||||
}
|
}
|
||||||
shaderstate[i].getRayColor(rslt, 0);
|
shaderstate[i].getRayColor(rslt, 0);
|
||||||
|
if(isjpg[i] && rslt.isTransparent()) {
|
||||||
|
argb_buf[i][(tileHeight-y-1)*tileWidth + x] = bgnight[i];
|
||||||
|
}
|
||||||
|
else {
|
||||||
argb_buf[i][(tileHeight-y-1)*tileWidth + x] = rslt.getARGB();
|
argb_buf[i][(tileHeight-y-1)*tileWidth + x] = rslt.getARGB();
|
||||||
|
}
|
||||||
if(day_argb_buf[i] != null) {
|
if(day_argb_buf[i] != null) {
|
||||||
shaderstate[i].getRayColor(rslt, 1);
|
shaderstate[i].getRayColor(rslt, 1);
|
||||||
|
if(isjpg[i] && rslt.isTransparent()) {
|
||||||
|
day_argb_buf[i][(tileHeight-y-1)*tileWidth + x] = bgday[i];
|
||||||
|
}
|
||||||
|
else {
|
||||||
day_argb_buf[i][(tileHeight-y-1)*tileWidth + x] = rslt.getARGB();
|
day_argb_buf[i][(tileHeight-y-1)*tileWidth + x] = rslt.getARGB();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
boolean renderone = false;
|
boolean renderone = false;
|
||||||
/* Test to see if we're unchanged from older tile */
|
/* Test to see if we're unchanged from older tile */
|
||||||
|
Loading…
Reference in New Issue
Block a user