Ticket #2752: wms_memory_usage.patch

File wms_memory_usage.patch, 2.9 KB (added by xeen, 3 years ago)

I mostly agree, however I'm strongly against making this customizeable. For one, users should not have to customize this because because it's dependent on the new/old drawing method and has nothing to do with their memory available. And for two, it will likely cause issues if accidentally set to a wrong value. I've increased the limit to 2000 pixels because otherwise I can have up to 6 images visible which is still slow with the traditional drawing method. I guess 2000 makes a good compromise between this, and each image takes only about 12 MB. Patch removes some old code, too.

  • src/wmsplugin/GeorefImage.java

     
    44import java.awt.Graphics; 
    55import java.awt.Image; 
    66import java.awt.Point; 
    7 import java.awt.Toolkit; 
    87import java.awt.image.BufferedImage; 
    9 import java.awt.image.FilteredImageSource; 
    10 import java.awt.image.ImageProducer; 
    11 import java.awt.image.RGBImageFilter; 
    128import java.io.IOException; 
    139import java.io.ObjectInputStream; 
    1410import java.io.ObjectOutputStream; 
     
    8682        } 
    8783 
    8884        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 alpha 
    90         // But we do get a black instead of white background. 
    91         //Image ppImg = image; 
    92         /*if(!alphaChannel) { 
    93             // set alpha value to 255 
    94             ppImg = clearAlpha(image); 
    95         }*/ 
    9685 
    9786        try { 
    9887            if(reImg != null) reImg.flush(); 
     
    10190            // Notice that this value can get negative due to integer overflows 
    10291            //System.out.println("Img Size:              "+ (width*height*3/1024/1024) +" MB"); 
    10392 
     93            int multipl = alphaChannel ? 4 : 3; 
    10494            // This happens when requesting images while zoomed out and then zooming in 
    10595            // Storing images this large in memory will certainly hang up JOSM. Luckily 
    10696            // traditional rendering is as fast at these zoom levels, so it's no loss. 
    10797            // 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) { 
    10999                fallbackDraw(g, image, minPt, maxPt); 
    110100            } else { 
    111101                // We haven't got a saved resized copy, so resize and cache it 
    112102                reImg = new BufferedImage(width, height, 
    113103                    alphaChannel 
    114104                        ? BufferedImage.TYPE_INT_ARGB 
    115                         : BufferedImage.TYPE_3BYTE_BGR  // This removes alpha, too 
     105                        : BufferedImage.TYPE_3BYTE_BGR  // This removes alpha 
    116106                    ); 
    117107                reImg.getGraphics().drawImage(image, 
    118108                    0, 0, width, height, // dest 
     
    164154        } 
    165155    } 
    166156 
    167     private Image clearAlpha(Image img) { 
    168         ImageProducer ip = img.getSource(); 
    169         RGBImageFilter filter = new RGBImageFilter() { 
    170                 @Override 
    171             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  
    181157    public void flushedResizedCachedInstance() { 
    182158        reImg = null; 
    183159    }