Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Imaging-161 #10

Open
wants to merge 2 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import org.apache.commons.imaging.ImageReadException;
import org.apache.commons.imaging.common.ImageBuilder;
import org.apache.commons.imaging.common.PackBits;
import org.apache.commons.imaging.common.itu_t4.T4AndT6Compression;
import org.apache.commons.imaging.formats.tiff.itu_t4.T4AndT6Compression;
import org.apache.commons.imaging.common.mylzw.MyLzwDecompressor;
import org.apache.commons.imaging.formats.tiff.TiffDirectory;
import org.apache.commons.imaging.formats.tiff.TiffField;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,33 +14,33 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.imaging.common.itu_t4;
package org.apache.commons.imaging.formats.tiff.itu_t4;

import java.io.OutputStream;

/**
* Output stream writing to a byte array, and capable
* of writing 1 bit at a time, starting from the most significant bit.
*/
class BitArrayOutputStream extends OutputStream {
final class BitArrayOutputStream extends OutputStream {
private byte[] buffer;
private int bytesWritten;
private int cache;
private int cacheMask = 0x80;

public BitArrayOutputStream() {
BitArrayOutputStream() {
buffer = new byte[16];
}

public BitArrayOutputStream(final int size) {
BitArrayOutputStream(final int size) {
buffer = new byte[size];
}

public int size() {
int size() {
return bytesWritten;
}

public byte[] toByteArray() {
byte[] toByteArray() {
flush();
if (bytesWritten == buffer.length) {
return buffer;
Expand Down Expand Up @@ -70,7 +70,7 @@ public void write(final int b) {
writeByte(b);
}

public void writeBit(final int bit) {
void writeBit(final int bit) {
if (bit != 0) {
cache |= cacheMask;
}
Expand All @@ -80,7 +80,7 @@ public void writeBit(final int bit) {
}
}

public int getBitsAvailableInCurrentByte() {
int getBitsAvailableInCurrentByte() {
int count = 0;
for (int mask = cacheMask; mask != 0; mask >>>= 1) {
++count;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.imaging.common.itu_t4;
package org.apache.commons.imaging.formats.tiff.itu_t4;

import java.io.IOException;
import java.io.InputStream;
Expand All @@ -24,15 +24,15 @@
* across byte boundaries in most significant
* bit first order.
*/
class BitInputStreamFlexible extends InputStream {
final class BitInputStreamFlexible extends InputStream {
// TODO should be byte order conscious, ie TIFF for reading
// samples size<8 - shuoldn't that effect their order within byte?
private final InputStream is;
private int cache;
private int cacheBitsRemaining;
private long bytesRead;

public BitInputStreamFlexible(final InputStream is) {
BitInputStreamFlexible(final InputStream is) {
this.is = is;
// super(is);
}
Expand All @@ -45,7 +45,7 @@ public int read() throws IOException {
return is.read();
}

public final int readBits(int count) throws IOException {
final int readBits(int count) throws IOException {

if (count <= 32) {
// catch-all
Expand Down Expand Up @@ -98,11 +98,11 @@ public final int readBits(int count) throws IOException {

}

public void flushCache() {
void flushCache() {
cacheBitsRemaining = 0;
}

public long getBytesRead() {
long getBytesRead() {
return bytesRead;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.imaging.common.itu_t4;
package org.apache.commons.imaging.formats.tiff.itu_t4;

import java.io.IOException;
import java.util.ArrayList;
Expand All @@ -23,15 +23,15 @@
/**
* A Huffman tree implemented as 1 array for high locality of reference.
*/
class HuffmanTree<T> {
final class HuffmanTree<T> {
private final List<Node<T>> nodes = new ArrayList<Node<T>>();

private static final class Node<T> {
boolean empty = true;
T value;
}

public final void insert(final String pattern, final T value) throws HuffmanTreeException {
final void insert(final String pattern, final T value) throws HuffmanTreeException {
int position = 0;
Node<T> node = growAndGetNode(position);
if (node.value != null) {
Expand Down Expand Up @@ -61,7 +61,7 @@ private Node<T> growAndGetNode(final int position) {
return node;
}

public final T decode(final BitInputStreamFlexible bitStream) throws HuffmanTreeException {
final T decode(final BitInputStreamFlexible bitStream) throws HuffmanTreeException {
int position = 0;
Node<T> node = nodes.get(0);
while (node.value == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.imaging.common.itu_t4;
package org.apache.commons.imaging.formats.tiff.itu_t4;

class HuffmanTreeException extends Exception {
final class HuffmanTreeException extends Exception {
private static final long serialVersionUID = 1L;

public HuffmanTreeException(final String message) {
HuffmanTreeException(final String message) {
super(message);
}

public HuffmanTreeException(final String message, final Throwable cause) {
HuffmanTreeException(final String message, final Throwable cause) {
super(message, cause);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.imaging.common.itu_t4;
package org.apache.commons.imaging.formats.tiff.itu_t4;

import java.io.ByteArrayInputStream;
import java.io.IOException;

import org.apache.commons.imaging.ImageReadException;
import org.apache.commons.imaging.ImageWriteException;
import org.apache.commons.imaging.common.itu_t4.T4_T6_Tables.Entry;
import org.apache.commons.imaging.formats.tiff.itu_t4.T4_T6_Tables.Entry;
import org.apache.commons.imaging.util.IoUtils;

public final class T4AndT6Compression {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.imaging.common.itu_t4;
package org.apache.commons.imaging.formats.tiff.itu_t4;

class T4_T6_Tables {
public static final Entry[] WHITE_TERMINATING_CODES = {
final class T4_T6_Tables {
static final Entry[] WHITE_TERMINATING_CODES = {
new Entry("00110101", 0),
new Entry("000111", 1),
new Entry("0111", 2),
Expand Down Expand Up @@ -83,7 +83,7 @@ class T4_T6_Tables {
new Entry("00110011", 62),
new Entry("00110100", 63), };

public static final Entry[] BLACK_TERMINATING_CODES = {
static final Entry[] BLACK_TERMINATING_CODES = {
new Entry("0000110111", 0),
new Entry("010", 1),
new Entry("11", 2),
Expand Down Expand Up @@ -149,7 +149,7 @@ class T4_T6_Tables {
new Entry("000001100110", 62),
new Entry("000001100111", 63), };

public static final Entry[] WHITE_MAKE_UP_CODES = {
static final Entry[] WHITE_MAKE_UP_CODES = {
new Entry("11011", 64),
new Entry("10010", 128),
new Entry("010111", 192),
Expand Down Expand Up @@ -178,7 +178,7 @@ class T4_T6_Tables {
new Entry("011000", 1664),
new Entry("010011011", 1728), };

public static final Entry[] BLACK_MAKE_UP_CODES = {
static final Entry[] BLACK_MAKE_UP_CODES = {
new Entry("0000001111", 64),
new Entry("000011001000", 128),
new Entry("000011001001", 192),
Expand Down Expand Up @@ -207,7 +207,7 @@ class T4_T6_Tables {
new Entry("0000001100100", 1664),
new Entry("0000001100101", 1728), };

public static final Entry[] ADDITIONAL_MAKE_UP_CODES = {
static final Entry[] ADDITIONAL_MAKE_UP_CODES = {
new Entry("00000001000", 1792),
new Entry("00000001100", 1856),
new Entry("00000001101", 1920),
Expand All @@ -222,34 +222,34 @@ class T4_T6_Tables {
new Entry("000000011110", 2496),
new Entry("000000011111", 2560), };

public static final Entry EOL = new Entry("000000000001", 0);
public static final Entry EOL13 = new Entry("0000000000001", 0);
public static final Entry EOL14 = new Entry("00000000000001", 0);
public static final Entry EOL15 = new Entry("000000000000001", 0);
public static final Entry EOL16 = new Entry("0000000000000001", 0);
public static final Entry EOL17 = new Entry("00000000000000001", 0);
public static final Entry EOL18 = new Entry("000000000000000001", 0);
public static final Entry EOL19 = new Entry("0000000000000000001", 0);
public static final Entry P = new Entry("0001", 0);
public static final Entry H = new Entry("001", 0);
public static final Entry V0 = new Entry("1", 0);
public static final Entry VR1 = new Entry("011", 0);
public static final Entry VR2 = new Entry("000011", 0);
public static final Entry VR3 = new Entry("0000011", 0);
public static final Entry VL1 = new Entry("010", 0);
public static final Entry VL2 = new Entry("000010", 0);
public static final Entry VL3 = new Entry("0000010", 0);
static final Entry EOL = new Entry("000000000001", 0);
static final Entry EOL13 = new Entry("0000000000001", 0);
static final Entry EOL14 = new Entry("00000000000001", 0);
static final Entry EOL15 = new Entry("000000000000001", 0);
static final Entry EOL16 = new Entry("0000000000000001", 0);
static final Entry EOL17 = new Entry("00000000000000001", 0);
static final Entry EOL18 = new Entry("000000000000000001", 0);
static final Entry EOL19 = new Entry("0000000000000000001", 0);
static final Entry P = new Entry("0001", 0);
static final Entry H = new Entry("001", 0);
static final Entry V0 = new Entry("1", 0);
static final Entry VR1 = new Entry("011", 0);
static final Entry VR2 = new Entry("000011", 0);
static final Entry VR3 = new Entry("0000011", 0);
static final Entry VL1 = new Entry("010", 0);
static final Entry VL2 = new Entry("000010", 0);
static final Entry VL3 = new Entry("0000010", 0);

public static class Entry {
static class Entry {
String bitString;
Integer value;

public Entry(final String bitString, final int value) {
Entry(final String bitString, final int value) {
this.bitString = bitString;
this.value = value;
}

public void writeBits(final BitArrayOutputStream outputStream) {
void writeBits(final BitArrayOutputStream outputStream) {
for (int i = 0; i < bitString.length(); i++) {
if (bitString.charAt(i) == '0') {
outputStream.writeBit(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@
/**
* Provides ITU-T T.4 and T.6 compression classes.
*/
package org.apache.commons.imaging.common.itu_t4;
package org.apache.commons.imaging.formats.tiff.itu_t4;

Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import org.apache.commons.imaging.common.BinaryOutputStream;
import org.apache.commons.imaging.common.PackBits;
import org.apache.commons.imaging.common.RationalNumber;
import org.apache.commons.imaging.common.itu_t4.T4AndT6Compression;
import org.apache.commons.imaging.formats.tiff.itu_t4.T4AndT6Compression;
import org.apache.commons.imaging.common.mylzw.MyLzwCompressor;
import org.apache.commons.imaging.formats.tiff.TiffElement;
import org.apache.commons.imaging.formats.tiff.TiffImageData;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import org.apache.commons.imaging.ImageWriteException;
import org.apache.commons.imaging.Imaging;
import org.apache.commons.imaging.ImagingConstants;
import org.apache.commons.imaging.common.itu_t4.T4AndT6Compression;
import org.apache.commons.imaging.formats.tiff.itu_t4.T4AndT6Compression;
import org.apache.commons.imaging.formats.tiff.constants.TiffConstants;
import org.apache.commons.imaging.util.Debug;
import org.junit.Test;
Expand Down