Changes between Version 6 and Version 7 of SCENE_COMMONS_R1


Ignore:
Timestamp:
06/15/09 15:03:14 (16 years ago)
Author:
deni
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • SCENE_COMMONS_R1

    v6 v7  
    66 
    77== Overview == 
    8 The goal of this task is to search for and implement some optimizations connected with the drawing of scenes. 
     8The goal of this task is to search for and implement some optimizations connected with the drawing of scenes. SimpleSceneDemoTest will be used to measure how effective these optimisations are. 
    99 
    1010== Task requirements == 
    11  * Get acquainted with scene elements, element helpers, etc, seek for potential optimizations and implement them. 
    12  * Use SimpleSceneDemoTest to measure how effective the potential optimisations are. 
     11 * Now SimpleSceneDemoTest redraws the scene in about 1220 milliseconds. 
     12 * Improve this time by at least 20 percent.  
    1313 
    1414== Task result == 
     
    2424== How to demo == 
    2525Compare the performance of SimpleSceneDemoTest before and after this task. 
     26 
     27 
     28= Design = 
     29The first two implementation ideas will be implemented, the third one did not prove effective and will not.  
     30 
     31'''ImmImage should be made really immutable and should not expose representation''', so that we can cache some things in it. [[BR]] 
     32The constructor ImmImage(BufferedImage image) should make a deep copy of the argument. Thus if the caller keeps a reference to the buffered image and makes some changes to it, they will not affect the ImmImage. [[BR]] 
     33The same applies for the method BufferedImage toBufferedImage() and its result. [[BR]] 
     34The other constructors will also make a copy of the image in order to be sure that the image is in the preferred format.[[BR]] 
     35A new private method will be created and the constructors and toBufferedImage() will use it: 
     36{{{ 
     37        /** 
     38         * Deep copy of BufferedImage 
     39         *  
     40         * @param source 
     41         *            the source image 
     42         * @return  
     43         *            a copy of the source image converted to out preferred type 
     44         */ 
     45        private static BufferedImage copyImage(BufferedImage source) { 
     46                BufferedImage newImage = new BufferedImage(source.getWidth(), source 
     47                                .getHeight(), ImmImage.PREFERRED_BI_TYPE); 
     48                Graphics2D gt = newImage.createGraphics(); 
     49                gt.drawImage(source, 0, 0, null); 
     50                gt.dispose(); 
     51                return newImage; 
     52        } 
     53}}} 
     54 
     55 
     56 
     57 
     58'''Some helper methods will be added to minimize the need to convert to BufferedImage:''' 
     59 * a method drawing the image into graphics. 
     60The ImageElementHelper will not draw the image itself, but will call this method. It is necessary to do so, because ImmImage has direct access to the wrapped BufferedImage, while the element helper would need to copy it. 
     61{{{ 
     62        /** 
     63         * Draws the image. 
     64         * @param g2d 
     65         *              The graphics where the image will be drawn. 
     66         *  
     67         */ 
     68        public void paint(Graphics2D g2d) { 
     69                // implementation 
     70        } 
     71}}} 
     72 * a method drawing the image multiplied by a given color 
     73 
     74{{{ 
     75         * Multiplies all image pixels by given color and draws the resulting image. 
     76         * @param g2d 
     77         *              The graphics where the image will be drawn. 
     78         * @param color 
     79         *              The color which by which to multiply.  
     80         *              Usually this will be the background color or the color of elements  
     81         *              above which the image is drawn.   
     82         */ 
     83        public void paint(Graphics2D g2d, ImmColor color) { 
     84                // implementation 
     85        } 
     86}}} 
     87 
     88'''Caching ImmImages multiplied by recently used colours''' will make drawing of images above other elements (including background) faster 
     89 * A new private field will be added in ImmImage to store the image multiplied by recently used colours - HashMap<ImmColor, ImmImage> colorImgCache. 
     90 * 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.