poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kiwiwi...@apache.org
Subject svn commit: r1744007 - in /poi/trunk/src: java/org/apache/poi/sl/draw/ ooxml/java/org/apache/poi/xslf/util/ scratchpad/src/org/apache/poi/hwmf/draw/
Date Mon, 16 May 2016 10:09:22 GMT
Author: kiwiwings
Date: Mon May 16 10:09:22 2016
New Revision: 1744007

URL: http://svn.apache.org/viewvc?rev=1744007&view=rev
Log:
Close resources in Common SL rendering classes and minimize memory consumption by using the
image anchor dimensions instead of the WMF-included dimensions

Modified:
    poi/trunk/src/java/org/apache/poi/sl/draw/BitmapImageRenderer.java
    poi/trunk/src/java/org/apache/poi/sl/draw/DrawPaint.java
    poi/trunk/src/java/org/apache/poi/sl/draw/DrawSimpleShape.java
    poi/trunk/src/java/org/apache/poi/sl/draw/ImageRenderer.java
    poi/trunk/src/ooxml/java/org/apache/poi/xslf/util/PPTX2PNG.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hwmf/draw/HwmfSLImageRenderer.java

Modified: poi/trunk/src/java/org/apache/poi/sl/draw/BitmapImageRenderer.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/sl/draw/BitmapImageRenderer.java?rev=1744007&r1=1744006&r2=1744007&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/sl/draw/BitmapImageRenderer.java (original)
+++ poi/trunk/src/java/org/apache/poi/sl/draw/BitmapImageRenderer.java Mon May 16 10:09:22
2016
@@ -24,6 +24,7 @@ import java.awt.Insets;
 import java.awt.Shape;
 import java.awt.geom.AffineTransform;
 import java.awt.geom.Rectangle2D;
+import java.awt.image.AffineTransformOp;
 import java.awt.image.BufferedImage;
 import java.awt.image.RescaleOp;
 import java.io.ByteArrayInputStream;
@@ -69,15 +70,26 @@ public class BitmapImageRenderer impleme
         return bi;
     }
 
-
-    /**
-     * @return the buffered image
-     */
+    @Override
     public BufferedImage getImage() {
         return img;
     }
 
     @Override
+    public BufferedImage getImage(Dimension dim) {
+        double w_old = img.getWidth();
+        double h_old = img.getHeight();
+        BufferedImage scaled = new BufferedImage((int)w_old, (int)h_old, BufferedImage.TYPE_INT_ARGB);
+        double w_new = dim.getWidth();
+        double h_new = dim.getHeight();
+        AffineTransform at = new AffineTransform();
+        at.scale(w_new/w_old, h_new/h_old);
+        AffineTransformOp scaleOp = new AffineTransformOp(at, AffineTransformOp.TYPE_BILINEAR);
+        scaleOp.filter(img, scaled);
+        return scaled;
+    }
+
+    @Override
     public Dimension getDimension() {
         return (img == null)
             ? new Dimension(0,0)

Modified: poi/trunk/src/java/org/apache/poi/sl/draw/DrawPaint.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/sl/draw/DrawPaint.java?rev=1744007&r1=1744006&r2=1744007&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/sl/draw/DrawPaint.java (original)
+++ poi/trunk/src/java/org/apache/poi/sl/draw/DrawPaint.java Mon May 16 10:09:22 2016
@@ -18,6 +18,7 @@
 package org.apache.poi.sl.draw;
 
 import java.awt.Color;
+import java.awt.Dimension;
 import java.awt.Graphics2D;
 import java.awt.LinearGradientPaint;
 import java.awt.MultipleGradientPaint.ColorSpaceType;
@@ -153,12 +154,20 @@ public class DrawPaint {
             renderer.setAlpha(alpha/100000.f);
         }
         
-        BufferedImage image = renderer.getImage();
+        Rectangle2D textAnchor = shape.getAnchor();
+        BufferedImage image;
+        if ("image/x-wmf".equals(fill.getContentType())) {
+            // don't rely on wmf dimensions, use dimension of anchor
+            // TODO: check pixels vs. points for image dimension 
+            image = renderer.getImage(new Dimension((int)textAnchor.getWidth(), (int)textAnchor.getHeight()));
+        } else {
+            image = renderer.getImage();
+        }
+
         if(image == null) {
             LOG.log(POILogger.ERROR, "Can't load image data");
             return null;
         }
-        Rectangle2D textAnchor = shape.getAnchor();
         Paint paint = new java.awt.TexturePaint(image, textAnchor);
 
         return paint;

Modified: poi/trunk/src/java/org/apache/poi/sl/draw/DrawSimpleShape.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/sl/draw/DrawSimpleShape.java?rev=1744007&r1=1744006&r2=1744007&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/sl/draw/DrawSimpleShape.java (original)
+++ poi/trunk/src/java/org/apache/poi/sl/draw/DrawSimpleShape.java Mon May 16 10:09:22 2016
@@ -408,6 +408,9 @@ public class DrawSimpleShape extends Dra
 
                     presets.put(cusName, new CustomGeometry(cusGeom));
                 }
