Permalink
Browse files

Hillshading PR #922 improvements (no functionality change), #923

  • Loading branch information...
devemux86 committed Feb 12, 2017
1 parent 7dd483c commit 1928ec964c8f843e9dbc75cf7a0b3b638a93ee1e
Showing with 751 additions and 371 deletions.
  1. +1 −0 docs/Changelog.md
  2. +1 −1 docs/MapCreation.md
  3. +2 −2 docs/Rendertheme.md
  4. +3 −2 mapsforge-core/src/main/java/org/mapsforge/core/graphics/GraphicContext.java
  5. +6 −5 mapsforge-core/src/main/java/org/mapsforge/core/graphics/GraphicFactory.java
  6. +9 −8 mapsforge-map-android/src/main/java/org/mapsforge/map/android/graphics/AndroidCanvas.java
  7. +11 −10 mapsforge-map-android/src/main/java/org/mapsforge/map/android/graphics/AndroidGraphicFactory.java
  8. +16 −13 mapsforge-map-android/src/main/java/org/mapsforge/map/android/util/AndroidUtil.java
  9. +4 −2 mapsforge-map-android/src/main/java/org/mapsforge/map/android/util/MapViewerTemplate.java
  10. +32 −29 mapsforge-map-awt/src/main/java/org/mapsforge/map/awt/graphics/AwtCanvas.java
  11. +19 −18 mapsforge-map-awt/src/main/java/org/mapsforge/map/awt/graphics/AwtGraphicFactory.java
  12. +72 −61 mapsforge-map-awt/src/main/java/org/mapsforge/map/awt/graphics/AwtLuminanceShadingComposite.java
  13. +47 −36 mapsforge-map/src/main/java/org/mapsforge/map/layer/hills/HillsRenderConfig.java
  14. +25 −9 mapsforge-map/src/main/java/org/mapsforge/map/layer/hills/ShadingAlgorithm.java
  15. +29 −18 mapsforge-map/src/main/java/org/mapsforge/map/layer/hills/SimpleShadingAlgortithm.java
  16. +10 −9 mapsforge-map/src/main/java/org/mapsforge/map/layer/renderer/CanvasRasterer.java
  17. +11 −8 mapsforge-map/src/main/java/org/mapsforge/map/layer/renderer/DatabaseRenderer.java
  18. +3 −6 mapsforge-map/src/main/java/org/mapsforge/map/layer/renderer/HillshadingContainer.java
  19. +2 −2 mapsforge-map/src/main/java/org/mapsforge/map/layer/renderer/ShapeType.java
  20. +5 −4 mapsforge-map/src/main/java/org/mapsforge/map/layer/renderer/StandardRenderer.java
  21. +26 −22 mapsforge-map/src/main/java/org/mapsforge/map/layer/renderer/TileRendererLayer.java
  22. +35 −32 mapsforge-map/src/main/java/org/mapsforge/map/rendertheme/renderinstruction/Hillshading.java
  23. +5 −2 mapsforge-map/src/main/java/org/mapsforge/map/rendertheme/rule/RenderTheme.java
  24. +10 −13 mapsforge-map/src/main/java/org/mapsforge/map/rendertheme/rule/RenderThemeHandler.java
  25. +3 −3 mapsforge-samples-android/AndroidManifest.xml
  26. +1 −1 mapsforge-samples-android/assets/mapsforge/stylemenu.xml
  27. +2 −1 mapsforge-samples-android/res/values/strings.xml
  28. +8 −14 ...ndroid/src/main/java/org/mapsforge/samples/android/{Hillshading.java → HillshadingMapViewer.java}
  29. +6 −1 mapsforge-samples-android/src/main/java/org/mapsforge/samples/android/Samples.java
  30. +1 −1 mapsforge-samples-android/src/main/java/org/mapsforge/samples/android/SamplesBaseActivity.java
  31. +20 −22 mapsforge-samples-awt/src/main/java/org/mapsforge/samples/awt/Samples.java
  32. +7 −2 mapsforge-themes/src/main/resources/assets/mapsforge/default.xml
  33. +5 −1 mapsforge-themes/src/main/resources/assets/mapsforge/osmarender.xml
  34. +0 −13 resources/renderTheme-v5.xsd
  35. +314 −0 resources/renderTheme-v6.xsd
