Skip to content

Commit 6d01bab

Browse files
committed
Merge remote-tracking branch 'origin/feature/mercator' into feature/geopackage
# Conflicts: # worldwind/src/main/java/gov/nasa/worldwind/layer/mercator/MercatorImageTile.java # worldwind/src/main/java/gov/nasa/worldwind/layer/mercator/MercatorSector.java # worldwind/src/main/java/gov/nasa/worldwind/layer/mercator/MercatorTiledImageLayer.java # worldwind/src/main/java/gov/nasa/worldwind/render/ImageRetriever.java # worldwind/src/main/java/gov/nasa/worldwind/render/ImageSource.java
2 parents 99d1eab + 06ee66c commit 6d01bab

4 files changed

Lines changed: 36 additions & 30 deletions

File tree

worldwind/src/main/java/gov/nasa/worldwind/layer/mercator/MercatorImageTile.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
import java.util.Collection;
66

77
import gov.nasa.worldwind.geom.Location;
8-
import gov.nasa.worldwind.render.ImageSource;
98
import gov.nasa.worldwind.render.ImageTile;
9+
import gov.nasa.worldwind.util.DownloadPostprocessor;
1010
import gov.nasa.worldwind.util.Level;
1111
import gov.nasa.worldwind.util.LevelSet;
1212
import gov.nasa.worldwind.util.Logger;
1313
import gov.nasa.worldwind.util.Tile;
1414
import gov.nasa.worldwind.util.TileFactory;
1515

