Changeset 13673 in osm for applications/editors/josm/plugins/wmsplugin/src
- Timestamp:
- 2009-02-12T09:24:58+01:00 (16 years ago)
- Location:
- applications/editors/josm/plugins/wmsplugin/src/wmsplugin
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/wmsplugin/src/wmsplugin/GeorefImage.java
r13667 r13673 58 58 return false; 59 59 } 60 60 61 61 // Width and height flicker about 2 pixels due to rounding errors, typically only 1 62 62 int width = Math.abs(maxPt.x-minPt.x); … … 64 64 int diffx = reImgHash.width - width; 65 65 int diffy = reImgHash.height - height; 66 66 67 67 // This happens if you zoom outside the world 68 68 if(width == 0 || height == 0) 69 69 return false; 70 70 71 71 // We still need to re-render if the requested size is larger (otherwise we'll have black lines) 72 72 // If it's only up to two pixels smaller, just draw the old image, the errors are minimal … … 79 79 80 80 boolean alphaChannel = Main.pref.getBoolean("wmsplugin.alpha_channel"); 81 Image ppImg = image; 82 if(!alphaChannel) { 81 // We don't need this, as simply saving the image to RGB instead of ARGB removes alpha 82 // But we do get a black instead of white background. 83 //Image ppImg = image; 84 /*if(!alphaChannel) { 83 85 // set alpha value to 255 84 86 ppImg = clearAlpha(image); 87 }*/ 88 89 try { 90 if(reImg != null) reImg.flush(); 91 long freeMem = Runtime.getRuntime().maxMemory() - Runtime.getRuntime().totalMemory(); 92 //System.out.println("Free Memory: "+ (freeMem/1024/1024) +" MB"); 93 // Notice that this value can get negative due to integer overflows 94 //System.out.println("Img Size: "+ (width*height*3/1024/1024) +" MB"); 95 96 // This happens when requesting images while zoomed out and then zooming in 97 // Storing images this large in memory will certainly hang up JOSM. Luckily 98 // traditional rendering is as fast at these zoom levels, so it's no loss. 99 // Also prevent caching if we're out of memory soon 100 if(width > 10000 || height > 10000 || width*height*3 > freeMem) { 101 fallbackDraw(g, image, minPt, maxPt); 102 } else { 103 // We haven't got a saved resized copy, so resize and cache it 104 reImg = new BufferedImage(width, height, 105 alphaChannel 106 ? BufferedImage.TYPE_INT_ARGB 107 : BufferedImage.TYPE_3BYTE_BGR // This removes alpha, too 108 ); 109 reImg.getGraphics().drawImage(image, 110 0, 0, width, height, // dest 111 0, 0, image.getWidth(null), image.getHeight(null), // src 112 null); 113 reImg.getGraphics().dispose(); 114 115 reImgHash.setSize(width, height); 116 g.drawImage(reImg, minPt.x, maxPt.y, null); 117 } 118 } catch(Exception e) { 119 fallbackDraw(g, image, minPt, maxPt); 85 120 } 86 87 // We haven't got a saved resized copy, so resize and cache it 88 reImg = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); 89 reImg.getGraphics().drawImage(ppImg, 90 0, 0, width, height, // dest 91 0, 0, ppImg.getWidth(null), ppImg.getHeight(null), // src 121 return true; 122 } 123 124 private void fallbackDraw(Graphics g, Image img, Point min, Point max) { 125 if(reImg != null) reImg.flush(); 126 reImg = null; 127 g.drawImage(img, 128 min.x, max.y, max.x, min.y, // dest 129 0, 0, img.getWidth(null), img.getHeight(null), // src 92 130 null); 93 94 reImgHash.setSize(width, height);95 g.drawImage(reImg, minPt.x, maxPt.y, null);96 return true;97 131 } 98 132 … … 124 158 return out_img; 125 159 } 126 160 127 161 public void flushedResizedCachedInstance() { 128 162 reImg = null; -
applications/editors/josm/plugins/wmsplugin/src/wmsplugin/Grabber.java
r13667 r13673 53 53 g.drawString(tr("Exception occurred"), 10, height()/2); 54 54 image.image = img; 55 image.flushedResizedCachedInstance(); 55 56 image.failed = true; 56 57 g.setFont(font); -
applications/editors/josm/plugins/wmsplugin/src/wmsplugin/WMSGrabber.java
r13645 r13673 56 56 image.max = proj.latlon2eastNorth(b.max); 57 57 58 if(image.isVisible(mv)) //don't download, if the image isn't visible already58 if(image.isVisible(mv)) { //don't download, if the image isn't visible already 59 59 image.image = grab(url); 60 image.flushedResizedCachedInstance(); 61 } 60 62 image.downloadingStarted = false; 61 63 } catch(Exception e) { -
applications/editors/josm/plugins/wmsplugin/src/wmsplugin/WMSLayer.java
r13667 r13673 172 172 img.downloadingStarted = true; 173 173 img.image = null; 174 img.flushedResizedCachedInstance(); 174 175 Grabber gr = WMSPlugin.getGrabber(baseURL, XYtoBounds(x,y), Main.main.proj, pixelPerDegree, img, mv, this); 175 176 executor.submit(gr); … … 250 251 GeorefImage img = images[modulo(x,dax)][modulo(y,day)]; 251 252 img.image = null; 253 img.flushedResizedCachedInstance(); 252 254 img.downloadingStarted = false; 253 255 img.failed = false;
Note:
See TracChangeset
for help on using the changeset viewer.