Author: ruschein
Date: 2010-02-01 14:17:27 -0800 (Mon, 01 Feb 2010)
New Revision: 19098

Modified:
   corelibs/trunk/ding/src/ding/view/DGraphView.java
Log:
Instrumented to print out image compression ratios.

Modified: corelibs/trunk/ding/src/ding/view/DGraphView.java
===================================================================
--- corelibs/trunk/ding/src/ding/view/DGraphView.java   2010-02-01 21:41:06 UTC 
(rev 19097)
+++ corelibs/trunk/ding/src/ding/view/DGraphView.java   2010-02-01 22:17:27 UTC 
(rev 19098)
@@ -98,7 +98,11 @@
        boolean calledFromGetSnapshot = false;
 
        // Size of snapshot image
-       private static final int DEF_SNAPSHOT_SIZE = 4000;
+       private static final int DEF_SNAPSHOT_SIZE = 400;
+       private static double minComprFactorSoFar = Double.MAX_VALUE;
+       private static double maxComprFactorSoFar = Double.MIN_VALUE;
+       private static double compressionFactors[] = new double[10000];
+       private static int compressionFactorCount = 0;
        
        static final float DEFAULT_ANCHOR_SIZE = 9.0f;
        static final Paint DEFAULT_ANCHOR_SELECTED_PAINT = Color.red;
@@ -2612,7 +2616,7 @@
                        bufferedImage =
                                (BufferedImage)createImage(DEF_SNAPSHOT_SIZE, 
DEF_SNAPSHOT_SIZE, 1,
                                                           /* skipBackground = 
*/ true);
-                       snapshotImage = convertToPNG(bufferedImage);
+                       snapshotImage = convertToCompressedImage(bufferedImage);
                        latest = true;
                }
 
@@ -2628,14 +2632,32 @@
        /**
         * Converts a BufferedImage to a lossless PNG.
         */
-       private byte[] convertToPNG(final BufferedImage bufferedImage) {
+       private byte[] convertToCompressedImage(final BufferedImage 
bufferedImage) {
+               System.err.println("Entering convertToCompressedImage()");
                try {
-                       final ByteArrayOutputStream baos = new 
ByteArrayOutputStream();
-                       ImageIO.write(bufferedImage, "PNG", baos);
+                       final ByteArrayOutputStream baos = new 
ByteArrayOutputStream(100000);
+                       ImageIO.write(bufferedImage, "jpeg", baos);
+                       final byte[] retval = baos.toByteArray();
+                       final double compressionFactor = (DEF_SNAPSHOT_SIZE * 
DEF_SNAPSHOT_SIZE * 4.0) / retval.length;
+                       if (compressionFactor < minComprFactorSoFar)
+                               minComprFactorSoFar = compressionFactor;
+                       if (compressionFactor > maxComprFactorSoFar)
+                               maxComprFactorSoFar = compressionFactor;
+                       System.err.println("About to exit 
convertToCompressedImage(), compr. factor = " + compressionFactor);
+                       System.err.println("Min. compr. factor so far = " + 
minComprFactorSoFar);
+                       System.err.println("Max. compr. factor so far = " + 
maxComprFactorSoFar);
 
-                       return baos.toByteArray();
+                       compressionFactors[compressionFactorCount++] = 
compressionFactor;
+                       // Calc avg.
+                       double sum = 0.0;
+                       for (int i = 0; i < compressionFactorCount; ++i)
+                               sum += compressionFactors[i];
+                       final double comprFactorAvg = sum / 
compressionFactorCount;
+                       System.err.println("Avg. compr. factor so far = " + 
comprFactorAvg);
+                       return retval;
                } catch (final IOException e) {
-                       System.err.println("Failed to convert a BufferedImage 
to a PNG!");
+                       System.err.println("Failed to convert a BufferedImage 
to a PNG! (" + e + ")");
+                       System.exit(-1);
                        return null;
                }
        }
@@ -2644,12 +2666,16 @@
        /**
         * Converts a PNG to a BufferedImage.
         */
-       private BufferedImage convertToBufferedImage(final byte[] png) {
+       private BufferedImage convertToBufferedImage(final byte[] 
compressedImage) {
+               System.err.println("Entering convertToBufferedImage()");
                try {
-                       final ByteArrayInputStream is = new 
ByteArrayInputStream(png);
-                       return (BufferedImage)ImageIO.read(is);
+                       final ByteArrayInputStream is = new 
ByteArrayInputStream(compressedImage);
+                       final BufferedImage retval = 
(BufferedImage)ImageIO.read(is);
+                       System.err.println("About to exit 
convertToBufferedImage()");
+                       return retval;
                } catch (final IOException e) {
-                       System.err.println("Failed to convert a PNG to a 
BufferedImage!");
+                       System.err.println("Failed to convert a PNG to a 
BufferedImage! (" + e + ")");
+                       System.exit(-1);
                        return null;
                }
        }

-- 
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