pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From le...@apache.org
Subject svn commit: r1528826 - in /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox: filter/JPXFilter.java pdmodel/graphics/xobject/PDCcitt.java pdmodel/graphics/xobject/PDPixelMap.java
Date Thu, 03 Oct 2013 12:29:34 GMT
Author: lehmi
Date: Thu Oct  3 12:29:34 2013
New Revision: 1528826

URL: http://svn.apache.org/r1528826
Log:
PDFBOX-1735: fix/add wrong/missing values, added optional inversion as proposed by Tilman
Hausherr

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/filter/JPXFilter.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/xobject/PDCcitt.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/xobject/PDPixelMap.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/filter/JPXFilter.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/filter/JPXFilter.java?rev=1528826&r1=1528825&r2=1528826&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/filter/JPXFilter.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/filter/JPXFilter.java Thu Oct  3 12:29:34
2013
@@ -17,6 +17,7 @@
 package org.apache.pdfbox.filter;
 
 import java.awt.image.BufferedImage;
+import java.awt.image.ColorModel;
 import java.awt.image.DataBuffer;
 import java.awt.image.DataBufferByte;
 import java.io.IOException;
@@ -28,18 +29,20 @@ import javax.imageio.ImageIO;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.pdfbox.cos.COSDictionary;
+import org.apache.pdfbox.cos.COSName;
+import org.apache.pdfbox.pdmodel.graphics.color.PDColorSpaceFactory;
 
 /**
  * This is used for the JPXDecode filter.
  *
- * @author <a href="mailto:timo.boehme@ontochem.com">Timo Böhme</a>
+ * @author <a href="mailto:timo.boehme@ontochem.com">Timo Boehme</a>
  *
  */
 public class JPXFilter implements Filter
 {
 
     /** Log instance. */
-    private static final Log log = LogFactory.getLog(JPXFilter.class);
+    private static final Log LOG = LogFactory.getLog(JPXFilter.class);
 
     /**
      * Decode JPEG2000 data using Java ImageIO library.
@@ -47,20 +50,30 @@ public class JPXFilter implements Filter
      * {@inheritDoc}
      *
      */
-    public void decode( InputStream compressedData, OutputStream result, COSDictionary options,
int filterIndex )
-        throws IOException
+    public void decode(InputStream compressedData, OutputStream result, COSDictionary options,
int filterIndex)
+            throws IOException
     {
-        BufferedImage bi = ImageIO.read( compressedData );
-        if ( bi != null )
+        BufferedImage bi = ImageIO.read(compressedData);
+        if (bi != null)
         {
             DataBuffer dBuf = bi.getData().getDataBuffer();
-            if ( dBuf.getDataType() == DataBuffer.TYPE_BYTE )
+            if (dBuf.getDataType() == DataBuffer.TYPE_BYTE)
             {
-                result.write( ( ( DataBufferByte ) dBuf ).getData() );
+                // maybe some wrong/missing values have to be revised/added
+                ColorModel colorModel = bi.getColorModel();
+                if (options.getItem(COSName.COLORSPACE) == null)
+                {
+                    options.setItem(COSName.COLORSPACE,
+                            PDColorSpaceFactory.createColorSpace(null, colorModel.getColorSpace()));
+                }
+                options.setInt(COSName.BITS_PER_COMPONENT, colorModel.getPixelSize() / colorModel.getNumComponents());
+                options.setInt(COSName.HEIGHT, bi.getHeight());
+                options.setInt(COSName.WIDTH, bi.getWidth());
+                result.write(((DataBufferByte) dBuf).getData());
             }
             else
             {
-                log.error( "Image data buffer not of type byte but type " + dBuf.getDataType()
);
+                LOG.error("Image data buffer not of type byte but type " + dBuf.getDataType());
             }
         }
     }
@@ -68,9 +81,9 @@ public class JPXFilter implements Filter
     /**
      * {@inheritDoc}
      */
-    public void encode( InputStream rawData, OutputStream result, COSDictionary options,
int filterIndex )
-        throws IOException
+    public void encode(InputStream rawData, OutputStream result, COSDictionary options, int
filterIndex)
+            throws IOException
     {
-        System.err.println( "Warning: JPXFilter.encode is not implemented yet, skipping this
stream." );
+        LOG.error("Warning: JPXFilter.encode is not implemented yet, skipping this stream.");
     }
 }

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/xobject/PDCcitt.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/xobject/PDCcitt.java?rev=1528826&r1=1528825&r2=1528826&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/xobject/PDCcitt.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/xobject/PDCcitt.java
Thu Oct  3 12:29:34 2013
@@ -149,6 +149,13 @@ public class PDCcitt extends PDXObjectIm
             rows = Math.max(rows, height);
         }
         boolean blackIsOne = decodeParms.getBoolean(COSName.BLACK_IS_1, false);
+        // maybe a decode array is defined
+        COSArray decode = getDecode();
+        if (decode != null && decode.getInt(0) == 1)
+        {
+            // [1.0, 0.0] -> invert the "color" values
+            blackIsOne = !blackIsOne;
+        }
         byte[] bufferData = null;
         ColorModel colorModel = null;
         PDColorSpace colorspace = getColorSpace();
@@ -177,7 +184,6 @@ public class PDCcitt extends PDXObjectIm
         bufferData = buffer.getData();
         IOUtils.populateBuffer(stream.getUnfilteredStream(), bufferData);
         BufferedImage image = new BufferedImage(colorModel, raster, false, null);
-
         if (!blackIsOne)
         {
             // Inverting the bitmap
@@ -186,7 +192,6 @@ public class PDCcitt extends PDXObjectIm
             // So a safe but slower approach was taken.
             invertBitmap(bufferData);
         }
-
         /*
          * If we have an image mask we need to add an alpha channel to the data
          */
@@ -203,7 +208,6 @@ public class PDCcitt extends PDXObjectIm
             BufferedImage indexed = new BufferedImage(cm, raster, false, null);
             image = indexed;
         }
-
         return applyMasks(image);
     }
 

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/xobject/PDPixelMap.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/xobject/PDPixelMap.java?rev=1528826&r1=1528825&r2=1528826&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/xobject/PDPixelMap.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/xobject/PDPixelMap.java
Thu Oct  3 12:29:34 2013
@@ -175,24 +175,23 @@ public class PDPixelMap extends PDXObjec
         }
         try
         {
-            int width = getWidth();
-            int height = getHeight();
-            int bpc = getBitsPerComponent();
-
             byte[] array = getPDStream().getByteArray();
             if (array.length == 0)
             {
                 LOG.error("Something went wrong ... the pixelmap doesn't contain any data.");
                 return null;
             }
-            // Get the ColorModel right
+            int width = getWidth();
+            int height = getHeight();
+            int bpc = getBitsPerComponent();
+
             PDColorSpace colorspace = getColorSpace();
             if (colorspace == null)
             {
                 LOG.error("getColorSpace() returned NULL.");
                 return null;
             }
-
+            // Get the ColorModel right
             ColorModel cm = null;
             if (colorspace instanceof PDIndexed)
             {



Mime
View raw message