POT textures (#334)
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
* Copyright 2013 Hannes Janetzek
|
||||
* Copyright 2016-2017 devemux86
|
||||
* Copyright 2017 nebular
|
||||
* Copyright 2017 Longri
|
||||
*
|
||||
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
|
||||
*
|
||||
@@ -38,6 +39,11 @@ public interface Canvas {
|
||||
*/
|
||||
void drawText(String string, float x, float y, Paint fill, Paint stroke);
|
||||
|
||||
/**
|
||||
* Draw Bitmap to fill target by stretching.
|
||||
*/
|
||||
void drawBitmap(Bitmap bitmap);
|
||||
|
||||
/**
|
||||
* Draw Bitmap to Canvas.
|
||||
*/
|
||||
|
||||
@@ -24,6 +24,7 @@ import org.oscim.theme.IRenderTheme.ThemeException;
|
||||
public class ThemeLoader {
|
||||
|
||||
public static boolean USE_ATLAS;
|
||||
public static boolean POT_TEXTURES;
|
||||
|
||||
public static IRenderTheme load(String renderThemePath) throws ThemeException {
|
||||
return load(new ExternalRenderTheme(renderThemePath));
|
||||
|
||||
@@ -23,6 +23,7 @@ package org.oscim.theme;
|
||||
import org.oscim.backend.CanvasAdapter;
|
||||
import org.oscim.backend.XMLReaderAdapter;
|
||||
import org.oscim.backend.canvas.Bitmap;
|
||||
import org.oscim.backend.canvas.Canvas;
|
||||
import org.oscim.backend.canvas.Color;
|
||||
import org.oscim.backend.canvas.Paint.Cap;
|
||||
import org.oscim.backend.canvas.Paint.FontFamily;
|
||||
@@ -49,6 +50,7 @@ import org.oscim.theme.styles.SymbolStyle;
|
||||
import org.oscim.theme.styles.SymbolStyle.SymbolBuilder;
|
||||
import org.oscim.theme.styles.TextStyle;
|
||||
import org.oscim.theme.styles.TextStyle.TextBuilder;
|
||||
import org.oscim.utils.math.MathUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.xml.sax.Attributes;
|
||||
@@ -559,7 +561,7 @@ public class XmlThemeBuilder extends DefaultHandler {
|
||||
logUnknownAttribute(elementName, name, value, i);
|
||||
}
|
||||
|
||||
b.texture = loadTexture(src, b.symbolWidth, b.symbolHeight, b.symbolPercent);
|
||||
b.texture = loadTexture(mTheme.getRelativePathPrefix(), src, b.symbolWidth, b.symbolHeight, b.symbolPercent);
|
||||
/*if (b.texture != null)
|
||||
b.texture.mipmap = true;*/
|
||||
|
||||
@@ -652,19 +654,32 @@ public class XmlThemeBuilder extends DefaultHandler {
|
||||
logUnknownAttribute(elementName, name, value, i);
|
||||
}
|
||||
|
||||
b.texture = loadTexture(src, b.symbolWidth, b.symbolHeight, b.symbolPercent);
|
||||
b.texture = loadTexture(mTheme.getRelativePathPrefix(), src, b.symbolWidth, b.symbolHeight, b.symbolPercent);
|
||||
|
||||
return b.build();
|
||||
}
|
||||
|
||||
private TextureItem loadTexture(String src, int width, int height, int percent) {
|
||||
public static TextureItem loadTexture(String relativePathPrefix, String src, int width, int height, int percent) {
|
||||
if (src == null || src.length() == 0)
|
||||
return null;
|
||||
|
||||
try {
|
||||
Bitmap bitmap = CanvasAdapter.getBitmapAsset(mTheme.getRelativePathPrefix(), src, width, height, percent);
|
||||
Bitmap bitmap = CanvasAdapter.getBitmapAsset(relativePathPrefix, src, width, height, percent);
|
||||
if (bitmap != null) {
|
||||
log.debug("loading {}", src);
|
||||
|
||||
if (ThemeLoader.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.drawBitmap(bitmap);
|
||||
bitmap = potBitmap;
|
||||
}
|
||||
}
|
||||
return new TextureItem(bitmap, true);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
||||
Reference in New Issue
Block a user