Ticket #2752: wms_memory_usage.patch
| File wms_memory_usage.patch, 2.9 KB (added by , 16 years ago) |
|---|
-
src/wmsplugin/GeorefImage.java
4 4 import java.awt.Graphics; 5 5 import java.awt.Image; 6 6 import java.awt.Point; 7 import java.awt.Toolkit;8 7 import java.awt.image.BufferedImage; 9 import java.awt.image.FilteredImageSource;10 import java.awt.image.ImageProducer;11 import java.awt.image.RGBImageFilter;12 8 import java.io.IOException; 13 9 import java.io.ObjectInputStream; 14 10 import java.io.ObjectOutputStream; … … 86 82 } 87 83 88 84 boolean alphaChannel = Main.pref.getBoolean("wmsplugin.alpha_channel"); 89 // We don't need this, as simply saving the image to RGB instead of ARGB removes alpha90 // But we do get a black instead of white background.91 //Image ppImg = image;92 /*if(!alphaChannel) {93 // set alpha value to 25594 ppImg = clearAlpha(image);95 }*/96 85 97 86 try { 98 87 if(reImg != null) reImg.flush(); … … 101 90 // Notice that this value can get negative due to integer overflows 102 91 //System.out.println("Img Size: "+ (width*height*3/1024/1024) +" MB"); 103 92 93 int multipl = alphaChannel ? 4 : 3; 104 94 // This happens when requesting images while zoomed out and then zooming in 105 95 // Storing images this large in memory will certainly hang up JOSM. Luckily 106 96 // traditional rendering is as fast at these zoom levels, so it's no loss. 107 97 // Also prevent caching if we're out of memory soon 108 if(width > 10000 || height > 10000 || width*height*3> freeMem) {98 if(width > 2000 || height > 2000 || width*height*multipl > freeMem) { 109 99 fallbackDraw(g, image, minPt, maxPt); 110 100 } else { 111 101 // We haven't got a saved resized copy, so resize and cache it 112 102 reImg = new BufferedImage(width, height, 113 103 alphaChannel 114 104 ? BufferedImage.TYPE_INT_ARGB 115 : BufferedImage.TYPE_3BYTE_BGR // This removes alpha , too105 : BufferedImage.TYPE_3BYTE_BGR // This removes alpha 116 106 ); 117 107 reImg.getGraphics().drawImage(image, 118 108 0, 0, width, height, // dest … … 164 154 } 165 155 } 166 156 167 private Image clearAlpha(Image img) {168 ImageProducer ip = img.getSource();169 RGBImageFilter filter = new RGBImageFilter() {170 @Override171 public int filterRGB(int x, int y, int rgb) {172 return rgb | 0xff000000;173 }174 };175 ImageProducer filt_ip = new FilteredImageSource(ip, filter);176 Image out_img = Toolkit.getDefaultToolkit().createImage(filt_ip);177 178 return out_img;179 }180 181 157 public void flushedResizedCachedInstance() { 182 158 reImg = null; 183 159 }
