Fix POT textures in render themes (#443)
This commit is contained in:
@@ -616,7 +616,7 @@ public class XmlMapsforgeThemeBuilder extends DefaultHandler {
|
||||
x += f;
|
||||
transparent = !transparent;
|
||||
}
|
||||
b.texture = new TextureItem(bitmap);
|
||||
b.texture = new TextureItem(Utils.potBitmap(bitmap));
|
||||
b.texture.mipmap = true;
|
||||
b.randomOffset = false;
|
||||
b.stipple = width;
|
||||
@@ -633,7 +633,7 @@ public class XmlMapsforgeThemeBuilder extends DefaultHandler {
|
||||
Canvas canvas = CanvasAdapter.newCanvas();
|
||||
canvas.setBitmap(bitmap);
|
||||
canvas.drawBitmap(b.texture.bitmap, b.repeatStart, 0);
|
||||
b.texture = new TextureItem(bitmap);
|
||||
b.texture = new TextureItem(Utils.potBitmap(bitmap));
|
||||
b.texture.mipmap = true;
|
||||
b.fixed = true;
|
||||
b.randomOffset = false;
|
||||
|
||||
@@ -608,7 +608,7 @@ public class XmlThemeBuilder extends DefaultHandler {
|
||||
x += f;
|
||||
transparent = !transparent;
|
||||
}
|
||||
b.texture = new TextureItem(bitmap);
|
||||
b.texture = new TextureItem(Utils.potBitmap(bitmap));
|
||||
b.texture.mipmap = true;
|
||||
b.randomOffset = false;
|
||||
b.stipple = width;
|
||||
@@ -625,7 +625,7 @@ public class XmlThemeBuilder extends DefaultHandler {
|
||||
Canvas canvas = CanvasAdapter.newCanvas();
|
||||
canvas.setBitmap(bitmap);
|
||||
canvas.drawBitmap(b.texture.bitmap, b.repeatStart, 0);
|
||||
b.texture = new TextureItem(bitmap);
|
||||
b.texture = new TextureItem(Utils.potBitmap(bitmap));
|
||||
b.texture.mipmap = true;
|
||||
b.fixed = true;
|
||||
b.randomOffset = false;
|
||||
|
||||
@@ -45,20 +45,7 @@ public final class Utils {
|
||||
Bitmap bitmap = CanvasAdapter.getBitmapAsset(relativePathPrefix, src, width, height, percent);
|
||||
if (bitmap != null) {
|
||||
log.debug("loading {}", src);
|
||||
|
||||
if (Parameters.POT_TEXTURES) {
|
||||
int potWidth = MathUtils.nextPowerOfTwo(bitmap.getWidth());
|
||||
int potHeight = MathUtils.nextPowerOfTwo(bitmap.getHeight());
|
||||
if (potWidth != bitmap.getWidth() || potHeight != bitmap.getHeight()) {
|
||||
log.debug("POT texture: {}x{} -> {}x{}", bitmap.getWidth(), bitmap.getHeight(), potWidth, potHeight);
|
||||
Bitmap potBitmap = CanvasAdapter.newBitmap(potWidth, potHeight, 0);
|
||||
Canvas canvas = CanvasAdapter.newCanvas();
|
||||
canvas.setBitmap(potBitmap);
|
||||
canvas.drawBitmapScaled(bitmap);
|
||||
bitmap = potBitmap;
|
||||
}
|
||||
}
|
||||
return new TextureItem(bitmap, true);
|
||||
return new TextureItem(potBitmap(bitmap), true);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("{}: missing file / {}", src, e.getMessage());
|
||||
@@ -66,6 +53,27 @@ public final class Utils {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a Bitmap with POT size, if {@link Parameters#POT_TEXTURES} is true.
|
||||
* Else the returned Bitmap is the same instance of given Bitmap.
|
||||
* If the given Bitmap has POT size, the given instance is returned.
|
||||
*/
|
||||
public static Bitmap potBitmap(Bitmap bitmap) {
|
||||
if (Parameters.POT_TEXTURES) {
|
||||
int potWidth = MathUtils.nextPowerOfTwo(bitmap.getWidth());
|
||||
int potHeight = MathUtils.nextPowerOfTwo(bitmap.getHeight());
|
||||
if (potWidth != bitmap.getWidth() || potHeight != bitmap.getHeight()) {
|
||||
log.debug("POT texture: {}x{} -> {}x{}", bitmap.getWidth(), bitmap.getHeight(), potWidth, potHeight);
|
||||
Bitmap potBitmap = CanvasAdapter.newBitmap(potWidth, potHeight, 0);
|
||||
Canvas potCanvas = CanvasAdapter.newCanvas();
|
||||
potCanvas.setBitmap(potBitmap);
|
||||
potCanvas.drawBitmapScaled(bitmap);
|
||||
bitmap = potBitmap;
|
||||
}
|
||||
}
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
private Utils() {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user