+                
+                staxFiltRd.close();
+                staxReader.close();
             } catch (Exception e) {
                 throw new RuntimeException("Unable to load preset geometries.", e);
             } finally {

Modified: poi/trunk/src/java/org/apache/poi/sl/draw/ImageRenderer.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/sl/draw/ImageRenderer.java?rev=1744007&r1=1744006&r2=1744007&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/sl/draw/ImageRenderer.java (original)
+++ poi/trunk/src/java/org/apache/poi/sl/draw/ImageRenderer.java Mon May 16 10:09:22 2016
@@ -18,17 +18,13 @@
  */
 package org.apache.poi.sl.draw;
 
-import java.awt.*;
-import java.awt.geom.AffineTransform;
+import java.awt.Dimension;
+import java.awt.Graphics2D;
+import java.awt.Insets;
 import java.awt.geom.Rectangle2D;
 import java.awt.image.BufferedImage;
-import java.awt.image.RescaleOp;
-import java.io.*;
-
-import javax.imageio.ImageIO;
-
-import org.apache.poi.util.POILogFactory;
-import org.apache.poi.util.POILogger;
+import java.io.IOException;
+import java.io.InputStream;
 
 /**
  * Classes can implement this interfaces to support other formats, for
@@ -109,6 +105,14 @@ public interface ImageRenderer {
      * @return the image as buffered image
      */
     BufferedImage getImage();
+
+    /**
+     * @param dim the dimension in pixels of the returned image
+     * @return the image as buffered image
+     * 
+     * @since POI 3.15-beta2
+     */
+    BufferedImage getImage(Dimension dim);
     
     /**
      * Render picture data into the supplied graphics

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xslf/util/PPTX2PNG.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/util/PPTX2PNG.java?rev=1744007&r1=1744006&r2=1744007&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/util/PPTX2PNG.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/util/PPTX2PNG.java Mon May 16 10:09:22 2016
@@ -160,6 +160,9 @@ public class PPTX2PNG {
                     File outfile = new File(outdir, outname);
                     ImageIO.write(img, format, outfile);
                 }
+                
+                graphics.dispose();
+                img.flush();
             }
         } finally {
             ss.close();

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hwmf/draw/HwmfSLImageRenderer.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwmf/draw/HwmfSLImageRenderer.java?rev=1744007&r1=1744006&r2=1744007&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hwmf/draw/HwmfSLImageRenderer.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hwmf/draw/HwmfSLImageRenderer.java Mon May
16 10:09:22 2016
@@ -72,18 +72,22 @@ public class HwmfSLImageRenderer impleme
 
     @Override
     public BufferedImage getImage() {
+        return getImage(getDimension());
+    }
+
+    @Override
+    public BufferedImage getImage(Dimension dim) {
         if (image == null) {
             return new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB); 
         }
         
-        Dimension dim = getDimension();
         BufferedImage bufImg = new BufferedImage((int)dim.getWidth(), (int)dim.getHeight(),
BufferedImage.TYPE_INT_ARGB);
         Graphics2D g = bufImg.createGraphics();
         g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
         g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
         g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
         g.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
-        image.draw(g);
+        image.draw(g, new Rectangle2D.Double(0,0,dim.getWidth(),dim.getHeight()));
         g.dispose();
         
         if (alpha != 0) {
@@ -97,7 +101,7 @@ public class HwmfSLImageRenderer impleme
         
         return bufImg;
     }
-
+    
     @Override
     public boolean drawImage(Graphics2D graphics, Rectangle2D anchor) {
         return drawImage(graphics, anchor, null);



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message