Changes between Version 7 and Version 8 of SCENE_COMMONS_R1


Ignore:
Timestamp:
06/15/09 16:50:47 (16 years ago)
Author:
deni
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • SCENE_COMMONS_R1

    v7 v8  
    8989 * A new private field will be added in ImmImage to store the image multiplied by recently used colours - HashMap<ImmColor, ImmImage> colorImgCache. 
    9090 * A new method for multiplying the image by given color will be added in ImmImage. It will check if the image multiplied by the given color is already cached. If it is it will return the cached value. If not - it will compute it and put it in the cache.  
     91There is a method that multiplies the image pixels by a color in ElementHelper, it will be copied here and removed from ElementHelper. 
     92 
     93'''Caching recently loaded ImmImages''' will prevent us from loading the same image more than once. 
     94 * All constructors except the one with BufferedImage will be deleted or made private. 
     95 * A new method will be created instead of them: 
     96 
     97{{{ 
     98        /** 
     99         * Loads an ImmImage from the given URL. 
     100         * @param url 
     101         *              The URL from which to load the image. 
     102         * @return 
     103         *              The loaded image 
     104         */ 
     105        public static ImmImage loadCached(URL url) { 
     106                if (!loadedImages.containsKey(url)) { 
     107                        try { 
     108                                InputStream is = null; 
     109                                try { 
     110                                        is = url.openStream(); 
     111                                        loadedImages.put(url, new ImmImage(is)); 
     112                                } finally { 
     113                                        if (is != null) { 
     114                                                is.close(); 
     115                                        } 
     116                                } 
     117                        } catch (IOException e) { 
     118                                throw new RuntimeException(e); 
     119                        } 
     120                } 
     121                return loadedImages.get(url); 
     122        } 
     123}}} 
     124 
     125It is a good idea to create a new class representing a map which keeps weak/soft references to its values. Otherwise we could run out of memory. [[BR]] 
     126However most probably this won't be done now.