16-
class MercatorImageTile extends ImageTile implements ImageSource.Transformer {
16+
class MercatorImageTile extends ImageTile implements DownloadPostprocessor<Bitmap> {
1717

1818
/**
1919
* Constructs a tile with a specified sector, level, row and column.
@@ -125,22 +125,24 @@ public Tile[] subdivide(TileFactory tileFactory) {
125125
}
126126

127127
@Override
128-
public Bitmap transform(Bitmap bitmap) {
128+
public Bitmap process(Bitmap resource) {
129129
// Re-project mercator tile to equirectangular
130-
Bitmap trans = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), bitmap.getConfig());
130+
int[] pixels = new int[resource.getWidth() * resource.getHeight()];
131+
int[] result = new int[resource.getWidth() * resource.getHeight()];
132+
resource.getPixels(pixels, 0, resource.getWidth(), 0, 0, resource.getWidth(), resource.getHeight());
131133
double miny = ((MercatorSector) sector).minLatPercent();
132134
double maxy = ((MercatorSector) sector).maxLatPercent();
133-
for (int y = 0; y < bitmap.getHeight(); y++) {
134-
double sy = 1.0 - y / (double) (bitmap.getHeight() - 1);
135+
for (int y = 0; y < resource.getHeight(); y++) {
136+
double sy = 1.0 - y / (double) (resource.getHeight() - 1);
135137
double lat = sy * (sector.maxLatitude() - sector.minLatitude()) + sector.minLatitude();
136138
double dy = 1.0 - (MercatorSector.gudermannianInverse(lat) - miny) / (maxy - miny);
137139
dy = Math.max(0.0, Math.min(1.0, dy));
138-
int iy = (int) (dy * (bitmap.getHeight() - 1));
139-
for (int x = 0; x < bitmap.getWidth(); x++) {
140-
trans.setPixel(x, y, bitmap.getPixel(x, iy));
140+
int iy = (int) (dy * (resource.getHeight() - 1));
141+
for (int x = 0; x < resource.getWidth(); x++) {
142+
result[x + y * resource.getWidth()] = pixels[x + iy * resource.getWidth()];
141143
}
142144
}
143-
return trans;
145+
return Bitmap.createBitmap(result, resource.getWidth(), resource.getHeight(), resource.getConfig());
144146
}
145147

146148
}

worldwind/src/main/java/gov/nasa/worldwind/render/ImageRetriever.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import java.net.URLConnection;
1717

1818
import gov.nasa.worldwind.WorldWind;
19+
import gov.nasa.worldwind.util.DownloadPostprocessor;
1920
import gov.nasa.worldwind.util.Logger;
2021
import gov.nasa.worldwind.util.Retriever;
2122
import gov.nasa.worldwind.util.WWUtil;
@@ -72,7 +73,7 @@ protected Bitmap decodeImage(ImageSource imageSource, ImageOptions imageOptions)
7273
}
7374

7475
if (imageSource.isUrl()) {
75-
return this.decodeUrl(imageSource.asUrl(), imageOptions, imageSource.transformer);
76+
return this.decodeUrl(imageSource.asUrl(), imageOptions, imageSource.postprocessor);
7677
}
7778

7879
return this.decodeUnrecognized(imageSource);
@@ -88,7 +89,7 @@ protected Bitmap decodeFilePath(String pathName, ImageOptions imageOptions) {
8889
return BitmapFactory.decodeFile(pathName, factoryOptions);
8990
}
9091

91-
protected Bitmap decodeUrl(String urlString, ImageOptions imageOptions, ImageSource.Transformer transformer) throws IOException {
92+
protected Bitmap decodeUrl(String urlString, ImageOptions imageOptions, DownloadPostprocessor<Bitmap> postprocessor) throws IOException {
9293
// TODO establish a file caching service for remote resources
9394
// TODO retry absent resources, they are currently handled but suppressed entirely after the first failure
9495
// TODO configurable connect and read timeouts
@@ -105,8 +106,8 @@ protected Bitmap decodeUrl(String urlString, ImageOptions imageOptions, ImageSou
105106
Bitmap bitmap = BitmapFactory.decodeStream(stream, null, factoryOptions);
106107

107108
// Apply bitmap transformation if required
108-
if (transformer != null && bitmap != null) {
109-
bitmap = transformer.transform(bitmap);
109+
if (postprocessor != null && bitmap != null) {
110+
bitmap = postprocessor.process(bitmap);
110111
}
111112

112113
return bitmap;

worldwind/src/main/java/gov/nasa/worldwind/render/ImageSource.java

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import java.util.Arrays;
1313
import java.util.HashMap;
1414

15+
import gov.nasa.worldwind.util.DownloadPostprocessor;
1516
import gov.nasa.worldwind.util.Logger;
1617
import gov.nasa.worldwind.util.WWUtil;
1718

@@ -50,18 +51,6 @@ public interface BitmapFactory {
5051
Bitmap createBitmap();
5152
}
5253

53-
/**
54-
* Interface for remote image source post-transformation
55-
*/
56-
public interface Transformer {
57-
/**
58-
* Transforms image according to specified algorithm implementation
59-
* @param bitmap original bitmap
60-
* @return transformed bitmap
61-
*/
62-
Bitmap transform(Bitmap bitmap);
63-
}
64-
6554
protected static final HashMap<Object, BitmapFactory> lineStippleFactories = new HashMap<>();
6655

6756
protected static final int TYPE_UNRECOGNIZED = 0;
@@ -80,7 +69,7 @@ public interface Transformer {
8069

8170
protected Object source;
8271

83-
protected Transformer transformer;
72+
protected DownloadPostprocessor<Bitmap> postprocessor;
8473

8574
protected ImageSource() {
8675
}
@@ -192,15 +181,15 @@ public static ImageSource fromUrl(String urlString) {
192181
* application's manifest must include the permissions that allow network connections.
193182
*
194183
* @param urlString complete URL string
195-
* @param transformer implementation of image post-transformation routine
184+
* @param postprocessor implementation of image post-transformation routine
196185
*
197186
* @return the new image source
198187
*
199188
* @throws IllegalArgumentException If the URL string is null
200189
*/
201-
public static ImageSource fromUrl(String urlString, Transformer transformer) {
190+
public static ImageSource fromUrl(String urlString, DownloadPostprocessor<Bitmap> postprocessor) {
202191
ImageSource imageSource = fromUrl(urlString);
203-
imageSource.transformer = transformer;
192+
imageSource.postprocessor = postprocessor;
204193
return imageSource;
205194
}
206195

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package gov.nasa.worldwind.util;
2+
3+
/**
4+
* Interface for resource download post-processing
5+
*/
6+
public interface DownloadPostprocessor<T> {
7+
/**
8+
* Process resource according to specified algorithm implementation
9+
*
10+
* @param resource original resource
11+
* @return processed resource
12+
*/
13+
T process(T resource);
14+
}

0 commit comments

Comments
 (0)