POT textures #334 improvements and samples

This commit is contained in:
Emux 2017-03-16 14:21:32 +02:00
parent d1fdca170e
commit 4c9354c326
16 changed files with 151 additions and 246 deletions

View File

@ -7,6 +7,7 @@
- Osmagray theme [#300](https://github.com/mapsforge/vtm/issues/300) - Osmagray theme [#300](https://github.com/mapsforge/vtm/issues/300)
- Symbol rotation [#294](https://github.com/mapsforge/vtm/issues/294) - 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) - 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) - 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) - 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) - vtm-ios-example module [#326](https://github.com/mapsforge/vtm/issues/326)

View File

@ -33,7 +33,7 @@
android:name=".AtlasMultiTextureActivity" android:name=".AtlasMultiTextureActivity"
android:configChanges="keyboardHidden|orientation|screenSize" /> android:configChanges="keyboardHidden|orientation|screenSize" />
<activity <activity
android:name=".AtlasThemeMapActivity" android:name=".AtlasThemeActivity"
android:configChanges="keyboardHidden|orientation|screenSize" /> android:configChanges="keyboardHidden|orientation|screenSize" />
<activity <activity
android:name=".BitmapTileMapActivity" android:name=".BitmapTileMapActivity"
@ -86,6 +86,9 @@
<activity <activity
android:name=".PathOverlayActivity" android:name=".PathOverlayActivity"
android:configChanges="keyboardHidden|orientation|screenSize" /> android:configChanges="keyboardHidden|orientation|screenSize" />
<activity
android:name=".POTTextureActivity"
android:configChanges="keyboardHidden|orientation|screenSize" />
<activity <activity
android:name=".RotateMarkerOverlayActivity" android:name=".RotateMarkerOverlayActivity"
android:configChanges="keyboardHidden|orientation|screenSize" /> android:configChanges="keyboardHidden|orientation|screenSize" />

View File

@ -19,7 +19,7 @@ import android.os.Bundle;
import org.oscim.theme.ThemeLoader; import org.oscim.theme.ThemeLoader;
public class AtlasThemeMapActivity extends SimpleMapActivity { public class AtlasThemeActivity extends SimpleMapActivity {
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
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);
}
}

View File

@ -43,10 +43,13 @@ public class Samples extends Activity {
LinearLayout linearLayout = (LinearLayout) findViewById(R.id.samples); LinearLayout linearLayout = (LinearLayout) findViewById(R.id.samples);
linearLayout.addView(createButton(SimpleMapActivity.class)); linearLayout.addView(createButton(SimpleMapActivity.class));
linearLayout.addView(createButton(MapsforgeMapActivity.class)); linearLayout.addView(createButton(MapsforgeMapActivity.class));
linearLayout.addView(createButton(MapsforgeStyleActivity.class));
linearLayout.addView(createButton(MapboxMapActivity.class)); linearLayout.addView(createButton(MapboxMapActivity.class));
linearLayout.addView(createButton(OsmJsonMapActivity.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(createLabel("Raster Maps"));
linearLayout.addView(createButton(BitmapTileMapActivity.class)); linearLayout.addView(createButton(BitmapTileMapActivity.class));

View File

@ -60,18 +60,18 @@ public class AndroidCanvas implements Canvas {
} }
@Override @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( android.graphics.Bitmap scaledBitmap = android.graphics.Bitmap.createScaledBitmap(
((AndroidBitmap) bitmap).mBitmap, canvas.getWidth(), canvas.getHeight(), true); ((AndroidBitmap) bitmap).mBitmap, canvas.getWidth(), canvas.getHeight(), true);
canvas.drawBitmap(scaledBitmap, 0, 0, null); canvas.drawBitmap(scaledBitmap, 0, 0, null);
scaledBitmap.recycle(); scaledBitmap.recycle();
} }
@Override
public void drawBitmap(Bitmap bitmap, float x, float y) {
canvas.drawBitmap(((AndroidBitmap) bitmap).mBitmap, x, y, null);
}
@Override @Override
public void drawCircle(float x, float y, float radius, Paint paint) { public void drawCircle(float x, float y, float radius, Paint paint) {
canvas.drawCircle(x, y, radius, ((AndroidPaint) paint).mPaint); canvas.drawCircle(x, y, radius, ((AndroidPaint) paint).mPaint);

View File

@ -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 @Override
public void drawBitmap(Bitmap bitmap, float x, float y) { public void drawBitmap(Bitmap bitmap, float x, float y) {
BufferedImage src = ((AwtBitmap) bitmap).bitmap; BufferedImage src = ((AwtBitmap) bitmap).bitmap;
@ -153,6 +147,12 @@ public class AwtCanvas implements Canvas {
this.canvas.drawImage(src, (int) x, (int) y, null); 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 @Override
public void drawCircle(float x, float y, float radius, Paint paint) { public void drawCircle(float x, float y, float radius, Paint paint) {
AwtPaint awtPaint = (AwtPaint) paint; AwtPaint awtPaint = (AwtPaint) paint;

View File

@ -34,8 +34,8 @@ import org.oscim.layers.vector.geometries.Style;
import org.oscim.map.Map; import org.oscim.map.Map;
import org.oscim.renderer.bucket.TextureItem; import org.oscim.renderer.bucket.TextureItem;
import org.oscim.theme.VtmThemes; import org.oscim.theme.VtmThemes;
import org.oscim.theme.XmlThemeBuilder;
import org.oscim.tiling.source.oscimap4.OSciMap4TileSource; import org.oscim.tiling.source.oscimap4.OSciMap4TileSource;
import org.oscim.utils.Utils;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -63,7 +63,7 @@ public class IOSLineTexTest extends GdxMap {
mMap.setMapPosition(0, 0, 1 << 2); 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 = new TextureItem(CanvasAdapter.getBitmapAsset("", "patterns/pike.png"));
tex.mipmap = true; tex.mipmap = true;

View File

@ -83,15 +83,6 @@ public class IosCanvas implements Canvas {
iosFill.drawLine(this.cgBitmapContext, string, x, y); 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 @Override
public void drawBitmap(Bitmap bitmap, float x, float y) { public void drawBitmap(Bitmap bitmap, float x, float y) {
this.cgBitmapContext.saveGState(); this.cgBitmapContext.saveGState();
@ -101,6 +92,15 @@ public class IosCanvas implements Canvas {
this.cgBitmapContext.restoreGState(); 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 @Override
public void drawCircle(float x, float y, float radius, Paint paint) { public void drawCircle(float x, float y, float radius, Paint paint) {
CGRect rect = new CGRect(x - radius, y - radius, x + radius, y + radius); CGRect rect = new CGRect(x - radius, y - radius, x + radius, y + radius);

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
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: <mapFile>");
}
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());
}
}

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
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: <mapFile>");
}
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());
}
}

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
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());
}
}

View File

@ -91,12 +91,12 @@ public class GwtCanvas implements org.oscim.backend.canvas.Canvas {
} }
@Override @Override
public void drawBitmap(Bitmap bitmap) { public void drawBitmap(Bitmap bitmap, float x, float y) {
// TODO // TODO
} }
@Override @Override
public void drawBitmap(Bitmap bitmap, float x, float y) { public void drawBitmapScaled(Bitmap bitmap) {
// TODO // TODO
} }

View File

@ -39,16 +39,16 @@ public interface Canvas {
*/ */
void drawText(String string, float x, float y, Paint fill, Paint stroke); 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. * Draw Bitmap to Canvas.
*/ */
void drawBitmap(Bitmap bitmap, float x, float y); 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 drawCircle(float x, float y, float radius, Paint paint);
void drawLine(float x1, float y1, float x2, float y2, Paint paint); void drawLine(float x1, float y1, float x2, float y2, Paint paint);

View File

@ -23,7 +23,6 @@ package org.oscim.theme;
import org.oscim.backend.CanvasAdapter; import org.oscim.backend.CanvasAdapter;
import org.oscim.backend.XMLReaderAdapter; import org.oscim.backend.XMLReaderAdapter;
import org.oscim.backend.canvas.Bitmap; import org.oscim.backend.canvas.Bitmap;
import org.oscim.backend.canvas.Canvas;
import org.oscim.backend.canvas.Color; import org.oscim.backend.canvas.Color;
import org.oscim.backend.canvas.Paint.Cap; import org.oscim.backend.canvas.Paint.Cap;
import org.oscim.backend.canvas.Paint.FontFamily; 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;
import org.oscim.renderer.atlas.TextureAtlas.Rect; import org.oscim.renderer.atlas.TextureAtlas.Rect;
import org.oscim.renderer.atlas.TextureRegion; import org.oscim.renderer.atlas.TextureRegion;
import org.oscim.renderer.bucket.TextureItem;
import org.oscim.theme.IRenderTheme.ThemeException; import org.oscim.theme.IRenderTheme.ThemeException;
import org.oscim.theme.rule.Rule; import org.oscim.theme.rule.Rule;
import org.oscim.theme.rule.Rule.Closed; 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.SymbolStyle.SymbolBuilder;
import org.oscim.theme.styles.TextStyle; import org.oscim.theme.styles.TextStyle;
import org.oscim.theme.styles.TextStyle.TextBuilder; 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.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.xml.sax.Attributes; import org.xml.sax.Attributes;
@ -561,7 +559,7 @@ public class XmlThemeBuilder extends DefaultHandler {
logUnknownAttribute(elementName, name, value, i); 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) /*if (b.texture != null)
b.texture.mipmap = true;*/ b.texture.mipmap = true;*/
@ -654,40 +652,11 @@ public class XmlThemeBuilder extends DefaultHandler {
logUnknownAttribute(elementName, name, value, i); 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(); 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) { private LineStyle createOutline(String style, Attributes attributes) {
if (style != null) { if (style != null) {
LineStyle line = (LineStyle) mStyles.get(OUTLINE_STYLE + style); LineStyle line = (LineStyle) mStyles.get(OUTLINE_STYLE + style);

View File

@ -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 * 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 * terms of the GNU Lesser General Public License as published by the Free Software
@ -14,8 +15,19 @@
*/ */
package org.oscim.utils; 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 { public final class Utils {
private static final Logger log = LoggerFactory.getLogger(Utils.class);
/** /**
* Null safe equals. * Null safe equals.
*/ */
@ -23,6 +35,38 @@ public final class Utils {
return (o1 == o2) || (o1 != null && o1.equals(o2)); 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() { private Utils() {
throw new IllegalStateException(); throw new IllegalStateException();
} }