]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
XGC-97: Add PreloaderRawPNG to handle images ImageIO cant
authorSimon Steiner <ssteiner@apache.org>
Fri, 5 Jun 2015 12:19:21 +0000 (12:19 +0000)
committerSimon Steiner <ssteiner@apache.org>
Fri, 5 Jun 2015 12:19:21 +0000 (12:19 +0000)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1683737 13f79535-47bb-0310-9956-ffa450edef68

findbugs-exclude.xml
lib/xmlgraphics-commons-svn-trunk.jar
src/java/org/apache/fop/render/pdf/ImageRawPNGAdapter.java

index 73796c1281f91a2df7944a5a706436a23a8b9692..2eaa8580b370e1bd67c4562c92880bb79eb2f153 100644 (file)
     <!-- Properties not yet implemented -->
     <Class name="org.apache.fop.fo.properties.CommonAural"/>
   </Match>
+   <Match>
+     <Class name="org.apache.fop.render.pdf.ImageRawPNGAdapter"/>
+     <Or>
+       <Method name="outputContents"/>
+       <Method name="setup"/>
+     </Or>
+     <Or>
+       <Bug pattern="OS_OPEN_STREAM"/>
+       <Bug pattern="OS_OPEN_STREAM_EXCEPTION_PATH"/>
+     </Or>
+   </Match> 
   <!-- END - APPROVED EXCLUSIONS -->
 
   <!-- START - TEMPORARY (UNAPPROVED) EXCLUSIONS -->
