mirror of
https://github.com/webbukkit/dynmap.git
synced 2024-11-28 13:15:30 +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 int mapzoomout;
|
||||
private MapType.ImageFormat imgformat;
|
||||
private int bgcolornight;
|
||||
private int bgcolorday;
|
||||
|
||||
public static final String IMGFORMAT_PNG = "png";
|
||||
public static final String IMGFORMAT_JPG = "jpg";
|
||||
@ -100,7 +102,20 @@ public class HDMap extends MapType {
|
||||
if(imgformat == null) {
|
||||
Log.severe("HDMap '"+name+"' set invalid image-format: " + fmt);
|
||||
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; }
|
||||
@ -222,4 +237,36 @@ public class HDMap extends MapType {
|
||||
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.MapTile;
|
||||
import org.dynmap.MapType;
|
||||
import org.dynmap.MapType.ImageFormat;
|
||||
import org.dynmap.TileHashManager;
|
||||
import org.dynmap.debug.Debug;
|
||||
import org.dynmap.utils.MapIterator.BlockStep;
|
||||
@ -971,6 +972,9 @@ public class IsoHDPerspective implements HDPerspective {
|
||||
DynmapBufferedImage dayim[] = new DynmapBufferedImage[numshaders];
|
||||
int[][] 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++) {
|
||||
HDShader shader = shaderstate[i].getShader();
|
||||
@ -985,6 +989,9 @@ public class IsoHDPerspective implements HDPerspective {
|
||||
dayim[i] = DynmapBufferedImage.allocateBufferedImage(tileWidth, tileHeight);
|
||||
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 */
|
||||
@ -996,6 +1003,7 @@ public class IsoHDPerspective implements HDPerspective {
|
||||
double ybase = tile.ty * tileHeight;
|
||||
boolean shaderdone[] = new boolean[numshaders];
|
||||
boolean rendered[] = new boolean[numshaders];
|
||||
|
||||
for(int x = 0; x < tileWidth; x++) {
|
||||
ps.px = x;
|
||||
for(int y = 0; y < tileHeight; y++) {
|
||||
@ -1018,10 +1026,20 @@ public class IsoHDPerspective implements HDPerspective {
|
||||
rendered[i] = true;
|
||||
}
|
||||
shaderstate[i].getRayColor(rslt, 0);
|
||||
argb_buf[i][(tileHeight-y-1)*tileWidth + x] = rslt.getARGB();
|
||||
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();
|
||||
}
|
||||
if(day_argb_buf[i] != null) {
|
||||
shaderstate[i].getRayColor(rslt, 1);
|
||||
day_argb_buf[i][(tileHeight-y-1)*tileWidth + x] = rslt.getARGB();
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user