Ticket #1954: CacheResizedImageInMemory.patch
File CacheResizedImageInMemory.patch, 2.5 KB (added by , 16 years ago) |
---|
-
src/wmsplugin/GeorefImage.java
1 1 package wmsplugin; 2 2 3 import java.awt.Dimension; 3 4 import java.awt.Graphics; 4 5 import java.awt.Point; 5 6 import java.awt.image.BufferedImage; … … 15 16 16 17 public class GeorefImage implements Serializable { 17 18 public BufferedImage image = null; 19 private BufferedImage reImg = null; 20 private Dimension reImgHash = new Dimension(0, 0); 18 21 public EastNorth min, max; 19 22 public boolean downloadingStarted; 20 23 … … 43 46 EastNorth ma = new EastNorth(max.east()+dx, max.north()+dy); 44 47 Point minPt = nc.getPoint(mi), maxPt = nc.getPoint(ma); 45 48 49 // downloadAndPaintVisible in WMSLayer.java requests visible images only 50 // so this path is never hit. 46 51 /* this is isVisible() but taking dx, dy into account */ 47 if(!(g.hitClip(minPt.x, maxPt.y, 48 maxPt.x - minPt.x, minPt.y - maxPt.y))) 52 /*if(!(g.hitClip(minPt.x, maxPt.y, maxPt.x - minPt.x, minPt.y - maxPt.y))) { 49 53 return false; 54 }*/ 55 56 // Width and height flicker about 2 pixels due to rounding errors, typically only 1 57 int width = Math.abs(maxPt.x-minPt.x); 58 int height = Math.abs(minPt.y-maxPt.y); 59 int diffx = reImgHash.width - width; 60 int diffy = reImgHash.height - height; 61 62 // We still need to re-render if the requested size is larger (otherwise we'll have black lines) 63 // If it's only up to two pixels smaller, just draw the old image, the errors are minimal 64 // but the performance improvements when moving are huge 65 // Zooming is still slow because the images need to be resized 66 if(diffx >= 0 && diffx <= 2 && diffy >= 0 && diffy <= 2 && reImg != null) { 67 g.drawImage(reImg, minPt.x, maxPt.y, null); 68 return true; 69 } 50 70 51 g.drawImage(image, 52 minPt.x, maxPt.y, maxPt.x, minPt.y, // dest 71 // We haven't got a saved resized copy, so resize and cache it 72 reImg = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); 73 reImg.getGraphics().drawImage(image, 74 0, 0, width, height, // dest 53 75 0, 0, image.getWidth(), image.getHeight(), // src 54 76 null); 55 77 78 reImgHash.setSize(width, height); 79 g.drawImage(reImg, minPt.x, maxPt.y, null); 56 80 return true; 57 81 } 58 82