pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1841354 - in /pdfbox/trunk/pdfbox/src: main/java/org/apache/pdfbox/pdmodel/graphics/image/LosslessFactory.java test/java/org/apache/pdfbox/pdmodel/graphics/image/LosslessFactoryTest.java
Date Wed, 19 Sep 2018 17:07:14 GMT
Author: tilman
Date: Wed Sep 19 17:07:14 2018
New Revision: 1841354

URL: http://svn.apache.org/viewvc?rev=1841354&view=rev
Log:
PDFBOX-4184: keep ICC colorspace + set alternate colorspace, by Emmeran Seehuber

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/image/LosslessFactory.java
    pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/image/LosslessFactoryTest.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/image/LosslessFactory.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/image/LosslessFactory.java?rev=1841354&r1=1841353&r2=1841354&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/image/LosslessFactory.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/image/LosslessFactory.java
Wed Sep 19 17:07:14 2018
@@ -60,11 +60,20 @@ public final class LosslessFactory
     }
 
     /**
-     * Creates a new lossless encoded Image XObject from a Buffered Image.
+     * Creates a new lossless encoded image XObject from a BufferedImage.
+     * <p>
+     * <u>New for advanced users from 2.0.12 on:</u><br>
+     * If you created your image with a non standard ICC colorspace, it will be
+     * preserved. (If you load images in java using ImageIO then no need to read
+     * this segment) However a new colorspace will be created for each image. So
+     * if you create a PDF with several such images, consider replacing the
+     * colorspace with a common object to save space. This is done with
+     * {@link PDImageXObject#getColorSpace()} and
+     * {@link PDImageXObject#setColorSpace(org.apache.pdfbox.pdmodel.graphics.color.PDColorSpace)
PDImageXObject.setColorSpace()}
      *
      * @param document the document where the image will be created
-     * @param image the buffered image to embed
-     * @return a new Image XObject
+     * @param image the BufferedImage to embed
+     * @return a new image XObject
      * @throws IOException if something goes wrong
      */
     public static PDImageXObject createFromImage(PDDocument document, BufferedImage image)
@@ -572,6 +581,11 @@ public final class LosslessFactory
                     }
                     pdProfile.getPDStream().getCOSObject().setInt(COSName.N,
                             srcCspace.getNumComponents());
+                    pdProfile.getPDStream().getCOSObject().setItem(COSName.ALTERNATE,
+                            srcCspace.getType() == ColorSpace.TYPE_CMYK ?
+                                    COSName.DEVICECMYK :
+                                    COSName.DEVICERGB);
+                    pdColorSpace = pdProfile;
                 }
             }
 

Modified: pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/image/LosslessFactoryTest.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/image/LosslessFactoryTest.java?rev=1841354&r1=1841353&r2=1841354&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/image/LosslessFactoryTest.java
(original)
+++ pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/image/LosslessFactoryTest.java
Wed Sep 19 17:07:14 2018
@@ -431,21 +431,12 @@ public class LosslessFactoryTest extends
         BufferedImage imageCMYK = op.filter(image, null);
 
         PDImageXObject ximage = LosslessFactory.createFromImage(document, imageCMYK);
-        validate(ximage, 8, imageCMYK.getWidth(), imageCMYK.getHeight(), "png", PDDeviceCMYK.INSTANCE.getName());
+        validate(ximage, 8, imageCMYK.getWidth(), imageCMYK.getHeight(), "png", "ICCBased");
 
         doWritePDF(document, ximage, testResultsDir, "cmyk.pdf");
-
-        // The image in CMYK got color-truncated because the ISO_Coated colorspace is way
smaller 
-        // than the sRGB colorspace. The image is converted back to sRGB when calling PDImageXObject.getImage().
-        // So to be able to check the image data we must also convert our CMYK Image back
to sRGB
-        //BufferedImage compareImageRGB = new BufferedImage(imageCMYK.getWidth(), imageCMYK.getHeight(),
-        //BufferedImage.TYPE_INT_BGR);
-        //Graphics2D graphics = compareImageRGB.createGraphics();
-        //graphics.drawImage(imageCMYK, 0, 0, null);
-        //graphics.dispose();
-        //ImageIO.write(compareImageRGB, "TIFF", new File("/tmp/compare.tiff"));
-        //ImageIO.write(ximage.getImage(), "TIFF", new File("/tmp/compare2.tiff"));
-        //checkIdent(compareImageRGB, ximage.getImage());
+        
+        // still slight difference of 1 color level
+        //checkIdent(imageCMYK, ximage.getImage());
     }
 
     public void testCreateLosslessFrom16Bit() throws IOException



Mime
View raw message