Author: Christian Lopes
Date: 2011-05-03 13:05:04 -0700 (Tue, 03 May 2011)
New Revision: 24905

Modified:
   cytoscapeweb/trunk/cytoscapeweb/html-template/js/cytoscapeweb.js
   
cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/view/ApplicationMediator.as
   
cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/view/render/ImageCache.as
Log:
- Fixed issue #2500 (Invalid BitmapData Error when generating large PNG images) 
- CW will also require at least Flash 10, because bitmap size limitations were 
increased in that version.
- Calling BitmapData.dispose() on node images, to prevent memory leaks.

Modified: cytoscapeweb/trunk/cytoscapeweb/html-template/js/cytoscapeweb.js
===================================================================
--- cytoscapeweb/trunk/cytoscapeweb/html-template/js/cytoscapeweb.js    
2011-05-03 19:50:18 UTC (rev 24904)
+++ cytoscapeweb/trunk/cytoscapeweb/html-template/js/cytoscapeweb.js    
2011-05-03 20:05:04 UTC (rev 24905)
@@ -1628,11 +1628,11 @@
          */
         embedSWF: function () {
             //Major version of Flash required
-            var requiredMajorVersion = 9;
+            var requiredMajorVersion = 10;
             //Minor version of Flash required
             var requiredMinorVersion = 0;
             //Minor version of Flash required
-            var requiredRevision = 24;
+            var requiredRevision = 0;
 
             var containerId = this.containerId;
 

Modified: 
cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/view/ApplicationMediator.as
===================================================================
--- 
cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/view/ApplicationMediator.as
    2011-05-03 19:50:18 UTC (rev 24904)
+++ 
cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/view/ApplicationMediator.as
    2011-05-03 20:05:04 UTC (rev 24905)
@@ -36,7 +36,6 @@
        import flash.geom.Rectangle;
        import flash.ui.Keyboard;
        import flash.ui.Mouse;
-       import flash.utils.ByteArray;
        
        import mx.controls.Alert;
        import mx.controls.Button;
@@ -212,14 +211,35 @@
 
             if (type === "png") {
                 var bounds:Rectangle = graphView.vis.getRealBounds();
+                
                 // At least 1 pixel:
-                bounds.width = bounds.width > 0 ? bounds.width : 1;
-                bounds.height = bounds.height > 0 ? bounds.height : 1;
+                var w:int = Math.max(bounds.width, 1);
+                var h:int = Math.max(bounds.height, 1);
                 
+                // Maximum pixel count 
(http://kb2.adobe.com/cps/496/cpsid_49662.html)
+                var pcount:int = w * h;
+                const MAX_PCOUNT:Number = 0xFFFFFF;
+                const MAX_PSIDE:Number = 8191;
+                var f:Number = 1;
+                
+                if (pcount > MAX_PCOUNT)
+                    f = f * MAX_PCOUNT/pcount;
+                
+                var maxSide:int = Math.max(w, h);
+                
+                if (maxSide > MAX_PSIDE)
+                    f = f * MAX_PSIDE/maxSide;
+                
+                if (f < 1) {
+                    w *= f;
+                    h *= f;
+                }
+                
+                // Draw the image:
                 var color:uint = 
configProxy.config.visualStyle.getValue(VisualProperties.BACKGROUND_COLOR);
-                
-                var source:BitmapData = new BitmapData(bounds.width, 
bounds.height, false, color);
+                var source:BitmapData = new BitmapData(w, h, false, color);
                 var matrix:Matrix = new Matrix(1, 0, 0, 1, -bounds.x, 
-bounds.y);
+                matrix.scale(f, f);
                 source.draw(graphView.vis, matrix);
 
                 var encoder:PNGEncoder = new PNGEncoder();

Modified: 
cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/view/render/ImageCache.as
===================================================================
--- 
cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/view/render/ImageCache.as  
    2011-05-03 19:50:18 UTC (rev 24904)
+++ 
cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/view/render/ImageCache.as  
    2011-05-03 20:05:04 UTC (rev 24905)
@@ -252,6 +252,9 @@
                 if (_imgCounter[url] === 0) {
                     delete _imgCounter[url];
                     delete _broken[url];
+                    
+                    var bd:BitmapData = _images[url];
+                    if (bd != null) bd.dispose();
                     delete _images[url];
                 }
             }

-- 
You received this message because you are subscribed to the Google Groups 
"cytoscape-cvs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/cytoscape-cvs?hl=en.

Reply via email to