index 63722717557f09c2aa77da1c44a4fb886f584f9a..e7470c8b7c28f480eae0a80338524a56cfe59582 100644 (file)
Binary files a/lib/xmlgraphics-commons-svn-trunk.jar and b/lib/xmlgraphics-commons-svn-trunk.jar differ
index f40ca6d943b868522e368dca1a4fda997453abd0..9742036b79b9161d27b729a6e794a89af08ddccb 100644 (file)
@@ -116,62 +116,52 @@ public class ImageRawPNGAdapter extends AbstractImageAdapter {
             // TODO: Implement code to combine image with background color if transparency is not allowed\r
             // here we need to inflate the PNG pixel data, which includes alpha, separate the alpha channel\r
             // and then deflate it back again\r
-            ByteArrayOutputStream baos = null;\r
-            DeflaterOutputStream dos = null;\r
-            InputStream in = null;\r
-            InflaterInputStream infStream = null;\r
-            DataInputStream dataStream = null;\r
+            ByteArrayOutputStream baos = new ByteArrayOutputStream();\r
+            DeflaterOutputStream dos = new DeflaterOutputStream(baos, new Deflater());\r
+            InputStream in = ((ImageRawStream) image).createInputStream();\r
             try {\r
-                baos = new ByteArrayOutputStream();\r
-                dos = new DeflaterOutputStream(baos, new Deflater());\r
-                in = ((ImageRawStream) image).createInputStream();\r
-                try {\r
-                    infStream = new InflaterInputStream(in, new Inflater());\r
-                    dataStream = new DataInputStream(infStream);\r
-                    // offset is the byte offset of the alpha component\r
-                    int offset = numberOfInterleavedComponents - 1; // 1 for GA, 3 for RGBA\r
-                    int numColumns = image.getSize().getWidthPx();\r
-                    int bytesPerRow = numberOfInterleavedComponents * numColumns;\r
-                    int filter;\r
-                    // read line by line; the first byte holds the filter\r
-                    while ((filter = dataStream.read()) != -1) {\r
-                        byte[] bytes = new byte[bytesPerRow];\r
-                        dataStream.readFully(bytes, 0, bytesPerRow);\r
-                        dos.write((byte) filter);\r
-                        for (int j = 0; j < numColumns; j++) {\r
-                            dos.write(bytes, offset, 1);\r
-                            offset += numberOfInterleavedComponents;\r
-                        }\r
-                        offset = numberOfInterleavedComponents - 1;\r
+                InflaterInputStream infStream = new InflaterInputStream(in, new Inflater());\r
+                DataInputStream dataStream = new DataInputStream(infStream);\r
+                // offset is the byte offset of the alpha component\r
+                int offset = numberOfInterleavedComponents - 1; // 1 for GA, 3 for RGBA\r
+                int numColumns = image.getSize().getWidthPx();\r
+                int bytesPerRow = numberOfInterleavedComponents * numColumns;\r
+                int filter;\r
+                // read line by line; the first byte holds the filter\r
+                while ((filter = dataStream.read()) != -1) {\r
+                    byte[] bytes = new byte[bytesPerRow];\r
+                    dataStream.readFully(bytes, 0, bytesPerRow);\r
+                    dos.write((byte) filter);\r
+                    for (int j = 0; j < numColumns; j++) {\r
+                        dos.write(bytes, offset, 1);\r
+                        offset += numberOfInterleavedComponents;\r
                     }\r
-                } catch (IOException e) {\r
-                    throw new RuntimeException("Error processing transparency channel:", e);\r
-                }\r
-                // set up alpha channel compression\r
-                FlateFilter transFlate;\r
-                try {\r
-                    transFlate = new FlateFilter();\r
-                    transFlate.setApplied(true);\r
-                    transFlate.setPredictor(FlateFilter.PREDICTION_PNG_OPT);\r
-                    transFlate.setColors(1);\r
-                    transFlate.setColumns(image.getSize().getWidthPx());\r
-                    transFlate.setBitsPerComponent(this.getBitsPerComponent());\r
-                } catch (PDFFilterException e) {\r
-                    throw new RuntimeException("FlateFilter configuration error", e);\r
+                    offset = numberOfInterleavedComponents - 1;\r
                 }\r
-                BitmapImage alphaMask = new BitmapImage("Mask:" + this.getKey(), image.getSize().getWidthPx(),\r
-                        image.getSize().getHeightPx(), baos.toByteArray(), null);\r
-                alphaMask.setPDFFilter(transFlate);\r
-                alphaMask.disallowMultipleFilters();\r
-                alphaMask.setColorSpace(new PDFDeviceColorSpace(PDFDeviceColorSpace.DEVICE_GRAY));\r
-                softMask = doc.addImage(null, alphaMask).makeReference();\r
+                dos.close();\r
+            } catch (IOException e) {\r
+                throw new RuntimeException("Error processing transparency channel:", e);\r
             } finally {\r
-                IOUtils.closeQuietly(infStream);\r
-                IOUtils.closeQuietly(dataStream);\r
                 IOUtils.closeQuietly(in);\r
-                IOUtils.closeQuietly(dos);\r
-                IOUtils.closeQuietly(baos);\r
             }\r
+            // set up alpha channel compression\r
+            FlateFilter transFlate;\r
+            try {\r
+                transFlate = new FlateFilter();\r
+                transFlate.setApplied(true);\r
+                transFlate.setPredictor(FlateFilter.PREDICTION_PNG_OPT);\r
+                transFlate.setColors(1);\r
+                transFlate.setColumns(image.getSize().getWidthPx());\r
+                transFlate.setBitsPerComponent(this.getBitsPerComponent());\r
+            } catch (PDFFilterException e) {\r
+                throw new RuntimeException("FlateFilter configuration error", e);\r
+            }\r
+            BitmapImage alphaMask = new BitmapImage("Mask:" + this.getKey(), image.getSize().getWidthPx(),\r
+                    image.getSize().getHeightPx(), baos.toByteArray(), null);\r
+            alphaMask.setPDFFilter(transFlate);\r
+            alphaMask.disallowMultipleFilters();\r
+            alphaMask.setColorSpace(new PDFDeviceColorSpace(PDFDeviceColorSpace.DEVICE_GRAY));\r
+            softMask = doc.addImage(null, alphaMask).makeReference();\r
         }\r
     }\r
 \r
@@ -219,9 +209,7 @@ public class ImageRawPNGAdapter extends AbstractImageAdapter {
     /** {@inheritDoc} */\r
     public void outputContents(OutputStream out) throws IOException {\r
         InputStream in = ((ImageRawStream) image).createInputStream();\r
-        InflaterInputStream infStream = null;\r
-        DataInputStream dataStream = null;\r
-        DeflaterOutputStream dos = null;\r
+\r
         try {\r
             if (numberOfInterleavedComponents == 1 || numberOfInterleavedComponents == 3) {\r
                 // means we have Gray, RGB, or Palette\r
@@ -231,14 +219,14 @@ public class ImageRawPNGAdapter extends AbstractImageAdapter {
                 // TODO: since we have alpha here do this when the alpha channel is extracted\r
                 int numBytes = numberOfInterleavedComponents - 1; // 1 for Gray, 3 for RGB\r
                 int numColumns = image.getSize().getWidthPx();\r
-                infStream = new InflaterInputStream(in, new Inflater());\r
-                dataStream = new DataInputStream(infStream);\r
+                InflaterInputStream infStream = new InflaterInputStream(in, new Inflater());\r
+                DataInputStream dataStream = new DataInputStream(infStream);\r
                 int offset = 0;\r
                 int bytesPerRow = numberOfInterleavedComponents * numColumns;\r
                 int filter;\r
                 // here we need to inflate the PNG pixel data, which includes alpha, separate the alpha\r
                 // channel and then deflate the RGB channels back again\r
-                dos = new DeflaterOutputStream(out, new Deflater());\r
+                DeflaterOutputStream dos = new DeflaterOutputStream(out, new Deflater());\r
                 while ((filter = dataStream.read()) != -1) {\r
                     byte[] bytes = new byte[bytesPerRow];\r
                     dataStream.readFully(bytes, 0, bytesPerRow);\r
@@ -249,11 +237,9 @@ public class ImageRawPNGAdapter extends AbstractImageAdapter {
                     }\r
                     offset = 0;\r
                 }\r
+                dos.close();\r
             }\r
         } finally {\r
-            IOUtils.closeQuietly(dos);\r
-            IOUtils.closeQuietly(dataStream);\r
-            IOUtils.closeQuietly(infStream);\r
             IOUtils.closeQuietly(in);\r
         }\r
     }\r