Changeset 7132 in josm for trunk/src/org/openstreetmap/josm/data/imagery
- Timestamp:
- 2014-05-15T03:15:28+02:00 (10 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/data/imagery
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/imagery/GeorefImage.java
r7025 r7132 22 22 import org.openstreetmap.josm.gui.layer.ImageryLayer; 23 23 import org.openstreetmap.josm.gui.layer.WMSLayer; 24 import org.openstreetmap.josm.tools.ImageProvider; 24 25 25 26 public class GeorefImage implements Serializable { … … 46 47 return layer.getEastNorth(xIndex+1, yIndex+1); 47 48 } 48 49 49 50 50 public GeorefImage(WMSLayer layer) { … … 57 57 this.yIndex = yIndex; 58 58 this.image = null; 59 flush edResizedCachedInstance();59 flushResizedCachedInstance(); 60 60 } 61 61 } … … 65 65 } 66 66 67 /** 68 * Resets this image to initial state and release all resources being used. 69 * @since 7132 70 */ 71 public void resetImage() { 72 if (image != null) { 73 image.flush(); 74 } 75 changeImage(null, null); 76 } 77 67 78 public void changeImage(State state, BufferedImage image) { 68 flush edResizedCachedInstance();79 flushResizedCachedInstance(); 69 80 this.image = image; 70 81 this.state = state; 71 82 if (state == null) 83 return; 72 84 switch (state) { 73 85 case FAILED: … … 103 115 104 116 public boolean paint(Graphics g, NavigatableComponent nc, int xIndex, int yIndex, int leftEdge, int bottomEdge) { 105 if ( image== null)117 if (getImage() == null) 106 118 return false; 107 119 … … 174 186 175 187 private void fallbackDraw(Graphics g, Image img, int x, int y, int width, int height, boolean alphaChannel) { 176 flush edResizedCachedInstance();188 flushResizedCachedInstance(); 177 189 g.drawImage( 178 190 img, x, y, x + width, y + height, … … 195 207 boolean hasImage = in.readBoolean(); 196 208 if (hasImage) { 197 image = (ImageIO.read(ImageIO.createImageInputStream(in)));209 image = ImageProvider.read(ImageIO.createImageInputStream(in), true, WMSLayer.PROP_ALPHA_CHANNEL.get()); 198 210 } else { 199 211 in.readObject(); // read null from input stream … … 213 225 } 214 226 215 public void flush edResizedCachedInstance() {227 public void flushResizedCachedInstance() { 216 228 if (reImg != null) { 217 229 BufferedImage img = reImg.get(); … … 223 235 } 224 236 225 226 237 public BufferedImage getImage() { 227 238 return image; -
trunk/src/org/openstreetmap/josm/data/imagery/WmsCache.java
r7033 r7132 42 42 import org.openstreetmap.josm.data.preferences.StringProperty; 43 43 import org.openstreetmap.josm.data.projection.Projection; 44 import org.openstreetmap.josm.gui.layer.WMSLayer; 45 import org.openstreetmap.josm.tools.ImageProvider; 44 46 import org.openstreetmap.josm.tools.Utils; 45 47 … … 48 50 //TODO Property for maximum age of tile, automatically remove old tiles 49 51 //TODO Measure time for partially loading from cache, compare with time to download tile. If slower, disable partial cache 50 //TODO Do loading from partial cache and downloading at the same time, don't wait for parti cal cache to load52 //TODO Do loading from partial cache and downloading at the same time, don't wait for partial cache to load 51 53 52 54 private static final StringProperty PROP_CACHE_PATH = new StringProperty("imagery.wms-cache.path", "wms"); … … 70 72 this.bounds = new ProjectionBounds(east, north, east + tileSize / pixelPerDegree, north + tileSize / pixelPerDegree); 71 73 this.filename = filename; 74 } 75 76 @Override 77 public String toString() { 78 return "CacheEntry [pixelPerDegree=" + pixelPerDegree + ", east=" + east + ", north=" + north + ", bounds=" 79 + bounds + ", filename=" + filename + ", lastUsed=" + lastUsed + ", lastModified=" + lastModified 80 + "]"; 72 81 } 73 82 } … … 299 308 } 300 309 301 private BufferedImage loadImage(ProjectionEntries projectionEntries, CacheEntry entry) throws IOException { 302 310 private BufferedImage loadImage(ProjectionEntries projectionEntries, CacheEntry entry, boolean enforceTransparency) throws IOException { 303 311 synchronized (this) { 304 312 entry.lastUsed = System.currentTimeMillis(); … … 307 315 if (memCache != null) { 308 316 BufferedImage result = memCache.get(); 309 if (result != null) 310 return result; 317 if (result != null) { 318 if (enforceTransparency == ImageProvider.isTransparencyForced(result)) { 319 return result; 320 } else if (Main.isDebugEnabled()) { 321 Main.debug("Skipping "+entry+" from memory cache (transparency enforcement)"); 322 } 323 } 311 324 } 312 325 } … … 314 327 try { 315 328 // Reading can't be in synchronized section, it's too slow 316 BufferedImage result = Image IO.read(getImageFile(projectionEntries, entry));329 BufferedImage result = ImageProvider.read(getImageFile(projectionEntries, entry), true, enforceTransparency); 317 330 synchronized (this) { 318 331 if (result == null) { … … 354 367 if (entry != null) { 355 368 try { 356 return loadImage(projectionEntries, entry );369 return loadImage(projectionEntries, entry, WMSLayer.PROP_ALPHA_CHANNEL.get()); 357 370 } catch (IOException e) { 358 371 Main.error("Unable to load file from wms cache"); … … 364 377 } 365 378 366 public 379 public BufferedImage getPartialMatch(Projection projection, double pixelPerDegree, double east, double north) { 367 380 ProjectionEntries projectionEntries; 368 381 List<CacheEntry> matches; … … 390 403 return null; 391 404 392 393 405 Collections.sort(matches, new Comparator<CacheEntry>() { 394 406 @Override … … 399 411 } 400 412 401 //TODO Use alpha layer only when enabled on wms layer 402 BufferedImage result = new BufferedImage(tileSize, tileSize, BufferedImage.TYPE_4BYTE_ABGR); 413 // Use alpha layer only when enabled on wms layer 414 boolean alpha = WMSLayer.PROP_ALPHA_CHANNEL.get(); 415 BufferedImage result = new BufferedImage(tileSize, tileSize, 416 alpha ? BufferedImage.TYPE_4BYTE_ABGR : BufferedImage.TYPE_3BYTE_BGR); 403 417 Graphics2D g = result.createGraphics(); 404 405 418 406 419 boolean drawAtLeastOnce = false; … … 409 422 BufferedImage img; 410 423 try { 411 img = loadImage(projectionEntries, ce); 424 // Enforce transparency only when alpha enabled on wms layer too 425 img = loadImage(projectionEntries, ce, alpha); 412 426 localCache.put(ce, new SoftReference<>(img)); 413 427 } catch (IOException e) {
Note:
See TracChangeset
for help on using the changeset viewer.