Changeset 22779 in osm for applications


Ignore:
Timestamp:
2010-08-26T07:56:39+02:00 (14 years ago)
Author:
jttt
Message:
  • do not redraw when nothing changed
  • resize GeorefImage array when necessary (for large screens)
  • keep resized images as SoftReference
Location:
applications/editors/josm/plugins/wmsplugin
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/wmsplugin/.classpath

    r22677 r22779  
    33        <classpathentry kind="src" path="src"/>
    44        <classpathentry including="images/" kind="src" path=""/>
    5         <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
     5        <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JDK 6"/>
    66        <classpathentry combineaccessrules="false" kind="src" path="/JOSM"/>
    77        <classpathentry combineaccessrules="false" kind="src" path="/remotecontrol"/>
  • applications/editors/josm/plugins/wmsplugin/src/wmsplugin/GeorefImage.java

    r22712 r22779  
    1313import java.io.ObjectOutputStream;
    1414import java.io.Serializable;
     15import java.lang.ref.SoftReference;
    1516
    1617import javax.imageio.ImageIO;
     
    2829
    2930        private BufferedImage image;
    30         private BufferedImage reImg = null;
     31        private SoftReference<BufferedImage> reImg;
    3132        private int xIndex;
    3233        private int yIndex;
     
    5152                        this.yIndex = yIndex;
    5253                        this.image = null;
    53                         this.reImg = null;
     54                        flushedResizedCachedInstance();
    5455                }
    5556        }
     
    6061
    6162        public void changeImage(State state, BufferedImage image) {
     63                flushedResizedCachedInstance();
    6264                this.image = image;
    63                 this.reImg = null;
    6465                this.state = state;
    6566
     
    126127                        return false;
    127128
    128                 if(reImg != null && reImg.getWidth() == width && reImg.getHeight() == height) {
    129                         g.drawImage(reImg, x, y, null);
     129                BufferedImage img = reImg == null?null:reImg.get();
     130                if(img != null && img.getWidth() == width && img.getHeight() == height) {
     131                        g.drawImage(img, x, y, null);
    130132                        return true;
    131133                }
     
    134136
    135137                try {
    136                         if(reImg != null) reImg.flush();
     138                        if(img != null) img.flush();
    137139                        long freeMem = Runtime.getRuntime().maxMemory() - Runtime.getRuntime().totalMemory();
    138140                        //System.out.println("Free Memory:           "+ (freeMem/1024/1024) +" MB");
     
    149151                        } else {
    150152                                // We haven't got a saved resized copy, so resize and cache it
    151                                 reImg = new BufferedImage(width, height, alphaChannel?BufferedImage.TYPE_INT_ARGB:BufferedImage.TYPE_3BYTE_BGR);
    152                                 reImg.getGraphics().drawImage(getImage(),
     153                                img = new BufferedImage(width, height, alphaChannel?BufferedImage.TYPE_INT_ARGB:BufferedImage.TYPE_3BYTE_BGR);
     154                                img.getGraphics().drawImage(getImage(),
    153155                                                0, 0, width, height, // dest
    154156                                                0, 0, getImage().getWidth(null), getImage().getHeight(null), // src
    155157                                                null);
    156                                 reImg.getGraphics().dispose();
    157                                 g.drawImage(reImg, x, y, null);
     158                                img.getGraphics().dispose();
     159                                g.drawImage(img, x, y, null);
     160                                reImg = new SoftReference<BufferedImage>(img);
    158161                        }
    159162                } catch(Exception e) {
     
    164167
    165168        private void fallbackDraw(Graphics g, Image img, int x, int y, int width, int height) {
    166                 if(reImg != null) {
    167                         reImg.flush();
    168                         reImg = null;
    169                 }
     169                flushedResizedCachedInstance();
    170170                g.drawImage(
    171171                                img, x, y, x + width, y + height,
     
    195195
    196196        public void flushedResizedCachedInstance() {
     197                if (reImg != null) {
     198                        BufferedImage img = reImg.get();
     199                        if (img != null) {
     200                                img.flush();
     201                        }
     202                }
    197203                reImg = null;
    198204        }
  • applications/editors/josm/plugins/wmsplugin/src/wmsplugin/WMSLayer.java

    r22720 r22779  
    6161        protected MapView mv;
    6262        protected String resolution;
    63         protected boolean stopAfterPaint = false;
    6463        protected int imageSize = 500;
    6564        protected int dax = 10;
    6665        protected int day = 10;
     66        protected int daStep = 5;
    6767        protected int minZoom = 3;
     68
     69        protected boolean deltaChanged;
    6870        protected double dx = 0.0;
    6971        protected double dy = 0.0;
     72
    7073        protected double pixelPerDegree;
    71         protected GeorefImage[][] images = new GeorefImage[dax][day];
     74        protected GeorefImage[][] images;
    7275        protected String baseURL;
    7376        protected String cookies;
     
    152155
    153156        public void initializeImages() {
     157                GeorefImage[][] old = images;
    154158                images = new GeorefImage[dax][day];
     159                if (old != null) {
     160                        for (int i=0; i<old.length; i++) {
     161                                for (int k=0; k<old[i].length; k++) {
     162                                        GeorefImage o = old[i][k];
     163                                        images[modulo(o.getXIndex(),dax)][modulo(o.getYIndex(),day)] = old[i][k];
     164                                }
     165                        }
     166                }
    155167                for(int x = 0; x<dax; ++x) {
    156168                        for(int y = 0; y<day; ++y) {
    157                                 images[x][y]= new GeorefImage(this);
     169                                if (images[x][y] == null) {
     170                                        images[x][y]= new GeorefImage(this);
     171                                }
    158172                        }
    159173                }
     
    188202
    189203        @Override public void paint(Graphics2D g, final MapView mv, Bounds b) {
     204                deltaChanged = false;
    190205                if(baseURL == null) return;
    191206                if (usesInvalidUrl && !isInvalidUrlConfirmed) return;
     
    246261
    247262        public void displace(double dx, double dy) {
     263                deltaChanged = true;
    248264                this.dx += dx;
    249265                this.dy += dy;
     
    278294
    279295        protected void downloadAndPaintVisible(Graphics g, final MapView mv, boolean real){
     296
     297                int newDax = dax;
     298                int newDay = day;
     299
     300                if (bmaxx - bminx >= dax || bmaxx - bminx < dax - 2 * daStep) {
     301                        newDax = ((bmaxx - bminx) / daStep + 1) * daStep;
     302                }
     303
     304                if (bmaxy - bminy >= day || bmaxy - bminx < day - 2 * daStep) {
     305                        newDay = ((bmaxy - bminy) / daStep + 1) * daStep;
     306                }
     307
     308                if (newDax != dax || newDay != day) {
     309                        dax = newDax;
     310                        day = newDay;
     311                        initializeImages();
     312                }
    280313
    281314                for(int x = bminx; x<=bmaxx; ++x) {
     
    706739        }
    707740
     741        @Override
     742        public boolean isChanged() {
     743                requestQueueLock.lock();
     744                try {
     745                        return !finishedRequests.isEmpty() || deltaChanged;
     746                } finally {
     747                        requestQueueLock.unlock();
     748                }
     749        }
     750
    708751        public void preferenceChanged(PreferenceChangeEvent event) {
    709752                if (event.getKey().equals(WMSPlugin.PROP_SIMULTANEOUS_CONNECTIONS.getKey())) {
Note: See TracChangeset for help on using the changeset viewer.