Skip to content

Commit 77331a9

Browse files
committed
Merge remote-tracking branch 'origin/develop' into develop
2 parents a08266f + cb26c20 commit 77331a9

14 files changed

Lines changed: 287 additions & 164 deletions

File tree

worldwind-examples/src/main/java/gov/nasa/worldwindx/experimental/AtmosphereLayer.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@
1313
import java.nio.ShortBuffer;
1414
import java.util.Arrays;
1515

16+
import gov.nasa.worldwind.WorldWind;
1617
import gov.nasa.worldwind.geom.Location;
1718
import gov.nasa.worldwind.geom.Sector;
1819
import gov.nasa.worldwind.geom.Vec3;
1920
import gov.nasa.worldwind.layer.AbstractLayer;
2021
import gov.nasa.worldwind.render.BufferObject;
22+
import gov.nasa.worldwind.render.ImageOptions;
2123
import gov.nasa.worldwind.render.ImageSource;
2224
import gov.nasa.worldwind.render.RenderContext;
2325
import gov.nasa.worldwind.util.Pool;
@@ -27,6 +29,8 @@ public class AtmosphereLayer extends AbstractLayer {
2729

2830
protected ImageSource nightImageSource;
2931

32+
protected ImageOptions nightImageOptions;
33+
3034
protected Location lightLocation;
3135

3236
protected Vec3 activeLightDirection = new Vec3();
@@ -41,18 +45,27 @@ public AtmosphereLayer() {
4145
this.setDisplayName("Atmosphere");
4246
this.setPickEnabled(false);
4347
this.nightImageSource = ImageSource.fromResource(R.drawable.dnb_land_ocean_ice_2012);
48+
this.nightImageOptions = ImageOptions.fromImageFormat(WorldWind.IMAGE_FORMAT_RGB_565);
4449
}
4550

4651
public ImageSource getNightImageSource() {
47-
return nightImageSource;
52+
return this.nightImageSource;
4853
}
4954

5055
public void setNightImageSource(ImageSource nightImageSource) {
5156
this.nightImageSource = nightImageSource;
5257
}
5358

59+
public ImageOptions getNightImageOptions() {
60+
return this.nightImageOptions;
61+
}
62+
63+
public void setNightImageOptions(ImageOptions nightImageOptions) {
64+
this.nightImageOptions = nightImageOptions;
65+
}
66+
5467
public Location getLightLocation() {
55-
return lightLocation;
68+
return this.lightLocation;
5669
}
5770

5871
public void setLightLocation(Location location) {
@@ -129,7 +142,7 @@ protected void renderGround(RenderContext rc) {
129142
if (this.nightImageSource != null && this.lightLocation != null) {
130143
drawable.nightTexture = rc.getTexture(this.nightImageSource);
131144
if (drawable.nightTexture == null) {
132-
drawable.nightTexture = rc.retrieveTexture(this.nightImageSource);
145+
drawable.nightTexture = rc.retrieveTexture(this.nightImageSource, this.nightImageOptions);
133146
}
134147
} else {
135148
drawable.nightTexture = null;

worldwind/src/main/java/gov/nasa/worldwind/WorldWind.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,28 @@ public class WorldWind {
133133

134134
}
135135

136+
/**
137+
* {@link ImageFormat} constant indicating 32-bit RGBA_8888 image format.
138+
*/
139+
public static final int IMAGE_FORMAT_RGBA_8888 = 0;
140+
141+
/**
142+
* {@link ImageFormat} constant indicating 16-bit RGBA_565 image format.
143+
*/
144+
public static final int IMAGE_FORMAT_RGB_565 = 1;
145+
146+
/**
147+
* Image format indicates the in-memory representation for images displayed by World Wind components. Images are
148+
* typically represented in the 32-bit RGBA_8888 format, the highest quality available. Components that do not
149+
* require an alpha channel and want to conserve memory may use the 16-bit RGBA_565 format. Accepted values are
150+
* {@link #IMAGE_FORMAT_RGBA_8888} and {@link #IMAGE_FORMAT_RGB_565}.
151+
*/
152+
@IntDef({IMAGE_FORMAT_RGBA_8888, IMAGE_FORMAT_RGB_565})
153+
@Retention(RetentionPolicy.SOURCE)
154+
public @interface ImageFormat {
155+
156+
}
157+
136158
/**
137159
* {@link NavigatorAction} constant indicating that the navigator has moved.
138160
*/

worldwind/src/main/java/gov/nasa/worldwind/layer/BackgroundLayer.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
package gov.nasa.worldwind.layer;
77

88
import gov.nasa.worldwind.R;
9+
import gov.nasa.worldwind.WorldWind;
910
import gov.nasa.worldwind.geom.Sector;
11+
import gov.nasa.worldwind.render.ImageOptions;
1012
import gov.nasa.worldwind.render.ImageSource;
1113
import gov.nasa.worldwind.shape.SurfaceImage;
1214
import gov.nasa.worldwind.util.Logger;
@@ -24,18 +26,19 @@ public class BackgroundLayer extends RenderableLayer {
2426
* associated with the World Window.
2527
*/
2628
public BackgroundLayer() {
27-
this(ImageSource.fromResource(R.drawable.gov_nasa_worldwind_worldtopobathy2004053));
29+
this(ImageSource.fromResource(R.drawable.gov_nasa_worldwind_worldtopobathy2004053), ImageOptions.fromImageFormat(WorldWind.IMAGE_FORMAT_RGB_565));
2830
}
2931

3032
/**
3133
* Constructs a background image layer with an image source. The image's dimensions must be no greater than 2048 x
3234
* 2048.
3335
*
34-
* @param imageSource the image source
36+
* @param imageSource the image source
37+
* @param imageOptions the image options, or null to use the default options
3538
*
3639
* @throws IllegalArgumentException If the image source is null
3740
*/
38-
public BackgroundLayer(ImageSource imageSource) {
41+
public BackgroundLayer(ImageSource imageSource, ImageOptions imageOptions) {
3942
if (imageSource == null) {
4043
throw new IllegalArgumentException(
4144
Logger.logMessage(Logger.ERROR, "BackgroundLayer", "constructor", "missingSource"));
@@ -47,6 +50,8 @@ public BackgroundLayer(ImageSource imageSource) {
4750
this.setPickEnabled(false);
4851

4952
// Delegate display to the SurfaceImage shape.
50-
this.addRenderable(new SurfaceImage(new Sector().setFullSphere(), imageSource));
53+
SurfaceImage surfaceImage = new SurfaceImage(new Sector().setFullSphere(), imageSource);
54+
surfaceImage.setImageOptions(imageOptions);
55+
this.addRenderable(surfaceImage);
5156
}
5257
}

worldwind/src/main/java/gov/nasa/worldwind/layer/BlueMarbleLandsatLayer.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import gov.nasa.worldwind.WorldWind;
99
import gov.nasa.worldwind.ogc.WmsGetMapUrlFactory;
1010
import gov.nasa.worldwind.ogc.WmsLayerConfig;
11+
import gov.nasa.worldwind.render.ImageOptions;
1112
import gov.nasa.worldwind.util.LevelSet;
1213
import gov.nasa.worldwind.util.LevelSetConfig;
1314
import gov.nasa.worldwind.util.Logger;
@@ -63,6 +64,10 @@ public BlueMarbleLandsatLayer(String serviceAddress) {
6364
landsatConfig.transparent = false; // combining BlueMarble and esat layers results in opaque images
6465
this.landsatUrlFactory = new WmsGetMapUrlFactory(landsatConfig);
6566

67+
// Configure this layer's image options to reduce memory usage by using a 16-bit format with no alpha.
68+
ImageOptions imageOptions = new ImageOptions();
69+
imageOptions.imageFormat = WorldWind.IMAGE_FORMAT_RGB_565;
70+
6671
// Configure this layer's level set to capture the entire globe at 15m resolution.
6772
double metersPerPixel = 15;
6873
double radiansPerPixel = metersPerPixel / WorldWind.WGS84_SEMI_MAJOR_AXIS;
@@ -73,6 +78,7 @@ public BlueMarbleLandsatLayer(String serviceAddress) {
7378
this.setLevelSet(new LevelSet(levelsConfig));
7479
this.setTileUrlFactory(this);
7580
this.setImageFormat("image/png");
81+
this.setImageOptions(imageOptions);
7682
}
7783

7884
@Override

worldwind/src/main/java/gov/nasa/worldwind/layer/BlueMarbleLayer.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55

66
package gov.nasa.worldwind.layer;
77

8+
import gov.nasa.worldwind.WorldWind;
89
import gov.nasa.worldwind.geom.Sector;
910
import gov.nasa.worldwind.ogc.WmsLayer;
1011
import gov.nasa.worldwind.ogc.WmsLayerConfig;
12+
import gov.nasa.worldwind.render.ImageOptions;
1113
import gov.nasa.worldwind.util.Logger;
1214

1315
/**
@@ -46,7 +48,11 @@ public BlueMarbleLayer(String serviceAddress) {
4648
config.coordinateSystem = "EPSG:4326";
4749
config.transparent = false; // the BlueMarble layer is opaque
4850

51+
ImageOptions imageOptions = new ImageOptions();
52+
imageOptions.imageFormat = WorldWind.IMAGE_FORMAT_RGB_565; // exploit opaque imagery to reduce memory usage
53+
4954
this.setDisplayName("Blue Marble");
5055
this.setConfiguration(new Sector().setFullSphere(), 500, config); // 500m resolution on Earth
56+
this.setImageOptions(imageOptions);
5157
}
5258
}

worldwind/src/main/java/gov/nasa/worldwind/layer/TiledImageLayer.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import gov.nasa.worldwind.draw.DrawableSurfaceTexture;
1313
import gov.nasa.worldwind.geom.Matrix3;
1414
import gov.nasa.worldwind.geom.Sector;
15+
import gov.nasa.worldwind.render.ImageOptions;
1516
import gov.nasa.worldwind.render.ImageSource;
1617
import gov.nasa.worldwind.render.ImageTile;
1718
import gov.nasa.worldwind.render.RenderContext;
@@ -34,6 +35,8 @@ public class TiledImageLayer extends AbstractLayer implements TileFactory {
3435

3536
protected String imageFormat;
3637

38+
protected ImageOptions imageOptions;
39+
3740
protected double detailControl = 4;
3841

3942
protected List<Tile> topLevelTiles = new ArrayList<>();
@@ -78,7 +81,7 @@ public void setLevelSet(LevelSet levelSet) {
7881
}
7982

8083
protected TileUrlFactory getTileUrlFactory() {
81-
return tileUrlFactory;
84+
return this.tileUrlFactory;
8285
}
8386

8487
protected void setTileUrlFactory(TileUrlFactory tileUrlFactory) {
@@ -87,16 +90,25 @@ protected void setTileUrlFactory(TileUrlFactory tileUrlFactory) {
8790
}
8891

8992
protected String getImageFormat() {
90-
return imageFormat;
93+
return this.imageFormat;
9194
}
9295

9396
protected void setImageFormat(String imageFormat) {
9497
this.imageFormat = imageFormat;
9598
this.invalidateTiles();
9699
}
97100

101+
public ImageOptions getImageOptions() {
102+
return this.imageOptions;
103+
}
104+
105+
public void setImageOptions(ImageOptions imageOptions) {
106+
this.imageOptions = imageOptions;
107+
this.invalidateTiles();
108+
}
109+
98110
public double getDetailControl() {
99-
return detailControl;
111+
return this.detailControl;
100112
}
101113

102114
public void setDetailControl(double detailControl) {
@@ -184,7 +196,7 @@ protected void addTileOrDescendants(RenderContext rc, ImageTile tile) {
184196
protected void addTile(RenderContext rc, ImageTile tile) {
185197
Texture texture = rc.getTexture(tile.getImageSource()); // try to get the texture from the cache
186198
if (texture == null) {
187-
texture = rc.retrieveTexture(tile.getImageSource()); // puts retrieved textures in the cache
199+
texture = rc.retrieveTexture(tile.getImageSource(), this.imageOptions); // puts retrieved textures in the cache
188200
}
189201

190202
if (texture != null) { // use the tile's own texture
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright (c) 2016 United States Government as represented by the Administrator of the
3+
* National Aeronautics and Space Administration. All Rights Reserved.
4+
*/
5+
6+
package gov.nasa.worldwind.render;
7+
8+
import gov.nasa.worldwind.WorldWind;
9+
10+
/**
11+
* Options for images displayed by World Wind components.
12+
*/
13+
public class ImageOptions {
14+
15+
/**
16+
* Indicates the in-memory representation for images displayed by World Wind components. By default, images are
17+
* represented in the 32-bit RGBA_8888 format, the highest quality available. Components that do not require an
18+
* alpha channel and want to conserve memory may use the 16-bit RGBA_565 format. Accepted values are {@link
19+
* WorldWind#IMAGE_FORMAT_RGBA_8888} and {@link WorldWind#IMAGE_FORMAT_RGB_565}.
20+
*/
21+
@WorldWind.ImageFormat
22+
public int imageFormat = WorldWind.IMAGE_FORMAT_RGBA_8888;
23+
24+
/**
25+
* Constructs an image options with default values.
26+
*/
27+
public ImageOptions() {
28+
}
29+
30+
/**
31+
* Constructs an image options with an image format.
32+
*
33+
* @param imageFormat the image format to use. Accepted values are {@link WorldWind#IMAGE_FORMAT_RGBA_8888} and
34+
* {@link WorldWind#IMAGE_FORMAT_RGB_565}.
35+
*
36+
* @return the new image options
37+
*/
38+
public static ImageOptions fromImageFormat(@WorldWind.ImageFormat int imageFormat) {
39+
ImageOptions imageOptions = new ImageOptions();
40+
imageOptions.imageFormat = imageFormat;
41+
return imageOptions;
42+
}
43+
}

0 commit comments

Comments
 (0)