View
@@ -3,6 +3,7 @@
## New since 0.7.0
- Android fix hardware acceleration [#919](https://github.com/mapsforge/mapsforge/issues/919) [#613](https://github.com/mapsforge/mapsforge/issues/613)
+- Hillshading from HGT digital elevation model data [#923](https://github.com/mapsforge/mapsforge/issues/923)
- Android tile cache folder option [#913](https://github.com/mapsforge/mapsforge/issues/913)
- Android SVG cache folder option [#914](https://github.com/mapsforge/mapsforge/issues/914)
- Desktop tile cache creation utility [#915](https://github.com/mapsforge/mapsforge/issues/915)
View
@@ -98,7 +98,7 @@ On the reader side, the only change required is to display the land areas correc
```xml
<?xml version="1.0" encoding="UTF-8"?>
<rendertheme xmlns="http://mapsforge.org/renderTheme" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://mapsforge.org/renderTheme .../renderTheme-v5.xsd"
+ xsi:schemaLocation="http://mapsforge.org/renderTheme .../renderTheme-v6.xsd"
version="4" map-background="#F8F8F8" map-background-outside="#DDDDDD">
<rule e="way" k="natural" v="issea|sea">
View
@@ -95,13 +95,13 @@ With mapsforge release 0.5, we introduce the enhanced **Rendertheme V4 XML** wit
Rendertheme V4 or newer remains **fully backward compatible** with version 3, meaning that any previously developed rendertheme definition will still render with V4 without any changes required (you do not even need to change the version number in the header).
-You can find the full xsd in the mapsforge repository at https://github.com/mapsforge/mapsforge/blob/master/resources/renderTheme-v5.xsd.
+You can find the full xsd in the mapsforge repository at https://github.com/mapsforge/mapsforge/blob/master/resources/renderTheme-v6.xsd.
But if you want to develop your renderthemes further, Rendertheme V4 offers a number of enhancements. If you want to make use of the new features, you will first need to set your rendertheme version in the header to 4 or newer:
```xml
<rendertheme xmlns="http://mapsforge.org/renderTheme" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://mapsforge.org/renderTheme renderTheme-v5.xsd" version="5" map-background="#f8f8f8" map-background-outside="#dddddd">
+ xsi:schemaLocation="http://mapsforge.org/renderTheme renderTheme-v6.xsd" version="5" map-background="#f8f8f8" map-background-outside="#dddddd">
```
###Header Elements
@@ -2,6 +2,7 @@
* Copyright 2010, 2011, 2012, 2013 mapsforge.org
* Copyright 2014 Ludwig M Brinckmann
* Copyright 2016 devemux86
+ * Copyright 2017 usrusr
*
* 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
@@ -19,8 +20,6 @@
import org.mapsforge.core.model.Rectangle;
public interface GraphicContext {
- void shadeBitmap(Bitmap bitmap, Rectangle shadeRect, Rectangle tileRect, float magnitude);
-
void drawBitmap(Bitmap bitmap, int left, int top);
void drawBitmap(Bitmap bitmap, int left, int top, Filter filter);
@@ -48,4 +47,6 @@
void setClip(int left, int top, int width, int height);
void setClipDifference(int left, int top, int width, int height);
+
+ void shadeBitmap(Bitmap bitmap, Rectangle shadeRect, Rectangle tileRect, float magnitude);
}
@@ -1,6 +1,7 @@
/*
* Copyright 2010, 2011, 2012, 2013 mapsforge.org
* Copyright 2014 Ludwig M Brinckmann
+ * Copyright 2017 usrusr
*
* 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
@@ -25,11 +26,6 @@
public interface GraphicFactory {
Bitmap createBitmap(int width, int height);
- /** create a single channel bitmap for hillshading
- * @param buffer
- */
- Bitmap createMonoBitmap(int width, int height, byte[] buffer);
-
Bitmap createBitmap(int width, int height, boolean isTransparent);
Canvas createCanvas();
@@ -40,6 +36,11 @@
Matrix createMatrix();
+ /**
+ * Create a single channel bitmap, e.g. for hillshading.
+ */
+ Bitmap createMonoBitmap(int width, int height, byte[] buffer);
+
Paint createPaint();
Paint createPaint(Paint paint);
@@ -2,6 +2,7 @@
* Copyright 2010, 2011, 2012, 2013 mapsforge.org
* Copyright 2014 Ludwig M Brinckmann
* Copyright 2014-2016 devemux86
+ * Copyright 2017 usrusr
*
* 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
@@ -118,14 +119,6 @@ public void drawBitmap(Bitmap bitmap, Matrix matrix) {
this.canvas.drawBitmap(AndroidGraphicFactory.getBitmap(bitmap), AndroidGraphicFactory.getMatrix(matrix), bitmapPaint);
}
- @Override
- public void shadeBitmap(Bitmap bitmap, Rectangle hillRect, Rectangle tileRect, float magnitude) {
- shadePaint.setAlpha((int) (255 * magnitude));
- Rect atr = new Rect((int)hillRect.left, (int)hillRect.top, (int)hillRect.right, (int)hillRect.bottom);
- Rect asr = new Rect((int)tileRect.left, (int)tileRect.top, (int)tileRect.right, (int)tileRect.bottom);
- this.canvas.drawBitmap(AndroidGraphicFactory.getBitmap(bitmap), atr, asr, shadePaint);
- }
-
@Override
public void drawBitmap(Bitmap bitmap, Matrix matrix, Filter filter) {
applyFilter(filter);
@@ -234,4 +227,12 @@ public void setClipDifference(int left, int top, int width, int height) {
public void setClipInternal(int left, int top, int width, int height, Region.Op op) {
this.canvas.clipRect(left, top, left + width, top + height, op);
}
+
+ @Override
+ public void shadeBitmap(Bitmap bitmap, Rectangle hillRect, Rectangle tileRect, float magnitude) {
+ shadePaint.setAlpha((int) (255 * magnitude));
+ Rect atr = new Rect((int) hillRect.left, (int) hillRect.top, (int) hillRect.right, (int) hillRect.bottom);
+ Rect asr = new Rect((int) tileRect.left, (int) tileRect.top, (int) tileRect.right, (int) tileRect.bottom);
+ this.canvas.drawBitmap(AndroidGraphicFactory.getBitmap(bitmap), atr, asr, shadePaint);
+ }
}
@@ -2,6 +2,7 @@
* Copyright 2010, 2011, 2012, 2013 mapsforge.org
* Copyright 2014 Ludwig M Brinckmann
* Copyright 2014-2017 devemux86
+ * Copyright 2017 usrusr
*
* 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
@@ -193,16 +194,6 @@ public static void clearResourceMemoryCache() {
public Bitmap createBitmap(int width, int height) {
return new AndroidBitmap(width, height, TRANSPARENT_BITMAP);
}
- @Override
- public Bitmap createMonoBitmap(int width, int height, byte[] buffer) {
- AndroidBitmap androidBitmap = new AndroidBitmap(width, height, MONO_ALPHA_BITMAP);
- if(buffer!=null) {
- Buffer b = ByteBuffer.wrap(buffer);
- androidBitmap.bitmap.copyPixelsFromBuffer(b);
- }
- return androidBitmap;
- }
-
@Override
public Bitmap createBitmap(int width, int height, boolean isTransparent) {
@@ -232,6 +223,16 @@ public Matrix createMatrix() {
return new AndroidMatrix();
}
+ @Override
+ public Bitmap createMonoBitmap(int width, int height, byte[] buffer) {
+ AndroidBitmap androidBitmap = new AndroidBitmap(width, height, MONO_ALPHA_BITMAP);
+ if (buffer != null) {
+ Buffer b = ByteBuffer.wrap(buffer);
+ androidBitmap.bitmap.copyPixelsFromBuffer(b);
+ }
+ return androidBitmap;
+ }
+
@Override
public Paint createPaint() {
return new AndroidPaint();
@@ -2,6 +2,7 @@
* Copyright 2010, 2011, 2012, 2013 mapsforge.org
* Copyright 2014-2015 Ludwig M Brinckmann
* Copyright 2014-2017 devemux86
+ * Copyright 2017 usrusr
*
* 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
@@ -223,7 +224,7 @@ public static TileCache createTileCache(Context c, String id, int tileSize, int
}
/**
- * Utility method to create a standard tile renderer layer.
+ * Utility method to create a standard tile renderer layer (without hillshading).
*
* @param tileCache the cache
* @param mapViewPosition the position
@@ -235,13 +236,13 @@ public static TileRendererLayer createTileRendererLayer(
TileCache tileCache, MapViewPosition mapViewPosition,
MapDataStore mapFile, XmlRenderTheme renderTheme) {
TileRendererLayer tileRendererLayer = new TileRendererLayer(tileCache, mapFile,
- mapViewPosition, AndroidGraphicFactory.INSTANCE, null);
+ mapViewPosition, AndroidGraphicFactory.INSTANCE);
tileRendererLayer.setXmlRenderTheme(renderTheme);
return tileRendererLayer;
}
/**
- * Utility method to create a standard tile renderer layer.
+ * Utility method to create a standard tile renderer layer (without hillshading).
*
* @param tileCache the cache
* @param mapViewPosition the position
@@ -263,27 +264,29 @@ public static TileRendererLayer createTileRendererLayer(
}
/**
- * Utility method to create a tile renderer layer with hillshading.
+ * Utility method to create a tile renderer layer.
*
- * @param tileCache the cache
- * @param mapViewPosition the position
- * @param mapFile the map file
- * @param renderTheme the render theme to use
- * @param hasAlpha if the layer is transparent (more memory)
- * @param renderLabels should usually be true
- * @param cacheLabels should usually be false
+ * @param tileCache the cache
+ * @param mapViewPosition the position
+ * @param mapFile the map file
+ * @param renderTheme the render theme to use
+ * @param hasAlpha if the layer is transparent (more memory)
+ * @param renderLabels should usually be true
+ * @param cacheLabels should usually be false
* @param hillsRenderConfig may be null to omit hillshading
* @return the layer
*/
- public static TileRendererLayer createTileRendererLayerWithHillshading(
+ public static TileRendererLayer createTileRendererLayer(
TileCache tileCache, MapViewPosition mapViewPosition,
MapDataStore mapFile, XmlRenderTheme renderTheme, boolean hasAlpha,
boolean renderLabels, boolean cacheLabels, HillsRenderConfig hillsRenderConfig) {
TileRendererLayer tileRendererLayer = new TileRendererLayer(tileCache, mapFile,
- mapViewPosition, hasAlpha, renderLabels, cacheLabels, AndroidGraphicFactory.INSTANCE, hillsRenderConfig);
+ mapViewPosition, hasAlpha, renderLabels, cacheLabels, AndroidGraphicFactory.INSTANCE,
+ hillsRenderConfig);
tileRendererLayer.setXmlRenderTheme(renderTheme);
return tileRendererLayer;
}
+
/**
* @return true if the current thread is the UI thread, false otherwise.
*/
@@ -2,6 +2,7 @@
* Copyright 2010, 2011, 2012, 2013 mapsforge.org
* Copyright 2013-2014 Ludwig M Brinckmann
* Copyright 2014-2016 devemux86
+ * Copyright 2017 usrusr
*
* 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
@@ -155,7 +156,7 @@ protected void createSharedPreferences() {
*
* @return the fallback initial position of the mapview.
*/
- protected org.mapsforge.core.model.MapPosition getDefaultInitialPosition() {
+ protected MapPosition getDefaultInitialPosition() {
return new MapPosition(new LatLong(0, 0), getZoomLevelDefault());
}
@@ -339,7 +340,8 @@ protected MapView getMapView() {
}
/**
- * override to enable hill shading
+ * Override to enable hill shading.
+ *
* @return null or the HillsRenderConfig to use (defining height model path and algorithm)
*/
protected HillsRenderConfig getHillsRenderConfig() {
@@ -1,6 +1,7 @@
/*
* Copyright 2010, 2011, 2012, 2013 mapsforge.org
* Copyright 2014-2016 devemux86
+ * Copyright 2017 usrusr
*
* 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
@@ -52,34 +53,38 @@
private BufferedImageOp grayscaleOp, invertOp, invertOp4;
private static Map.Entry<Float, Composite> sizeOneShadingCompositeCache = null;
- private static Composite getHillshadingComposite(float magnitude){
+
+ private static Composite getHillshadingComposite(float magnitude) {
Map.Entry<Float, Composite> existing = sizeOneShadingCompositeCache;
- if(existing!=null && existing.getKey()==magnitude){
- // JMM says: "A thread-safe immutable object is seen as immutable by all threads, even if a data race is used to pass references to the immutable object between threads"
+ if (existing != null && existing.getKey() == magnitude) {
+ // JMM says: "A thread-safe immutable object is seen as immutable by all threads, even
+ // if a data race is used to pass references to the immutable object between threads"
// worst case we construct more than strictly needed
return existing.getValue();
}
Composite selected = selectHillShadingComposite(magnitude);
- if(sizeOneShadingCompositeCache==null) {
- // only cache the first magnitude value, in the rare instance that more than one magnitude value would be used
- // in a process lifecycle it would be better to create new Composite instances than create new instances _and_ new cache entries
+ if (sizeOneShadingCompositeCache == null) {
+ // only cache the first magnitude value, in the rare instance that more than one
+ // magnitude value would be used in a process lifecycle it would be better to create
+ // new Composite instances than create new instances _and_ new cache entries
sizeOneShadingCompositeCache = new AbstractMap.SimpleImmutableEntry(magnitude, selected);
}
return selected;
}
- /** composite selection,
- * select between {@link AlphaComposite} (fast, squashes saturation at high magnitude)
- * and {@link AwtLuminanceShadingComposite} (per-pixel rgb->hsv->rgb conversion to keep saturation at high magnitude, might be a bit slow and/or inconsistent with the android implementation) */
+
+ /**
+ * Composite selection, select between {@link AlphaComposite} (fast, squashes saturation at high magnitude)
+ * and {@link AwtLuminanceShadingComposite} (per-pixel rgb->hsv->rgb conversion to keep saturation at high magnitude,
+ * might be a bit slow and/or inconsistent with the android implementation)
+ */
private static Composite selectHillShadingComposite(float magnitude) {
return new AwtLuminanceShadingComposite(magnitude);
// return AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, magnitude);
}
-
-
AwtCanvas() {
createFilters();
}
@@ -169,24 +174,6 @@ public void drawBitmap(Bitmap bitmap, Matrix matrix) {
AwtGraphicFactory.getAffineTransform(matrix));
}
- @Override
- public void shadeBitmap(Bitmap bitmap, Rectangle shadeRect, Rectangle tileRect, float magnitude) {
- Composite oldComposite = this.graphics2D.getComposite();
- Composite composite = getHillshadingComposite(magnitude);
-
- this.graphics2D.setComposite(composite);
- BufferedImage bufferedImage = AwtGraphicFactory.getBufferedImage(bitmap);
-
- this.graphics2D.drawImage(bufferedImage
- , (int)tileRect.left, (int)tileRect.top, (int)tileRect.right, (int)tileRect.bottom
- , (int)shadeRect.left, (int)shadeRect.top, (int)shadeRect.right, (int)shadeRect.bottom
- , null);
-
-
- this.graphics2D.setComposite(oldComposite);
- }
-
-
@Override
public void drawBitmap(Bitmap bitmap, Matrix matrix, Filter filter) {
this.graphics2D.drawRenderedImage(applyFilter(AwtGraphicFactory.getBufferedImage(bitmap), filter), AwtGraphicFactory.getAffineTransform(matrix));
@@ -357,6 +344,22 @@ public void setClipDifference(int left, int top, int width, int height) {
this.graphics2D.setClip(clip);
}
+ @Override
+ public void shadeBitmap(Bitmap bitmap, Rectangle shadeRect, Rectangle tileRect, float magnitude) {
+ Composite oldComposite = this.graphics2D.getComposite();
+ Composite composite = getHillshadingComposite(magnitude);
+
+ this.graphics2D.setComposite(composite);
+ BufferedImage bufferedImage = AwtGraphicFactory.getBufferedImage(bitmap);
+
+ this.graphics2D.drawImage(bufferedImage,
+ (int) tileRect.left, (int) tileRect.top, (int) tileRect.right, (int) tileRect.bottom,
+ (int) shadeRect.left, (int) shadeRect.top, (int) shadeRect.right, (int) shadeRect.bottom,
+ null);
+
+ this.graphics2D.setComposite(oldComposite);
+ }
+
private void enableAntiAliasing() {
this.graphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
this.graphics2D.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
Oops, something went wrong.

0 comments on commit 1928ec9

Please sign in to comment.