diff --git a/docs/Changelog.md b/docs/Changelog.md
index 3b620b69..c5db3221 100644
--- a/docs/Changelog.md
+++ b/docs/Changelog.md
@@ -7,6 +7,7 @@
- Osmagray theme [#300](https://github.com/mapsforge/vtm/issues/300)
- Symbol rotation [#294](https://github.com/mapsforge/vtm/issues/294)
- Location custom shaders & improvements [#317](https://github.com/mapsforge/vtm/issues/317) [#321](https://github.com/mapsforge/vtm/issues/321)
+- POT textures [#334](https://github.com/mapsforge/vtm/issues/334)
- OkHttp external cache [#135](https://github.com/mapsforge/vtm/issues/135)
- Texture atlas improvements [#301](https://github.com/mapsforge/vtm/pull/301) [#304](https://github.com/mapsforge/vtm/pull/304)
- vtm-ios-example module [#326](https://github.com/mapsforge/vtm/issues/326)
diff --git a/vtm-android-example/AndroidManifest.xml b/vtm-android-example/AndroidManifest.xml
index 32a63d47..6bada2d7 100644
--- a/vtm-android-example/AndroidManifest.xml
+++ b/vtm-android-example/AndroidManifest.xml
@@ -33,7 +33,7 @@
android:name=".AtlasMultiTextureActivity"
android:configChanges="keyboardHidden|orientation|screenSize" />
+
diff --git a/vtm-android-example/src/org/oscim/android/test/AtlasThemeMapActivity.java b/vtm-android-example/src/org/oscim/android/test/AtlasThemeActivity.java
similarity index 93%
rename from vtm-android-example/src/org/oscim/android/test/AtlasThemeMapActivity.java
rename to vtm-android-example/src/org/oscim/android/test/AtlasThemeActivity.java
index de509782..c2a22a4d 100644
--- a/vtm-android-example/src/org/oscim/android/test/AtlasThemeMapActivity.java
+++ b/vtm-android-example/src/org/oscim/android/test/AtlasThemeActivity.java
@@ -19,7 +19,7 @@ import android.os.Bundle;
import org.oscim.theme.ThemeLoader;
-public class AtlasThemeMapActivity extends SimpleMapActivity {
+public class AtlasThemeActivity extends SimpleMapActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
diff --git a/vtm-android-example/src/org/oscim/android/test/POTTextureActivity.java b/vtm-android-example/src/org/oscim/android/test/POTTextureActivity.java
new file mode 100644
index 00000000..4e3354d5
--- /dev/null
+++ b/vtm-android-example/src/org/oscim/android/test/POTTextureActivity.java
@@ -0,0 +1,29 @@
+/*
+ * Copyright 2017 devemux86
+ *
+ * This program is free software: you can redistribute it and/or modify it under the
+ * terms of the GNU Lesser General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License along with
+ * this program. If not, see .
+ */
+package org.oscim.android.test;
+
+import android.os.Bundle;
+
+import org.oscim.theme.ThemeLoader;
+
+public class POTTextureActivity extends SimpleMapActivity {
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ ThemeLoader.POT_TEXTURES = true;
+
+ super.onCreate(savedInstanceState);
+ }
+}
diff --git a/vtm-android-example/src/org/oscim/android/test/Samples.java b/vtm-android-example/src/org/oscim/android/test/Samples.java
index 893216ed..b11340bb 100644
--- a/vtm-android-example/src/org/oscim/android/test/Samples.java
+++ b/vtm-android-example/src/org/oscim/android/test/Samples.java
@@ -43,10 +43,13 @@ public class Samples extends Activity {
LinearLayout linearLayout = (LinearLayout) findViewById(R.id.samples);
linearLayout.addView(createButton(SimpleMapActivity.class));
linearLayout.addView(createButton(MapsforgeMapActivity.class));
- linearLayout.addView(createButton(MapsforgeStyleActivity.class));
linearLayout.addView(createButton(MapboxMapActivity.class));
linearLayout.addView(createButton(OsmJsonMapActivity.class));
- linearLayout.addView(createButton(AtlasThemeMapActivity.class));
+
+ linearLayout.addView(createLabel("Vector Features"));
+ linearLayout.addView(createButton(MapsforgeStyleActivity.class));
+ linearLayout.addView(createButton(AtlasThemeActivity.class));
+ linearLayout.addView(createButton(POTTextureActivity.class));
linearLayout.addView(createLabel("Raster Maps"));
linearLayout.addView(createButton(BitmapTileMapActivity.class));
diff --git a/vtm-android/src/org/oscim/android/canvas/AndroidCanvas.java b/vtm-android/src/org/oscim/android/canvas/AndroidCanvas.java
index bbef0388..407f581c 100644
--- a/vtm-android/src/org/oscim/android/canvas/AndroidCanvas.java
+++ b/vtm-android/src/org/oscim/android/canvas/AndroidCanvas.java
@@ -60,18 +60,18 @@ public class AndroidCanvas implements Canvas {
}
@Override
- public void drawBitmap(Bitmap bitmap) {
+ public void drawBitmap(Bitmap bitmap, float x, float y) {
+ canvas.drawBitmap(((AndroidBitmap) bitmap).mBitmap, x, y, null);
+ }
+
+ @Override
+ public void drawBitmapScaled(Bitmap bitmap) {
android.graphics.Bitmap scaledBitmap = android.graphics.Bitmap.createScaledBitmap(
((AndroidBitmap) bitmap).mBitmap, canvas.getWidth(), canvas.getHeight(), true);
canvas.drawBitmap(scaledBitmap, 0, 0, null);
scaledBitmap.recycle();
}
- @Override
- public void drawBitmap(Bitmap bitmap, float x, float y) {
- canvas.drawBitmap(((AndroidBitmap) bitmap).mBitmap, x, y, null);
- }
-
@Override
public void drawCircle(float x, float y, float radius, Paint paint) {
canvas.drawCircle(x, y, radius, ((AndroidPaint) paint).mPaint);
diff --git a/vtm-desktop/src/org/oscim/awt/AwtCanvas.java b/vtm-desktop/src/org/oscim/awt/AwtCanvas.java
index 4259b140..054ba68d 100644
--- a/vtm-desktop/src/org/oscim/awt/AwtCanvas.java
+++ b/vtm-desktop/src/org/oscim/awt/AwtCanvas.java
@@ -128,12 +128,6 @@ public class AwtCanvas implements Canvas {
}
}
- @Override
- public void drawBitmap(Bitmap bitmap) {
- Image scaledImage = ((AwtBitmap) bitmap).bitmap.getScaledInstance(this.bitmap.getWidth(), this.bitmap.getHeight(), Image.SCALE_DEFAULT);
- this.canvas.drawImage(scaledImage, 0, 0, this.bitmap.getWidth(), this.bitmap.getHeight(), null);
- }
-
@Override
public void drawBitmap(Bitmap bitmap, float x, float y) {
BufferedImage src = ((AwtBitmap) bitmap).bitmap;
@@ -153,6 +147,12 @@ public class AwtCanvas implements Canvas {
this.canvas.drawImage(src, (int) x, (int) y, null);
}
+ @Override
+ public void drawBitmapScaled(Bitmap bitmap) {
+ Image scaledImage = ((AwtBitmap) bitmap).bitmap.getScaledInstance(this.bitmap.getWidth(), this.bitmap.getHeight(), Image.SCALE_DEFAULT);
+ this.canvas.drawImage(scaledImage, 0, 0, this.bitmap.getWidth(), this.bitmap.getHeight(), null);
+ }
+
@Override
public void drawCircle(float x, float y, float radius, Paint paint) {
AwtPaint awtPaint = (AwtPaint) paint;
diff --git a/vtm-ios-example/src/org/oscim/ios/test/IOSLineTexTest.java b/vtm-ios-example/src/org/oscim/ios/test/IOSLineTexTest.java
index 7f4ce361..a0f375a1 100644
--- a/vtm-ios-example/src/org/oscim/ios/test/IOSLineTexTest.java
+++ b/vtm-ios-example/src/org/oscim/ios/test/IOSLineTexTest.java
@@ -34,8 +34,8 @@ import org.oscim.layers.vector.geometries.Style;
import org.oscim.map.Map;
import org.oscim.renderer.bucket.TextureItem;
import org.oscim.theme.VtmThemes;
-import org.oscim.theme.XmlThemeBuilder;
import org.oscim.tiling.source.oscimap4.OSciMap4TileSource;
+import org.oscim.utils.Utils;
import java.util.ArrayList;
import java.util.List;
@@ -63,7 +63,7 @@ public class IOSLineTexTest extends GdxMap {
mMap.setMapPosition(0, 0, 1 << 2);
- tex = XmlThemeBuilder.loadTexture("", "patterns/pike.png", 0, 0, 100);
+ tex = Utils.loadTexture("", "patterns/pike.png", 0, 0, 100);
// tex = new TextureItem(CanvasAdapter.getBitmapAsset("", "patterns/pike.png"));
tex.mipmap = true;
diff --git a/vtm-ios/src/org/oscim/ios/backend/IosCanvas.java b/vtm-ios/src/org/oscim/ios/backend/IosCanvas.java
index 8087742e..b42f17f8 100644
--- a/vtm-ios/src/org/oscim/ios/backend/IosCanvas.java
+++ b/vtm-ios/src/org/oscim/ios/backend/IosCanvas.java
@@ -83,15 +83,6 @@ public class IosCanvas implements Canvas {
iosFill.drawLine(this.cgBitmapContext, string, x, y);
}
- @Override
- public void drawBitmap(Bitmap bitmap) {
- CGRect rect = new CGRect(0, 0, this.cgBitmapContext.getWidth(), this.cgBitmapContext.getHeight());
- this.cgBitmapContext.saveGState();
- this.cgBitmapContext.translateCTM(0, 0);
- this.cgBitmapContext.drawImage(rect, ((IosBitmap) bitmap).cgBitmapContext.toImage());
- this.cgBitmapContext.restoreGState();
- }
-
@Override
public void drawBitmap(Bitmap bitmap, float x, float y) {
this.cgBitmapContext.saveGState();
@@ -101,6 +92,15 @@ public class IosCanvas implements Canvas {
this.cgBitmapContext.restoreGState();
}
+ @Override
+ public void drawBitmapScaled(Bitmap bitmap) {
+ CGRect rect = new CGRect(0, 0, this.cgBitmapContext.getWidth(), this.cgBitmapContext.getHeight());
+ this.cgBitmapContext.saveGState();
+ this.cgBitmapContext.translateCTM(0, 0);
+ this.cgBitmapContext.drawImage(rect, ((IosBitmap) bitmap).cgBitmapContext.toImage());
+ this.cgBitmapContext.restoreGState();
+ }
+
@Override
public void drawCircle(float x, float y, float radius, Paint paint) {
CGRect rect = new CGRect(x - radius, y - radius, x + radius, y + radius);
diff --git a/vtm-playground/src/org/oscim/test/MapsforgeLine_NPOT_Test.java b/vtm-playground/src/org/oscim/test/MapsforgeLine_NPOT_Test.java
deleted file mode 100644
index e45f5294..00000000
--- a/vtm-playground/src/org/oscim/test/MapsforgeLine_NPOT_Test.java
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * Copyright 2017 Longri
- *
- * This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
- *
- * This program is free software: you can redistribute it and/or modify it under the
- * terms of the GNU Lesser General Public License as published by the Free Software
- * Foundation, either version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
- * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License along with
- * this program. If not, see .
- */
-package org.oscim.test;
-
-import org.oscim.gdx.GdxMap;
-import org.oscim.gdx.GdxMapApp;
-import org.oscim.layers.TileGridLayer;
-import org.oscim.layers.tile.vector.VectorTileLayer;
-import org.oscim.renderer.BitmapRenderer;
-import org.oscim.renderer.GLViewport;
-import org.oscim.scalebar.DefaultMapScaleBar;
-import org.oscim.scalebar.ImperialUnitAdapter;
-import org.oscim.scalebar.MapScaleBar;
-import org.oscim.scalebar.MapScaleBarLayer;
-import org.oscim.scalebar.MetricUnitAdapter;
-import org.oscim.theme.VtmThemes;
-import org.oscim.tiling.source.mapfile.MapFileTileSource;
-
-import java.io.File;
-
-public class MapsforgeLine_NPOT_Test extends GdxMap {
-
- private static File mapFile;
-
- @Override
- public void createLayers() {
- MapFileTileSource tileSource = new MapFileTileSource();
- tileSource.setMapFile(mapFile.getAbsolutePath());
- tileSource.setPreferredLanguage("en");
-
- VectorTileLayer l = mMap.setBaseMap(tileSource);
- mMap.setTheme(VtmThemes.DEFAULT);
- mMap.layers().add(new TileGridLayer(mMap));
-
- DefaultMapScaleBar mapScaleBar = new DefaultMapScaleBar(mMap);
- mapScaleBar.setScaleBarMode(DefaultMapScaleBar.ScaleBarMode.BOTH);
- mapScaleBar.setDistanceUnitAdapter(MetricUnitAdapter.INSTANCE);
- mapScaleBar.setSecondaryDistanceUnitAdapter(ImperialUnitAdapter.INSTANCE);
- mapScaleBar.setScaleBarPosition(MapScaleBar.ScaleBarPosition.BOTTOM_LEFT);
-
- MapScaleBarLayer mapScaleBarLayer = new MapScaleBarLayer(mMap, mapScaleBar);
- BitmapRenderer renderer = mapScaleBarLayer.getRenderer();
- renderer.setPosition(GLViewport.Position.BOTTOM_LEFT);
- renderer.setOffset(5, 0);
- mMap.layers().add(mapScaleBarLayer);
-
- //https://www.google.de/maps/@52.5808431,13.4000501,19.5z
- mMap.setMapPosition(52.5808431, 13.4000501, 1 << 21);
- }
-
- private static File getMapFile(String[] args) {
- if (args.length == 0) {
- throw new IllegalArgumentException("missing argument: ");
- }
-
- File file = new File(args[0]);
- if (!file.exists()) {
- throw new IllegalArgumentException("file does not exist: " + file);
- } else if (!file.isFile()) {
- throw new IllegalArgumentException("not a file: " + file);
- } else if (!file.canRead()) {
- throw new IllegalArgumentException("cannot read file: " + file);
- }
- return file;
- }
-
- public static void main(String[] args) {
- mapFile = getMapFile(args);
-
- GdxMapApp.init();
- GdxMapApp.run(new MapsforgeLine_NPOT_Test());
- }
-}
\ No newline at end of file
diff --git a/vtm-playground/src/org/oscim/test/MapsforgeLine_POT_Test.java b/vtm-playground/src/org/oscim/test/MapsforgeLine_POT_Test.java
deleted file mode 100644
index c24a5c81..00000000
--- a/vtm-playground/src/org/oscim/test/MapsforgeLine_POT_Test.java
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * Copyright 2017 Longri
- *
- * This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
- *
- * This program is free software: you can redistribute it and/or modify it under the
- * terms of the GNU Lesser General Public License as published by the Free Software
- * Foundation, either version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
- * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License along with
- * this program. If not, see .
- */
-package org.oscim.test;
-
-import org.oscim.gdx.GdxMap;
-import org.oscim.gdx.GdxMapApp;
-import org.oscim.layers.TileGridLayer;
-import org.oscim.layers.tile.vector.VectorTileLayer;
-import org.oscim.renderer.BitmapRenderer;
-import org.oscim.renderer.GLViewport;
-import org.oscim.scalebar.DefaultMapScaleBar;
-import org.oscim.scalebar.ImperialUnitAdapter;
-import org.oscim.scalebar.MapScaleBar;
-import org.oscim.scalebar.MapScaleBarLayer;
-import org.oscim.scalebar.MetricUnitAdapter;
-import org.oscim.theme.ThemeLoader;
-import org.oscim.theme.VtmThemes;
-import org.oscim.tiling.source.mapfile.MapFileTileSource;
-
-import java.io.File;
-
-public class MapsforgeLine_POT_Test extends GdxMap {
-
- private static File mapFile;
-
- @Override
- public void createLayers() {
- ThemeLoader.POT_TEXTURES = true;
-
- MapFileTileSource tileSource = new MapFileTileSource();
- tileSource.setMapFile(mapFile.getAbsolutePath());
- tileSource.setPreferredLanguage("en");
-
- VectorTileLayer l = mMap.setBaseMap(tileSource);
- mMap.setTheme(VtmThemes.DEFAULT);
- mMap.layers().add(new TileGridLayer(mMap));
-
- DefaultMapScaleBar mapScaleBar = new DefaultMapScaleBar(mMap);
- mapScaleBar.setScaleBarMode(DefaultMapScaleBar.ScaleBarMode.BOTH);
- mapScaleBar.setDistanceUnitAdapter(MetricUnitAdapter.INSTANCE);
- mapScaleBar.setSecondaryDistanceUnitAdapter(ImperialUnitAdapter.INSTANCE);
- mapScaleBar.setScaleBarPosition(MapScaleBar.ScaleBarPosition.BOTTOM_LEFT);
-
- MapScaleBarLayer mapScaleBarLayer = new MapScaleBarLayer(mMap, mapScaleBar);
- BitmapRenderer renderer = mapScaleBarLayer.getRenderer();
- renderer.setPosition(GLViewport.Position.BOTTOM_LEFT);
- renderer.setOffset(5, 0);
- mMap.layers().add(mapScaleBarLayer);
-
- //https://www.google.de/maps/@52.5808431,13.4000501,19.5z
- mMap.setMapPosition(52.5808431, 13.4000501, 1 << 21);
- }
-
- private static File getMapFile(String[] args) {
- if (args.length == 0) {
- throw new IllegalArgumentException("missing argument: ");
- }
-
- File file = new File(args[0]);
- if (!file.exists()) {
- throw new IllegalArgumentException("file does not exist: " + file);
- } else if (!file.isFile()) {
- throw new IllegalArgumentException("not a file: " + file);
- } else if (!file.canRead()) {
- throw new IllegalArgumentException("cannot read file: " + file);
- }
- return file;
- }
-
- public static void main(String[] args) {
- mapFile = getMapFile(args);
-
- GdxMapApp.init();
- GdxMapApp.run(new MapsforgeLine_POT_Test());
- }
-}
\ No newline at end of file
diff --git a/vtm-playground/src/org/oscim/test/POTTextureTest.java b/vtm-playground/src/org/oscim/test/POTTextureTest.java
new file mode 100644
index 00000000..f0c3aa09
--- /dev/null
+++ b/vtm-playground/src/org/oscim/test/POTTextureTest.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2017 Longri
+ * Copyright 2017 devemux86
+ *
+ * This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
+ *
+ * This program is free software: you can redistribute it and/or modify it under the
+ * terms of the GNU Lesser General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License along with
+ * this program. If not, see .
+ */
+package org.oscim.test;
+
+import org.oscim.gdx.GdxMapApp;
+import org.oscim.theme.ThemeLoader;
+
+public class POTTextureTest extends MapTest {
+
+ private POTTextureTest() {
+ ThemeLoader.POT_TEXTURES = true;
+ }
+
+ public static void main(String[] args) {
+ GdxMapApp.init();
+ GdxMapApp.run(new POTTextureTest());
+ }
+}
diff --git a/vtm-web/src/org/oscim/gdx/client/GwtCanvas.java b/vtm-web/src/org/oscim/gdx/client/GwtCanvas.java
index 654956de..2ef2ce10 100644
--- a/vtm-web/src/org/oscim/gdx/client/GwtCanvas.java
+++ b/vtm-web/src/org/oscim/gdx/client/GwtCanvas.java
@@ -91,12 +91,12 @@ public class GwtCanvas implements org.oscim.backend.canvas.Canvas {
}
@Override
- public void drawBitmap(Bitmap bitmap) {
+ public void drawBitmap(Bitmap bitmap, float x, float y) {
// TODO
}
@Override
- public void drawBitmap(Bitmap bitmap, float x, float y) {
+ public void drawBitmapScaled(Bitmap bitmap) {
// TODO
}
diff --git a/vtm/src/org/oscim/backend/canvas/Canvas.java b/vtm/src/org/oscim/backend/canvas/Canvas.java
index f0900055..93f86ea2 100644
--- a/vtm/src/org/oscim/backend/canvas/Canvas.java
+++ b/vtm/src/org/oscim/backend/canvas/Canvas.java
@@ -39,16 +39,16 @@ 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.
*/
void drawBitmap(Bitmap bitmap, float x, float y);
+ /**
+ * Draw scaled Bitmap to fill target.
+ */
+ void drawBitmapScaled(Bitmap bitmap);
+
void drawCircle(float x, float y, float radius, Paint paint);
void drawLine(float x1, float y1, float x2, float y2, Paint paint);
diff --git a/vtm/src/org/oscim/theme/XmlThemeBuilder.java b/vtm/src/org/oscim/theme/XmlThemeBuilder.java
index 6e19cd4e..c5f9cb9c 100644
--- a/vtm/src/org/oscim/theme/XmlThemeBuilder.java
+++ b/vtm/src/org/oscim/theme/XmlThemeBuilder.java
@@ -23,7 +23,6 @@ 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;
@@ -31,7 +30,6 @@ import org.oscim.backend.canvas.Paint.FontStyle;
import org.oscim.renderer.atlas.TextureAtlas;
import org.oscim.renderer.atlas.TextureAtlas.Rect;
import org.oscim.renderer.atlas.TextureRegion;
-import org.oscim.renderer.bucket.TextureItem;
import org.oscim.theme.IRenderTheme.ThemeException;
import org.oscim.theme.rule.Rule;
import org.oscim.theme.rule.Rule.Closed;
@@ -50,7 +48,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.oscim.utils.Utils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xml.sax.Attributes;
@@ -561,7 +559,7 @@ public class XmlThemeBuilder extends DefaultHandler {
logUnknownAttribute(elementName, name, value, i);
}
- b.texture = loadTexture(mTheme.getRelativePathPrefix(), src, b.symbolWidth, b.symbolHeight, b.symbolPercent);
+ b.texture = Utils.loadTexture(mTheme.getRelativePathPrefix(), src, b.symbolWidth, b.symbolHeight, b.symbolPercent);
/*if (b.texture != null)
b.texture.mipmap = true;*/
@@ -654,40 +652,11 @@ public class XmlThemeBuilder extends DefaultHandler {
logUnknownAttribute(elementName, name, value, i);
}
- b.texture = loadTexture(mTheme.getRelativePathPrefix(), src, b.symbolWidth, b.symbolHeight, b.symbolPercent);
+ b.texture = Utils.loadTexture(mTheme.getRelativePathPrefix(), src, b.symbolWidth, b.symbolHeight, b.symbolPercent);
return b.build();
}
- 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(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) {
- log.debug("missing file / {}", e.getMessage());
- }
- return null;
- }
-
private LineStyle createOutline(String style, Attributes attributes) {
if (style != null) {
LineStyle line = (LineStyle) mStyles.get(OUTLINE_STYLE + style);
diff --git a/vtm/src/org/oscim/utils/Utils.java b/vtm/src/org/oscim/utils/Utils.java
index 78ad635e..caccd9f2 100644
--- a/vtm/src/org/oscim/utils/Utils.java
+++ b/vtm/src/org/oscim/utils/Utils.java
@@ -1,5 +1,6 @@
/*
- * Copyright 2016 devemux86
+ * Copyright 2016-2017 devemux86
+ * Copyright 2017 Longri
*
* This program is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
@@ -14,8 +15,19 @@
*/
package org.oscim.utils;
+import org.oscim.backend.CanvasAdapter;
+import org.oscim.backend.canvas.Bitmap;
+import org.oscim.backend.canvas.Canvas;
+import org.oscim.renderer.bucket.TextureItem;
+import org.oscim.theme.ThemeLoader;
+import org.oscim.utils.math.MathUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
public final class Utils {
+ private static final Logger log = LoggerFactory.getLogger(Utils.class);
+
/**
* Null safe equals.
*/
@@ -23,6 +35,38 @@ public final class Utils {
return (o1 == o2) || (o1 != null && o1.equals(o2));
}
+ /**
+ * Load a texture from a specified location and optional dimensions.
+ */
+ 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(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.drawBitmapScaled(bitmap);
+ bitmap = potBitmap;
+ }
+ }
+ return new TextureItem(bitmap, true);
+ }
+ } catch (Exception e) {
+ log.debug("missing file / {}", e.getMessage());
+ }
+ return null;
+ }
+
private Utils() {
throw new IllegalStateException();
}