You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by le...@apache.org on 2011/07/04 19:47:51 UTC
svn commit: r1142749 -
/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/filter/CCITTFaxDecodeFilter.java
Author: lehmi
Date: Mon Jul 4 17:47:51 2011
New Revision: 1142749
URL: http://svn.apache.org/viewvc?rev=1142749&view=rev
Log:
PDFBOX-479: inline images don't provide the length of the data and are using abbreviations for the decode params
Modified:
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/filter/CCITTFaxDecodeFilter.java
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/filter/CCITTFaxDecodeFilter.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/filter/CCITTFaxDecodeFilter.java?rev=1142749&r1=1142748&r2=1142749&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/filter/CCITTFaxDecodeFilter.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/filter/CCITTFaxDecodeFilter.java Mon Jul 4 17:47:51 2011
@@ -16,6 +16,7 @@
*/
package org.apache.pdfbox.filter;
+import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@@ -56,7 +57,7 @@ public class CCITTFaxDecodeFilter implem
throws IOException
{
- COSBase decodeP = options.getDictionaryObject(COSName.DECODE_PARMS);
+ COSBase decodeP = options.getDictionaryObject(COSName.DECODE_PARMS, COSName.DP);
COSDictionary decodeParms = null;
if (decodeP instanceof COSDictionary)
{
@@ -66,12 +67,31 @@ public class CCITTFaxDecodeFilter implem
{
decodeParms = (COSDictionary)((COSArray)decodeP).get(0);
}
- int length = options.getInt(COSName.LENGTH);
- byte[] compressed = new byte[length];
- compressedData.read(compressed, 0, length);
+ int length = options.getInt(COSName.LENGTH, -1);
+ byte[] compressed = null;
+ if (length != -1)
+ {
+ compressed = new byte[length];
+ compressedData.read(compressed, 0, length);
+ }
+ else
+ {
+ // inline images don't provide the length of the stream so that
+ // we have to read until the end of the stream to find out the length
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ // the streams inline images are stored in are mostly small ones
+ int tempBufferlength = 512;
+ byte[] tempBuffer = new byte[tempBufferlength];
+ int bytesRead = 0;
+ while ( (bytesRead = compressedData.read(tempBuffer, 0, tempBufferlength)) != -1)
+ {
+ baos.write(tempBuffer, 0, bytesRead);
+ }
+ compressed = baos.toByteArray();
+ }
int cols = decodeParms.getInt(COSName.COLUMNS, 1728);
int rows = decodeParms.getInt(COSName.ROWS, 0);
- int height = options.getInt(COSName.HEIGHT, 0);
+ int height = options.getInt(COSName.HEIGHT, COSName.H, 0);
if (rows > 0 && height > 0)
{
// ensure that rows doesn't contain implausible data, see PDFBOX-771