You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ti...@apache.org on 2020/08/26 17:53:13 UTC

svn commit: r1881217 - /pdfbox/branches/issue45/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/image/PNGConverter.java

Author: tilman
Date: Wed Aug 26 17:53:13 2020
New Revision: 1881217

URL: http://svn.apache.org/viewvc?rev=1881217&view=rev
Log:
PDFBOX-4847: ensure that an embedded sRGB color profile is also compressed, by Emmeran Seehuber

Modified:
    pdfbox/branches/issue45/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/image/PNGConverter.java

Modified: pdfbox/branches/issue45/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/image/PNGConverter.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/issue45/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/image/PNGConverter.java?rev=1881217&r1=1881216&r2=1881217&view=diff
==============================================================================
--- pdfbox/branches/issue45/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/image/PNGConverter.java (original)
+++ pdfbox/branches/issue45/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/image/PNGConverter.java Wed Aug 26 17:53:13 2020
@@ -404,14 +404,17 @@ final class PNGConverter
         if (state.iCCP != null || state.sRGB != null)
         {
             // We have got a color profile, which we must attach
-            PDICCBased profile = new PDICCBased(document);
-            COSStream cosStream = profile.getPDStream().getCOSObject();
+            COSArray array = new COSArray();
+            array.add(COSName.ICCBASED);
+            PDStream pdStream = new PDStream(document);
+            array.add(pdStream);
+            COSStream cosStream = pdStream.getCOSObject();
             cosStream.setInt(COSName.N, colorSpace.getNumberOfComponents());
             cosStream.setItem(COSName.ALTERNATE, colorSpace.getNumberOfComponents()
                     == 1 ? COSName.DEVICEGRAY : COSName.DEVICERGB);
+            cosStream.setItem(COSName.FILTER, COSName.FLATE_DECODE);
             if (state.iCCP != null)
             {
-                cosStream.setItem(COSName.FILTER, COSName.FLATE_DECODE);
                 // We need to skip over the name
                 int iccProfileDataStart = 0;
                 while (iccProfileDataStart < 80 && iccProfileDataStart < state.iCCP.length)
@@ -451,7 +454,7 @@ final class PNGConverter
             {
                 // We tag the image with the sRGB profile
                 ICC_Profile rgbProfile = ICC_Profile.getInstance(ColorSpace.CS_sRGB);
-                OutputStream outputStream = cosStream.createRawOutputStream();
+                OutputStream outputStream = cosStream.createOutputStream();
                 try
                 {
                     outputStream.write(rgbProfile.getData());
@@ -462,6 +465,7 @@ final class PNGConverter
                 }
             }
 
+            PDICCBased profile = PDICCBased.create(array, null);
             imageXObject.setColorSpace(profile);
         }
         return imageXObject;