Author: tilman Date: Wed Mar 26 16:48:02 2014 New Revision: 1581928 URL: http://svn.apache.org/r1581928 Log: PDFBOX-1708: implemented EncodedByteAlign = true for CCITTFaxG31DDecodeInputStream
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/filter/CCITTFaxFilter.java pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/filter/ccitt/CCITTFaxG31DDecodeInputStream.java pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/filter/ccitt/TestCCITTFaxG31DDecodeInputStream.java Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/filter/CCITTFaxFilter.java URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/filter/CCITTFaxFilter.java?rev=1581928&r1=1581927&r2=1581928&view=diff ============================================================================== --- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/filter/CCITTFaxFilter.java (original) +++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/filter/CCITTFaxFilter.java Wed Mar 26 16:48:02 2014 @@ -100,7 +100,7 @@ final class CCITTFaxFilter extends Filte if (k == 0) { InputStream in = new CCITTFaxG31DDecodeInputStream( - new ByteArrayInputStream(compressed), cols); + new ByteArrayInputStream(compressed), cols, encodedByteAlign); in = new FillOrderChangeInputStream(in); //Decorate to change fill order decompressed = IOUtils.toByteArray(in); in.close(); Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/filter/ccitt/CCITTFaxG31DDecodeInputStream.java URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/filter/ccitt/CCITTFaxG31DDecodeInputStream.java?rev=1581928&r1=1581927&r2=1581928&view=diff ============================================================================== --- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/filter/ccitt/CCITTFaxG31DDecodeInputStream.java (original) +++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/filter/ccitt/CCITTFaxG31DDecodeInputStream.java Wed Mar 26 16:48:02 2014 @@ -35,6 +35,7 @@ public final class CCITTFaxG31DDecodeInp private InputStream source; private int columns; private int rows; + private boolean encodedByteAlign; //for reading compressed bits private int bits; @@ -60,27 +61,34 @@ public final class CCITTFaxG31DDecodeInp /** * Creates a new decoder. + * * @param source the input stream containing the compressed data. * @param columns the number of columns * @param rows the number of rows (0 if undefined) + * @param encodedByteAlign true if each encoded scan line is filled + * to a byte boundary, false if not */ - public CCITTFaxG31DDecodeInputStream(InputStream source, int columns, int rows) + public CCITTFaxG31DDecodeInputStream(InputStream source, int columns, int rows, boolean encodedByteAlign) { this.source = source; this.columns = columns; this.rows = rows; this.decodedLine = new PackedBitArray(columns); this.decodedReadPos = this.decodedLine.getByteCount(); + this.encodedByteAlign = encodedByteAlign; } /** * Creates a new decoder. + * * @param source the input stream containing the compressed data. * @param columns the number of columns + * @param encodedByteAlign true if each encoded scan line is filled + * to a byte boundary, false if not */ - public CCITTFaxG31DDecodeInputStream(InputStream source, int columns) + public CCITTFaxG31DDecodeInputStream(InputStream source, int columns, boolean encodedByteAlign) { - this(source, columns, 0); + this(source, columns, 0, encodedByteAlign); } /** {@inheritDoc} */ @@ -110,6 +118,10 @@ public final class CCITTFaxG31DDecodeInp private boolean decodeLine() throws IOException { + if (encodedByteAlign && this.bitPos != 0) + { + readByte(); + } if (this.bits < 0) { return false; //Shortcut after EOD Modified: pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/filter/ccitt/TestCCITTFaxG31DDecodeInputStream.java URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/filter/ccitt/TestCCITTFaxG31DDecodeInputStream.java?rev=1581928&r1=1581927&r2=1581928&view=diff ============================================================================== --- pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/filter/ccitt/TestCCITTFaxG31DDecodeInputStream.java (original) +++ pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/filter/ccitt/TestCCITTFaxG31DDecodeInputStream.java Wed Mar 26 16:48:02 2014 @@ -121,7 +121,7 @@ public class TestCCITTFaxG31DDecodeInput int rows = 2; //We actually have data for three rows. Just checking the restriction. CCITTFaxG31DDecodeInputStream decoder = new CCITTFaxG31DDecodeInputStream( - new ByteArrayInputStream(data), columns, rows); + new ByteArrayInputStream(data), columns, rows, false); byte[] decoded = IOUtils.toByteArray(decoder); decoder.close(); @@ -168,7 +168,7 @@ public class TestCCITTFaxG31DDecodeInput public static byte[] decode(byte[] data, int columns) throws IOException { CCITTFaxG31DDecodeInputStream decoder = new CCITTFaxG31DDecodeInputStream( - new ByteArrayInputStream(data), columns); + new ByteArrayInputStream(data), columns, false); byte[] decoded = IOUtils.toByteArray(decoder); decoder.close(); return decoded;