poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ye...@apache.org
Subject svn commit: r696622 - in /poi/trunk/src: java/org/apache/poi/hssf/usermodel/HSSFPicture.java testcases/org/apache/poi/hssf/data/45829.png testcases/org/apache/poi/hssf/usermodel/TestHSSFPicture.java
Date Thu, 18 Sep 2008 10:28:25 GMT
Author: yegor
Date: Thu Sep 18 03:28:24 2008
New Revision: 696622

URL: http://svn.apache.org/viewvc?rev=696622&view=rev
Log:
fixed bug #45829: HSSFPicture.getImageDimension() fails when DPI of image is zero

Added:
    poi/trunk/src/testcases/org/apache/poi/hssf/data/45829.png   (with props)
Modified:
    poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFPicture.java
    poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPicture.java

Modified: poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFPicture.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFPicture.java?rev=696622&r1=696621&r2=696622&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFPicture.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFPicture.java Thu Sep 18 03:28:24
2008
@@ -235,6 +235,12 @@
                     BufferedImage img = r.read(0);
 
                     int[] dpi = getResolution(r);
+
+                    //if DPI is zero then assume standard 96 DPI
+                    //since cannot divide by zero
+                    if (dpi[0] == 0) dpi[0] = 96;
+                    if (dpi[1] == 0) dpi[1] = 96;
+                    
                     size.width = img.getWidth()*96/dpi[0];
                     size.height = img.getHeight()*96/dpi[1];
 

Added: poi/trunk/src/testcases/org/apache/poi/hssf/data/45829.png
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/data/45829.png?rev=696622&view=auto
==============================================================================
Binary file - no diff available.

Propchange: poi/trunk/src/testcases/org/apache/poi/hssf/data/45829.png
------------------------------------------------------------------------------
    svn:executable = *

Propchange: poi/trunk/src/testcases/org/apache/poi/hssf/data/45829.png
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Modified: poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPicture.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPicture.java?rev=696622&r1=696621&r2=696622&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPicture.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPicture.java Thu Sep 18
03:28:24 2008
@@ -47,4 +47,18 @@
         assertEquals(848, anchor1.getDx2());
         assertEquals(240, anchor1.getDy2());
     }
+
+    /**
+     * Bug # 45829 reported ArithmeticException (/ by zero) when resizing png with zero DPI.
+     */
+    public void test45829() {
+        HSSFWorkbook wb = new HSSFWorkbook();
+        HSSFSheet sh1 = wb.createSheet();
+        HSSFPatriarch p1 = sh1.createDrawingPatriarch();
+
+        byte[] pictureData = HSSFTestDataSamples.getTestDataFileContent("45829.png");
+        int idx1 = wb.addPicture( pictureData, HSSFWorkbook.PICTURE_TYPE_PNG );
+        HSSFPicture pic = p1.createPicture(new HSSFClientAnchor(), idx1);
+        pic.resize();
+    }
 }



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


Mime
View raw message