pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From le...@apache.org
Subject [2/8] pdfbox-jbig2 git commit: initial commit of the JBig2 ImageIO plugin
Date Mon, 16 Oct 2017 18:09:15 GMT
http://git-wip-us.apache.org/repos/asf/pdfbox-jbig2/blob/4619d28b/src/test/java/org/apache/pdfbox/jbig2/JBIG2ImageReaderDemo.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/pdfbox/jbig2/JBIG2ImageReaderDemo.java b/src/test/java/org/apache/pdfbox/jbig2/JBIG2ImageReaderDemo.java
new file mode 100644
index 0000000..bb253cc
--- /dev/null
+++ b/src/test/java/org/apache/pdfbox/jbig2/JBIG2ImageReaderDemo.java
@@ -0,0 +1,79 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.pdfbox.jbig2;
+
+import java.awt.Rectangle;
+import java.awt.image.BufferedImage;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.reflect.InvocationTargetException;
+import java.net.URL;
+
+import javax.imageio.ImageReadParam;
+import javax.imageio.stream.ImageInputStream;
+
+import org.apache.pdfbox.jbig2.Bitmap;
+import org.apache.pdfbox.jbig2.JBIG2Document;
+import org.apache.pdfbox.jbig2.JBIG2ImageReader;
+import org.apache.pdfbox.jbig2.JBIG2ImageReaderSpi;
+import org.apache.pdfbox.jbig2.TestImage;
+import org.apache.pdfbox.jbig2.err.JBIG2Exception;
+import org.apache.pdfbox.jbig2.image.Bitmaps;
+import org.apache.pdfbox.jbig2.image.FilterType;
+import org.apache.pdfbox.jbig2.io.DefaultInputStreamFactory;
+
+public class JBIG2ImageReaderDemo {
+
+  private String filepath;
+  private int imageIndex;
+
+  public JBIG2ImageReaderDemo(String filepath, int imageIndex) {
+    this.filepath = filepath;
+    this.imageIndex = imageIndex;
+  }
+
+  public void show() throws IOException, JBIG2Exception {
+    InputStream inputStream = new FileInputStream(new File(filepath));
+    DefaultInputStreamFactory disf = new DefaultInputStreamFactory();
+    ImageInputStream imageInputStream = disf.getInputStream(inputStream);
+
+    JBIG2ImageReader imageReader = new JBIG2ImageReader(new JBIG2ImageReaderSpi());
+
+    imageReader.setInput(imageInputStream);
+    ImageReadParam param = new PreconfiguredImageReadParam(new Rectangle(100, 100, 500, 500));
+
+    long timeStamp = System.currentTimeMillis();
+
+    final JBIG2Document doc = new JBIG2Document(imageInputStream);
+    final Bitmap bitmap = doc.getPage(imageIndex).getBitmap();
+    final BufferedImage bufferedImage = Bitmaps.asBufferedImage(bitmap, param, FilterType.Lanczos);
+    long duration = System.currentTimeMillis() - timeStamp;
+    System.out.println(filepath + " decoding took " + duration + " ms");
+
+    new TestImage(bufferedImage);
+  }
+
+  public static void main(String[] args) throws InterruptedException, InvocationTargetException, IOException,
+      JBIG2Exception {
+    URL imageUrl = JBIG2ImageReaderDemo.class.getResource("/images/042_1.jb2");
+    new JBIG2ImageReaderDemo(imageUrl.getPath(), 1).show();
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/pdfbox-jbig2/blob/4619d28b/src/test/java/org/apache/pdfbox/jbig2/JBIG2ImageReaderTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/pdfbox/jbig2/JBIG2ImageReaderTest.java b/src/test/java/org/apache/pdfbox/jbig2/JBIG2ImageReaderTest.java
new file mode 100644
index 0000000..9da7b08
--- /dev/null
+++ b/src/test/java/org/apache/pdfbox/jbig2/JBIG2ImageReaderTest.java
@@ -0,0 +1,141 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.pdfbox.jbig2;
+
+import java.awt.image.BufferedImage;
+import java.awt.image.Raster;
+import java.io.IOException;
+import java.io.InputStream;
+
+import javax.imageio.ImageReadParam;
+import javax.imageio.ImageReader;
+import javax.imageio.stream.ImageInputStream;
+
+import junit.framework.Assert;
+
+import org.apache.pdfbox.jbig2.JBIG2ImageReader;
+import org.apache.pdfbox.jbig2.JBIG2ImageReaderSpi;
+import org.apache.pdfbox.jbig2.err.IntegerMaxValueException;
+import org.apache.pdfbox.jbig2.err.InvalidHeaderValueException;
+import org.apache.pdfbox.jbig2.io.DefaultInputStreamFactory;
+import org.junit.Test;
+
+public class JBIG2ImageReaderTest {
+
+  @Test
+  public void testGetDefaultReadParams() throws Exception {
+    ImageReader reader = new JBIG2ImageReader(new JBIG2ImageReaderSpi());
+    ImageReadParam param = reader.getDefaultReadParam();
+    Assert.assertNotNull(param);
+
+    Assert.assertNull(param.getSourceRegion());
+    Assert.assertNull(param.getSourceRenderSize());
+
+    Assert.assertEquals(1, param.getSourceXSubsampling());
+    Assert.assertEquals(1, param.getSourceYSubsampling());
+    Assert.assertEquals(0, param.getSubsamplingXOffset());
+    Assert.assertEquals(0, param.getSubsamplingYOffset());
+  }
+
+  @Test
+  public void testRead() throws IOException, InvalidHeaderValueException, IntegerMaxValueException {
+    String filepath = "/images/042_1.jb2";
+    int imageIndex = 0;
+
+    InputStream inputStream = getClass().getResourceAsStream(filepath);
+    DefaultInputStreamFactory disf = new DefaultInputStreamFactory();
+    ImageInputStream imageInputStream = disf.getInputStream(inputStream);
+
+    JBIG2ImageReader imageReader = new JBIG2ImageReader(new JBIG2ImageReaderSpi());
+    imageReader.setInput(imageInputStream);
+
+    // long timeStamp = System.currentTimeMillis();
+    BufferedImage bufferedImage = imageReader.read(imageIndex, imageReader.getDefaultReadParam());
+    // long duration = System.currentTimeMillis() - timeStamp;
+    // System.out.println(filepath + " decoding took " + duration + " ms");
+
+    Assert.assertNotNull(bufferedImage);
+  }
+
+  @Test
+  public void testReadRaster() throws IOException, InvalidHeaderValueException, IntegerMaxValueException {
+    String filepath = "/images/042_1.jb2";
+    int imageIndex = 0;
+
+    InputStream inputStream = getClass().getResourceAsStream(filepath);
+    DefaultInputStreamFactory disf = new DefaultInputStreamFactory();
+    ImageInputStream imageInputStream = disf.getInputStream(inputStream);
+
+    JBIG2ImageReader imageReader = new JBIG2ImageReader(new JBIG2ImageReaderSpi());
+    imageReader.setInput(imageInputStream);
+    Raster raster = imageReader.readRaster(imageIndex, imageReader.getDefaultReadParam());
+
+    Assert.assertNotNull(raster);
+  }
+
+  @Test
+  public void testReadImageReadParamNull() throws IOException, InvalidHeaderValueException, IntegerMaxValueException {
+    String filepath = "/images/042_1.jb2";
+    int imageIndex = 0;
+
+    InputStream inputStream = getClass().getResourceAsStream(filepath);
+    DefaultInputStreamFactory disf = new DefaultInputStreamFactory();
+    ImageInputStream imageInputStream = disf.getInputStream(inputStream);
+    JBIG2ImageReader imageReader = new JBIG2ImageReader(new JBIG2ImageReaderSpi());
+    imageReader.setInput(imageInputStream);
+    BufferedImage bufferedImage = imageReader.read(imageIndex, null);
+
+    Assert.assertNotNull(bufferedImage);
+  }
+
+  @Test
+  public void testReadRasterImageReadParamNull() throws IOException, InvalidHeaderValueException,
+      IntegerMaxValueException {
+    String filepath = "/images/042_1.jb2";
+    int imageIndex = 0;
+
+    InputStream inputStream = getClass().getResourceAsStream(filepath);
+    DefaultInputStreamFactory disf = new DefaultInputStreamFactory();
+    ImageInputStream imageInputStream = disf.getInputStream(inputStream);
+    JBIG2ImageReader imageReader = new JBIG2ImageReader(new JBIG2ImageReaderSpi());
+    imageReader.setInput(imageInputStream);
+    Raster raster = imageReader.readRaster(imageIndex, null);
+
+    Assert.assertNotNull(raster);
+  }
+
+  @Test
+  public void testGetNumImages() throws IOException, InvalidHeaderValueException, IntegerMaxValueException {
+    String filepath = "/images/002.jb2";
+
+    InputStream inputStream = getClass().getResourceAsStream(filepath);
+    DefaultInputStreamFactory disf = new DefaultInputStreamFactory();
+    ImageInputStream imageInputStream = disf.getInputStream(inputStream);
+    JBIG2ImageReader imageReader = new JBIG2ImageReader(new JBIG2ImageReaderSpi());
+    imageReader.setInput(imageInputStream);
+    int numImages = imageReader.getNumImages(true);
+    Assert.assertEquals(17, numImages);
+  }
+
+  @Test
+  public void testCanReadRaster() throws IOException {
+    JBIG2ImageReader imageReader = new JBIG2ImageReader(new JBIG2ImageReaderSpi());
+    Assert.assertTrue(imageReader.canReadRaster());
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/pdfbox-jbig2/blob/4619d28b/src/test/java/org/apache/pdfbox/jbig2/JBIG2PageTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/pdfbox/jbig2/JBIG2PageTest.java b/src/test/java/org/apache/pdfbox/jbig2/JBIG2PageTest.java
new file mode 100644
index 0000000..1fb6ae5
--- /dev/null
+++ b/src/test/java/org/apache/pdfbox/jbig2/JBIG2PageTest.java
@@ -0,0 +1,121 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.pdfbox.jbig2;
+
+import java.awt.Rectangle;
+import java.awt.image.BufferedImage;
+import java.io.IOException;
+import java.io.InputStream;
+
+import javax.imageio.stream.ImageInputStream;
+
+import org.apache.pdfbox.jbig2.Bitmap;
+import org.apache.pdfbox.jbig2.JBIG2Document;
+import org.apache.pdfbox.jbig2.JBIG2ReadParam;
+import org.apache.pdfbox.jbig2.TestImage;
+import org.apache.pdfbox.jbig2.err.JBIG2Exception;
+import org.apache.pdfbox.jbig2.image.Bitmaps;
+import org.apache.pdfbox.jbig2.image.FilterType;
+import org.apache.pdfbox.jbig2.io.DefaultInputStreamFactory;
+import org.junit.Ignore;
+import org.junit.Test;
+
+public class JBIG2PageTest {
+
+  // TESTS WITH TESTOUTPUT
+  // Ignore in build process
+
+  @Ignore
+  @Test
+  public void composeDisplayTest() throws IOException, JBIG2Exception {
+
+    String filepath = "/images/amb_1.jb2";
+    int pageNumber = 1;
+
+    InputStream is = getClass().getResourceAsStream(filepath);
+    DefaultInputStreamFactory disf = new DefaultInputStreamFactory();
+    ImageInputStream iis = disf.getInputStream(is);
+    JBIG2Document doc = new JBIG2Document(iis);
+
+    Bitmap pageBitmap = doc.getPage(pageNumber).getBitmap();
+    BufferedImage b = Bitmaps.asBufferedImage(pageBitmap, new JBIG2ReadParam(1, 1, 0, 0, new Rectangle(166, 333, 555,
+        444), null), FilterType.Gaussian);
+    new TestImage(b);
+  }
+
+  @Ignore
+  @Test
+  public void composeTestWithDurationCalc() throws IOException, JBIG2Exception {
+    int runs = 40;
+    long avg = 0;
+
+    String path = "/images/042_8.jb2";
+    int pageNumber = 1;
+
+    System.out.println("File: " + path);
+
+    InputStream is = getClass().getResourceAsStream(path);
+    DefaultInputStreamFactory disf = new DefaultInputStreamFactory();
+    ImageInputStream iis = disf.getInputStream(is);
+
+    for (int i = 0; i < runs; i++) {
+
+      long time = System.currentTimeMillis();
+      JBIG2Document doc = new JBIG2Document(iis);
+      Bitmap pageBitmap = doc.getPage(pageNumber).getBitmap();
+      Bitmaps.asBufferedImage(pageBitmap);
+      long duration = System.currentTimeMillis() - time;
+
+      System.out.println((i + 1) + ": " + duration + " ms");
+      avg += duration;
+    }
+    System.out.println("Average: " + avg / runs);
+  }
+
+  @Ignore
+  @Test
+  public void composeTestWithDurationCalcAggregate() throws IOException, JBIG2Exception {
+    int runs = 40;
+    long avg = 0;
+    String path = "/images/002.jb2";
+    int pages = 17;
+
+    System.out.println("File: " + path);
+
+    InputStream is = getClass().getResourceAsStream(path);
+    DefaultInputStreamFactory disf = new DefaultInputStreamFactory();
+    ImageInputStream iis = disf.getInputStream(is);
+
+    for (int j = 1; j <= pages; j++) {
+      avg = 0;
+
+      for (int i = 0; i < runs; i++) {
+        long time = System.currentTimeMillis();
+        JBIG2Document doc = new JBIG2Document(iis);
+        Bitmap pageBitmap = doc.getPage(j).getBitmap();
+        Bitmaps.asBufferedImage(pageBitmap);
+        long duration = System.currentTimeMillis() - time;
+        System.out.print((i + 1) + ": " + duration + " ms ");
+        avg += duration;
+      }
+      System.out.println();
+      System.out.println("Page " + j + " Average: " + avg / runs);
+    }
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/pdfbox-jbig2/blob/4619d28b/src/test/java/org/apache/pdfbox/jbig2/PreconfiguredImageReadParam.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/pdfbox/jbig2/PreconfiguredImageReadParam.java b/src/test/java/org/apache/pdfbox/jbig2/PreconfiguredImageReadParam.java
new file mode 100644
index 0000000..b8f58c0
--- /dev/null
+++ b/src/test/java/org/apache/pdfbox/jbig2/PreconfiguredImageReadParam.java
@@ -0,0 +1,56 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.pdfbox.jbig2;
+
+import java.awt.Dimension;
+import java.awt.Rectangle;
+
+import javax.imageio.ImageReadParam;
+
+public class PreconfiguredImageReadParam extends ImageReadParam {
+  public PreconfiguredImageReadParam(Rectangle sourceRegion) {
+    this.sourceRegion = sourceRegion;
+  }
+
+  public PreconfiguredImageReadParam(Dimension sourceRenderSize) {
+    this.sourceRenderSize = sourceRenderSize;
+  }
+
+  public PreconfiguredImageReadParam(int sourceXSubsampling, int sourceYSubsampling, int subsamplingXOffset,
+      int subsamplingYOffset) {
+    this.sourceXSubsampling = sourceXSubsampling;
+    this.sourceYSubsampling = sourceYSubsampling;
+    this.subsamplingXOffset = subsamplingXOffset;
+    this.subsamplingYOffset = subsamplingYOffset;
+  }
+
+  public PreconfiguredImageReadParam(Rectangle sourceRegion, Dimension sourceRenderSize) {
+    this.sourceRegion = sourceRegion;
+    this.sourceRenderSize = sourceRenderSize;
+  }
+
+  public PreconfiguredImageReadParam(Rectangle sourceRegion, Dimension sourceRenderSize, int sourceXSubsampling,
+      int sourceYSubsampling, int subsamplingXOffset, int subsamplingYOffset) {
+    this.sourceRegion = sourceRegion;
+    this.sourceRenderSize = sourceRenderSize;
+    this.sourceXSubsampling = sourceXSubsampling;
+    this.sourceYSubsampling = sourceYSubsampling;
+    this.subsamplingXOffset = subsamplingXOffset;
+    this.subsamplingYOffset = subsamplingYOffset;
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/pdfbox-jbig2/blob/4619d28b/src/test/java/org/apache/pdfbox/jbig2/decoder/arithmetic/ArithmeticDecoderTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/pdfbox/jbig2/decoder/arithmetic/ArithmeticDecoderTest.java b/src/test/java/org/apache/pdfbox/jbig2/decoder/arithmetic/ArithmeticDecoderTest.java
new file mode 100644
index 0000000..b29d03c
--- /dev/null
+++ b/src/test/java/org/apache/pdfbox/jbig2/decoder/arithmetic/ArithmeticDecoderTest.java
@@ -0,0 +1,577 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.pdfbox.jbig2.decoder.arithmetic;
+
+import java.io.InputStream;
+import javax.imageio.stream.ImageInputStream;
+
+import org.apache.pdfbox.jbig2.decoder.arithmetic.ArithmeticDecoder;
+import org.apache.pdfbox.jbig2.decoder.arithmetic.CX;
+import org.apache.pdfbox.jbig2.io.DefaultInputStreamFactory;
+import org.junit.*;
+
+public class ArithmeticDecoderTest {
+
+  long[][] tracedata = { //
+      {
+          0L, 0x8000L, 0x42638000L, 0x3D9C0000L
+      }, {
+          0L, 0xAC02L, 0x84C70000L, 0x273A0000L
+      }, {
+          0L, 0xF002L, 0xA18C7600L, 0x4E758800L
+      }, {
+          0L, 0xD801L, 0x898B7600L, 0x4E758800L
+      }, {
+          0L, 0xC000L, 0x718A7600L, 0x4E758800L
+      }, {
+          0L, 0xA7FFL, 0x59897600L, 0x4E758800L
+      }, {
+          0L, 0x8FFEL, 0x41887600L, 0x4E758800L
+      }, {
+          0L, 0xEFFAL, 0x530EEC00L, 0x9CEB1000L
+      }, {
+          0L, 0xE539L, 0x484DEC00L, 0x9CEB1000L
+      }, {
+          0L, 0xDA78L, 0x3D8CEC00L, 0x9CEB1000L
+      }, {
+          0L, 0xCFB7L, 0x32CBEC00L, 0x9CEB1000L
+      }, {
+          0L, 0xC4F6L, 0x280AEC00L, 0x9CEB1000L
+      }, {
+          0L, 0xBA35L, 0x1D49EC00L, 0x9CEB1000L
+      }, {
+          0L, 0xAF74L, 0x1288EC00L, 0x9CEB1000L
+      }, {
+          1L, 0xA4B3L, 0x07C7EC00L, 0x9CEB1000L
+      }, {
+          0L, 0xAC10L, 0x7C7EC000L, 0x2F910000L
+      }, {
+          0L, 0x900FL, 0x607DC000L, 0x2F910000L
+      }, {
+          0L, 0xE81CL, 0x88F98000L, 0x5F220000L
+      }, {
+          0L, 0xD21BL, 0x72F88000L, 0x5F220000L
+      }, {
+          0L, 0xBC1AL, 0x5CF78000L, 0x5F220000L
+      }, {
+          0L, 0xA619L, 0x46F68000L, 0x5F220000L
+      }, {
+          0L, 0x9018L, 0x30F58000L, 0x5F220000L
+      }, {
+          0L, 0xF42EL, 0x35E90000L, 0xBE440000L
+      }, {
+          0L, 0xE32DL, 0x24E80000L, 0xBE440000L
+      }, {
+          0L, 0xD22CL, 0x13E70000L, 0xBE440000L
+      }, {
+          1L, 0xC12BL, 0x02E60000L, 0xBE440000L
+      }, {
+          0L, 0x8808L, 0x1737E000L, 0x70D01800L
+      }, {
+          1L, 0xE80EL, 0x066DC000L, 0xE1A03000L
+      }, {
+          0L, 0x9008L, 0x336E0000L, 0x5C998000L
+      }, {
+          0L, 0xF40EL, 0x3ADA0000L, 0xB9330000L
+      }, {
+          0L, 0xE00DL, 0x26D90000L, 0xB9330000L
+      }, {
+          1L, 0xCC0CL, 0x12D80000L, 0xB9330000L
+      }, {
+          0L, 0xA008L, 0x96C70800L, 0x0940F000L
+      }, {
+          0L, 0x8807L, 0x7EC60800L, 0x0940F000L
+      }, {
+          0L, 0xE00CL, 0xCD8A1000L, 0x1281E000L
+      }, {
+          0L, 0xCA0BL, 0xB7891000L, 0x1281E000L
+      }, {
+          0L, 0xB40AL, 0xA1881000L, 0x1281E000L
+      }, {
+          0L, 0x9E09L, 0x8B871000L, 0x1281E000L
+      }, {
+          0L, 0x8808L, 0x75861000L, 0x1281E000L
+      }, {
+          0L, 0xE40EL, 0xBF0A2000L, 0x2503C000L
+      }, {
+          0L, 0xD00DL, 0xAB092000L, 0x2503C000L
+      }, {
+          0L, 0xBC0CL, 0x97082000L, 0x2503C000L
+      }, {
+          0L, 0xA80BL, 0x83072000L, 0x2503C000L
+      }, {
+          0L, 0x940AL, 0x6F062000L, 0x2503C000L
+      }, {
+          0L, 0x8009L, 0x5B052000L, 0x2503C000L
+      }, {
+          0L, 0xD810L, 0x8E084000L, 0x4A078000L
+      }, {
+          0L, 0xC60FL, 0x7C074000L, 0x4A078000L
+      }, {
+          0L, 0xB40EL, 0x6A064000L, 0x4A078000L
+      }, {
+          0L, 0xA20DL, 0x58054000L, 0x4A078000L
+      }, {
+          0L, 0x900CL, 0x46044000L, 0x4A078000L
+      }, {
+          0L, 0xFC16L, 0x68068000L, 0x940F0000L
+      }, {
+          0L, 0xEB15L, 0x57058000L, 0x940F0000L
+      }, {
+          0L, 0xDA14L, 0x46048000L, 0x940F0000L
+      }, {
+          0L, 0xC913L, 0x35038000L, 0x940F0000L
+      }, {
+          0L, 0xB812L, 0x24028000L, 0x940F0000L
+      }, {
+          0L, 0xA711L, 0x13018000L, 0x940F0000L
+      }, {
+          1L, 0x9610L, 0x02008000L, 0x940F0000L
+      }, {
+          1L, 0x8808L, 0x10068400L, 0x78017800L
+      }, {
+          0L, 0xA008L, 0x80342000L, 0x1FD3C000L
+      }, {
+          0L, 0x8807L, 0x68332000L, 0x1FD3C000L
+      }, {
+          0L, 0xE00CL, 0xA0644000L, 0x3FA78000L
+      }, {
+          0L, 0xCA0BL, 0x8A634000L, 0x3FA78000L
+      }, {
+          0L, 0xB40AL, 0x74624000L, 0x3FA78000L
+      }, {
+          0L, 0x9E09L, 0x5E614000L, 0x3FA78000L
+      }, {
+          0L, 0x8808L, 0x48604000L, 0x3FA78000L
+      }, {
+          0L, 0xE40EL, 0x64BE8000L, 0x7F4F0000L
+      }, {
+          0L, 0xD00DL, 0x50BD8000L, 0x7F4F0000L
+      }, {
+          0L, 0xBC0CL, 0x3CBC8000L, 0x7F4F0000L
+      }, {
+          0L, 0xA80BL, 0x28BB8000L, 0x7F4F0000L
+      }, {
+          0L, 0x940AL, 0x14BA8000L, 0x7F4F0000L
+      }, {
+          1L, 0x8009L, 0x00B98000L, 0x7F4F0000L
+      }, {
+          1L, 0xA008L, 0x05CD0C00L, 0x9A3AF000L
+      }, {
+          0L, 0xC008L, 0x2E686000L, 0x919F8000L
+      }, {
+          1L, 0x9E07L, 0x0C676000L, 0x919F8000L
+      }, {
+          0L, 0x8804L, 0x319D8000L, 0x56660000L
+      }, {
+          1L, 0xC006L, 0x13390000L, 0xACCC0000L
+      }, {
+          0L, 0x9004L, 0x4CE41000L, 0x431FEC00L
+      }, {
+          0L, 0xC006L, 0x39C62000L, 0x863FD800L
+      }, {
+          1L, 0x9805L, 0x11C52000L, 0x863FD800L
+      }, {
+          0L, 0xA004L, 0x47148000L, 0x58EF6000L
+      }, {
+          1L, 0xD806L, 0x26270000L, 0xB1DEC000L
+      }, {
+          0L, 0xC004L, 0x989C0000L, 0x27670000L
+      }, {
+          0L, 0x8C03L, 0x649B0000L, 0x27670000L
+      }, {
+          0L, 0xB004L, 0x61340400L, 0x4ECFFA00L
+      }, {
+          0L, 0x8003L, 0x31330400L, 0x4ECFFA00L
+      }, {
+          1L, 0xA004L, 0x02640800L, 0x9D9FF400L
+      }, {
+          1L, 0xA004L, 0x09902000L, 0x9673D000L
+      }, {
+          1L, 0xD004L, 0x26408000L, 0xA9C34000L
+      }, {
+          0L, 0xE004L, 0x99020000L, 0x47010000L
+      }, {
+          0L, 0x9803L, 0x51010000L, 0x47010000L
+      }, {
+          1L, 0xA004L, 0x12004000L, 0x8E03BE00L
+      }, {
+          0L, 0xE004L, 0x48010000L, 0x9802F800L
+      }, {
+          1L, 0x9803L, 0x00000000L, 0x9802F800L
+      }, {
+          0L, 0x9002L, 0x00000000L, 0x9001F000L
+      }, {
+          1L, 0xA202L, 0x00000000L, 0xA201E000L
+      }, {
+          0L, 0x9002L, 0x00000000L, 0x9001C000L
+      }, {
+          1L, 0xA202L, 0x00000000L, 0xA2018000L
+      }, {
+          0L, 0x9002L, 0x00000000L, 0x90010000L
+      }, {
+          1L, 0xA202L, 0x00000000L, 0xA201FE00L
+      }, {
+          0L, 0x9002L, 0x00000000L, 0x9001FC00L
+      }, {
+          1L, 0xA202L, 0x00000000L, 0xA201F800L
+      }, {
+          0L, 0x9002L, 0x00000000L, 0x9001F000L
+      }, {
+          1L, 0xA202L, 0x00000000L, 0xA201E000L
+      }, {
+          0L, 0x9002L, 0x00000000L, 0x9001C000L
+      }, {
+          1L, 0xA202L, 0x00000000L, 0xA2018000L
+      }, {
+          0L, 0x9002L, 0x00000000L, 0x90010000L
+      }, {
+          1L, 0xA202L, 0x00000000L, 0xA201FE00L
+      }, {
+          0L, 0x9002L, 0x00000000L, 0x9001FC00L
+      }, {
+          1L, 0xA202L, 0x00000000L, 0xA201F800L
+      }, {
+          0L, 0x9002L, 0x00000000L, 0x9001F000L
+      }, {
+          1L, 0xA202L, 0x00000000L, 0xA201E000L
+      }, {
+          0L, 0x9002L, 0x00000000L, 0x9001C000L
+      }, {
+          1L, 0xA202L, 0x00000000L, 0xA2018000L
+      }, {
+          0L, 0x9002L, 0x00000000L, 0x90010000L
+      }, {
+          1L, 0xA202L, 0x00008200L, 0xA2017C00L
+      }, {
+          0L, 0x9002L, 0x00010400L, 0x9000F800L
+      }, {
+          1L, 0xA202L, 0x00020800L, 0xA1FFF000L
+      }, {
+          0L, 0x9002L, 0x00041000L, 0x8FFDE000L
+      }, {
+          1L, 0xA202L, 0x00082000L, 0xA1F9C000L
+      }, {
+          0L, 0x9002L, 0x00104000L, 0x8FF18000L
+      }, {
+          1L, 0xA202L, 0x00208000L, 0xA1E10000L
+      }, {
+          0L, 0x9002L, 0x00410000L, 0x8FC00000L
+      }, {
+          1L, 0xA202L, 0x00821A00L, 0xA17FE400L
+      }, {
+          0L, 0x9002L, 0x01043400L, 0x8EFDC800L
+      }, {
+          1L, 0xA202L, 0x02086800L, 0x9FF99000L
+      }, {
+          0L, 0x9002L, 0x0410D000L, 0x8BF12000L
+      }, {
+          1L, 0xA202L, 0x0821A000L, 0x99E04000L
+      }, {
+          0L, 0x9002L, 0x10434000L, 0x7FBE8000L
+      }, {
+          1L, 0xA202L, 0x20868000L, 0x817B0000L
+      }, {
+          0L, 0x9002L, 0x410D0000L, 0x4EF40000L
+      }, {
+          0L, 0xA202L, 0x821B7600L, 0x1FE68800L
+      }, {
+          0L, 0xB402L, 0x7434EC00L, 0x3FCD1000L
+      }, {
+          0L, 0xF802L, 0x7867D800L, 0x7F9A2000L
+      }, {
+          0L, 0xC401L, 0x4466D800L, 0x7F9A2000L
+      }, {
+          1L, 0x9000L, 0x1065D800L, 0x7F9A2000L
+      }, {
+          0L, 0xD004L, 0x41976000L, 0x8E6C8000L
+      }, {
+          1L, 0x9803L, 0x09966000L, 0x8E6C8000L
+      }, {
+          1L, 0xE004L, 0x26598000L, 0xB9AA0000L
+      }, {
+          0L, 0x9002L, 0x4CB30000L, 0x434E0000L
+      }, {
+          0L, 0xA202L, 0x99670C00L, 0x089AF200L
+      }, {
+          0L, 0xB402L, 0xA2CC1800L, 0x1135E400L
+      }, {
+          0L, 0xF802L, 0xD5963000L, 0x226BC800L
+      }, {
+          0L, 0xC401L, 0xA1953000L, 0x226BC800L
+      }, {
+          0L, 0x9000L, 0x6D943000L, 0x226BC800L
+      }, {
+          0L, 0xB7FEL, 0x73266000L, 0x44D79000L
+      }, {
+          0L, 0x87FDL, 0x43256000L, 0x44D79000L
+      }, {
+          1L, 0xAFF8L, 0x2648C000L, 0x89AF2000L
+      }, {
+          0L, 0xA004L, 0x99230000L, 0x06E08000L
+      }, {
+          0L, 0xD806L, 0xCA440000L, 0x0DC10000L
+      }, {
+          0L, 0xA805L, 0x9A430000L, 0x0DC10000L
+      }, {
+          0L, 0xF008L, 0xD485E800L, 0x1B821600L
+      }, {
+          0L, 0xC807L, 0xAC84E800L, 0x1B821600L
+      }, {
+          0L, 0xA006L, 0x8483E800L, 0x1B821600L
+      }, {
+          0L, 0xF00AL, 0xB905D000L, 0x37042C00L
+      }, {
+          0L, 0xCC09L, 0x9504D000L, 0x37042C00L
+      }, {
+          0L, 0xA808L, 0x7103D000L, 0x37042C00L
+      }, {
+          0L, 0x8407L, 0x4D02D000L, 0x37042C00L
+      }, {
+          0L, 0xC00CL, 0x5203A000L, 0x6E085800L
+      }, {
+          0L, 0x9E0BL, 0x3002A000L, 0x6E085800L
+      }, {
+          0L, 0xF814L, 0x1C034000L, 0xDC10B000L
+      }, {
+          1L, 0xDC13L, 0x00024000L, 0xDC10B000L
+      }, {
+          1L, 0xE008L, 0x00120000L, 0xDFF58000L
+      }, {
+          1L, 0x9004L, 0x00486200L, 0x8FBB9C00L
+      }, {
+          1L, 0xC004L, 0x01218800L, 0xBEE27000L
+      }, {
+          1L, 0xD004L, 0x04862000L, 0xCB7DC000L
+      }, {
+          1L, 0xE004L, 0x12188000L, 0xCDEB0000L
+      }, {
+          0L, 0x9002L, 0x24310000L, 0x6BD00000L
+      }, {
+          0L, 0xA202L, 0x4862FE00L, 0x599F0000L
+      }, {
+          1L, 0xB402L, 0x00C3FC00L, 0xB33E0000L
+      }, {
+          1L, 0xE004L, 0x030FF000L, 0xDCF40000L
+      }, {
+          0L, 0x9002L, 0x061FE000L, 0x89E20000L
+      }, {
+          1L, 0xA202L, 0x0C3FC000L, 0x95C20000L
+      }, {
+          0L, 0x9002L, 0x187F8000L, 0x77820000L
+      }, {
+          1L, 0xA202L, 0x30FF0000L, 0x71020000L
+      }, {
+          1L, 0x9002L, 0x61FFFE00L, 0x2E020000L
+      }, {
+          1L, 0xFC04L, 0x43FBF800L, 0xB8080000L
+      }, {
+          1L, 0xA802L, 0x87F7F000L, 0x200A0000L
+      }, {
+          0L, 0xA402L, 0x63EDE000L, 0x40140000L
+      }, {
+          0L, 0x9C02L, 0x1BD9C000L, 0x80280000L
+      }, {
+          1L, 0xAC02L, 0x37B38000L, 0x744E0000L
+      }, {
+          1L, 0xA802L, 0x6F670000L, 0x389A0000L
+      }, {
+          1L, 0xA402L, 0x32CE2000L, 0x7133DC00L
+      }, {
+          1L, 0xAC02L, 0x659C4000L, 0x4665B800L
+      }, {
+          0L, 0xB002L, 0x23368000L, 0x8CCB7000L
+      }, {
+          1L, 0xA202L, 0x466D0000L, 0x5B94E000L
+      }, {
+          1L, 0xA802L, 0x8CDA0000L, 0x1B27C000L
+      }, {
+          1L, 0xAE02L, 0x77B20000L, 0x364F8000L
+      }, {
+          1L, 0xCC02L, 0x5F620000L, 0x6C9F0000L
+      }, {
+          0L, 0x9401L, 0x27610000L, 0x6C9F0000L
+      }, {
+          1L, 0xE004L, 0x9D87FC00L, 0x427C0000L
+      }, {
+          1L, 0x9803L, 0x5586FC00L, 0x427C0000L
+      }, {
+          0L, 0xA004L, 0x1B0BF800L, 0x84F80000L
+      }, {
+          1L, 0xE004L, 0x6C2FE000L, 0x73D40000L
+      }, {
+          0L, 0x9803L, 0x242EE000L, 0x73D40000L
+      }, {
+          1L, 0x9002L, 0x485DC000L, 0x47A40000L
+      }, {
+          1L, 0xA202L, 0x90BB8000L, 0x11460000L
+      }, {
+          1L, 0xB402L, 0x91750000L, 0x228C0000L
+      }, {
+          1L, 0xF802L, 0xB2E8DC00L, 0x45192000L
+      }, {
+          1L, 0xC401L, 0x7EE7DC00L, 0x45192000L
+      }, {
+          1L, 0x9000L, 0x4AE6DC00L, 0x45192000L
+      }, {
+          0L, 0xB7FEL, 0x2DCBB800L, 0x8A324000L
+      }, {
+          1L, 0xC004L, 0xB72EE000L, 0x08D50000L
+      }, {
+          1L, 0x8C03L, 0x832DE000L, 0x08D50000L
+      }, {
+          1L, 0xB004L, 0x9E59C000L, 0x11AA0000L
+      }, {
+          1L, 0x8003L, 0x6E58C000L, 0x11AA0000L
+      }, {
+          1L, 0xA004L, 0x7CAF8000L, 0x23540000L
+      }, {
+          1L, 0xF006L, 0xA95D0000L, 0x46A80000L
+      }, {
+          1L, 0xCC05L, 0x855C0000L, 0x46A80000L
+      }, {
+          1L, 0xA804L, 0x615B0000L, 0x46A80000L
+      }, {
+          1L, 0x8403L, 0x3D5A0000L, 0x46A80000L
+      }, {
+          1L, 0xC004L, 0x32B28E00L, 0x8D517000L
+      }, {
+          0L, 0x9E03L, 0x10B18E00L, 0x8D517000L
+      }, {
+          1L, 0x8804L, 0x42C63800L, 0x453DC000L
+      }, {
+          1L, 0xC006L, 0x358A7000L, 0x8A7B8000L
+      }, {
+          0L, 0x9C05L, 0x11897000L, 0x8A7B8000L
+      }, {
+          1L, 0x9004L, 0x4625C000L, 0x49DE0000L
+      }, {
+          1L, 0xC006L, 0x2C498000L, 0x93BC0000L
+      }, {
+          0L, 0x9805L, 0x04488000L, 0x93BC0000L
+      }, {
+          0L, 0xA004L, 0x11223400L, 0x8EE1CA00L
+      }, {
+          1L, 0xD004L, 0x4488D000L, 0x8B7B2800L
+      }, {
+          0L, 0x9803L, 0x0C87D000L, 0x8B7B2800L
+      }, {
+          0L, 0xE004L, 0x321F4000L, 0xADE4A000L
+      }, {
+          0L, 0x9002L, 0x643E8000L, 0x2BC34000L
+      }, {
+          0L, 0xFC04L, 0x4CF60000L, 0xAF0D0000L
+      }, {
+          0L, 0xA802L, 0x99EDB600L, 0x0E144800L
+      }, {
+          1L, 0xA402L, 0x87D96C00L, 0x1C289000L
+      }, {
+          0L, 0x9C02L, 0x63B0D800L, 0x38512000L
+      }, {
+          0L, 0x8C02L, 0x1B5FB000L, 0x70A24000L
+      }, {
+          1L, 0xAC02L, 0x36BF6000L, 0x75428000L
+      }, {
+          1L, 0xA802L, 0x6D7EC000L, 0x3A830000L
+      }, {
+          1L, 0xA402L, 0x2EFB8000L, 0x75060000L
+      }, {
+          1L, 0xAC02L, 0x5DF70000L, 0x4E0A0000L
+      }, {
+          0L, 0xB002L, 0x13ECD400L, 0x9C152A00L
+      }, {
+          1L, 0xA202L, 0x27D9A800L, 0x7A285400L
+      }, {
+          0L, 0xA802L, 0x4FB35000L, 0x584EA800L
+      }, {
+          0L, 0xA202L, 0x9F66A000L, 0x029B5000L
+      }, {
+          0L, 0x9C02L, 0x96CB4000L, 0x0536A000L
+      }, {
+          1L, 0x8C02L, 0x81948000L, 0x0A6D4000L
+      }, {
+          1L, 0xD804L, 0xAE4E0000L, 0x29B50000L
+      }, {
+          0L, 0x8203L, 0x584D0000L, 0x29B50000L
+      }, {
+          1L, 0xB008L, 0x09337C00L, 0xA6D48000L
+      }, {
+          0L, 0xAC02L, 0x1266F800L, 0x999B0000L
+      }, {
+          1L, 0xAC02L, 0x24CDF000L, 0x87340000L
+      }, {
+          0L, 0xAC02L, 0x499BE000L, 0x62660000L
+      }, {
+          0L, 0xAC02L, 0x9337C000L, 0x18CA0000L
+      }, {
+          0L, 0xAC02L, 0x7A6D8000L, 0x31940000L
+      }, {
+          1L, 0xB002L, 0x4CD90000L, 0x63280000L
+      }, {
+          1L, 0xA202L, 0x99B3FE00L, 0x084E0000L
+      }, {
+          1L, 0x9C02L, 0x8B65FC00L, 0x109C0000L
+      }, {
+          0L, 0x8C02L, 0x6AC9F800L, 0x21380000L
+      }, {
+          1L, 0xD804L, 0x5323E000L, 0x84E00000L
+      }, {
+          1L, 0xAC02L, 0xA647C000L, 0x05BA0000L
+      }, {
+          1L, 0xAC02L, 0xA08D8000L, 0x0B740000L
+      }, {
+          1L, 0xB002L, 0x99190000L, 0x16E80000L
+      }, {
+          1L, 0xBE02L, 0x9031FE00L, 0x2DD00000L
+      }, {
+          1L, 0xEC02L, 0x9061FC00L, 0x5BA00000L
+      },
+  };
+
+  @Test
+  public void decodeTest() throws Throwable {
+    InputStream is = getClass().getResourceAsStream("/images/arith/encoded testsequence");
+    DefaultInputStreamFactory factory = new DefaultInputStreamFactory();
+    ImageInputStream iis = factory.getInputStream(is);
+
+    ArithmeticDecoder decoder = new ArithmeticDecoder(iis);
+
+    CX cx = new CX(1, 0);
+    for (int i = 0; i < 257; i++) {
+      decoder.decode(cx);
+    }
+
+  }
+
+  @Test
+  public void decodeTestWithTracadataComparison() throws Throwable {
+    InputStream is = getClass().getResourceAsStream("/images/arith/encoded testsequence");
+    DefaultInputStreamFactory factory = new DefaultInputStreamFactory();
+    ImageInputStream iis = factory.getInputStream(is);
+
+    ArithmeticDecoder decoder = new ArithmeticDecoder(iis);
+    CX cx = new CX(1, 0);
+
+    for (int i = 0; i < 255; i++) {
+      Assert.assertEquals(tracedata[i][0], decoder.decode(cx));
+      Assert.assertEquals(tracedata[i + 1][1], (long) decoder.getA());
+      Assert.assertEquals(tracedata[i + 1][2], decoder.getC());
+
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/pdfbox-jbig2/blob/4619d28b/src/test/java/org/apache/pdfbox/jbig2/decoder/arithmetic/ArithmeticIntegerDecoderTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/pdfbox/jbig2/decoder/arithmetic/ArithmeticIntegerDecoderTest.java b/src/test/java/org/apache/pdfbox/jbig2/decoder/arithmetic/ArithmeticIntegerDecoderTest.java
new file mode 100644
index 0000000..a17b8c6
--- /dev/null
+++ b/src/test/java/org/apache/pdfbox/jbig2/decoder/arithmetic/ArithmeticIntegerDecoderTest.java
@@ -0,0 +1,46 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.pdfbox.jbig2.decoder.arithmetic;
+
+import java.io.InputStream;
+
+import javax.imageio.stream.ImageInputStream;
+
+import junit.framework.Assert;
+
+import org.apache.pdfbox.jbig2.decoder.arithmetic.ArithmeticDecoder;
+import org.apache.pdfbox.jbig2.decoder.arithmetic.ArithmeticIntegerDecoder;
+import org.apache.pdfbox.jbig2.io.DefaultInputStreamFactory;
+import org.junit.Test;
+
+public class ArithmeticIntegerDecoderTest {
+
+  @Test
+  public void decodeTest() throws Throwable {
+    InputStream is = getClass().getResourceAsStream("/images/arith/encoded testsequence");
+    DefaultInputStreamFactory isFactory = new DefaultInputStreamFactory();
+    ImageInputStream iis = isFactory.getInputStream(is);
+
+    ArithmeticDecoder ad = new ArithmeticDecoder(iis);
+    ArithmeticIntegerDecoder aid = new ArithmeticIntegerDecoder(ad);
+
+    long result = aid.decode(null);
+
+    Assert.assertEquals(1, result);
+  }
+}

http://git-wip-us.apache.org/repos/asf/pdfbox-jbig2/blob/4619d28b/src/test/java/org/apache/pdfbox/jbig2/decoder/mmr/MMRDecompressorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/pdfbox/jbig2/decoder/mmr/MMRDecompressorTest.java b/src/test/java/org/apache/pdfbox/jbig2/decoder/mmr/MMRDecompressorTest.java
new file mode 100644
index 0000000..9b3baba
--- /dev/null
+++ b/src/test/java/org/apache/pdfbox/jbig2/decoder/mmr/MMRDecompressorTest.java
@@ -0,0 +1,60 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.pdfbox.jbig2.decoder.mmr;
+
+import static org.junit.Assert.assertArrayEquals;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import javax.imageio.stream.ImageInputStream;
+
+import org.apache.pdfbox.jbig2.Bitmap;
+import org.apache.pdfbox.jbig2.decoder.mmr.MMRDecompressor;
+import org.apache.pdfbox.jbig2.err.InvalidHeaderValueException;
+import org.apache.pdfbox.jbig2.io.DefaultInputStreamFactory;
+import org.apache.pdfbox.jbig2.io.SubInputStream;
+import org.junit.Test;
+
+public class MMRDecompressorTest {
+
+  @Test
+  public void mmrDecodingTest() throws IOException, InvalidHeaderValueException {
+    final byte[] expected = new byte[]{
+        0, 0, 2, 34, 38, 102, -17, -1, 2, 102, 102, //
+        -18, -18, -17, -1, -1, 0, 2, 102, 102, 127, //
+        -1, -1, -1, 0, 0, 0, 4, 68, 102, 102, 127
+    };
+
+    final InputStream is = getClass().getResourceAsStream("/images/sampledata.jb2");
+    final DefaultInputStreamFactory disf = new DefaultInputStreamFactory();
+    final ImageInputStream iis = disf.getInputStream(is);
+
+    // Sixth Segment (number 5)
+    final SubInputStream sis = new SubInputStream(iis, 252, 38);
+
+    final MMRDecompressor mmrd = new MMRDecompressor(16 * 4, 4, sis);
+
+    final Bitmap b = mmrd.uncompress();
+    final byte[] actual = b.getByteArray();
+
+    assertArrayEquals(expected, actual);
+
+    // new TestImage(b.getByteArray(), (int) b.getWidth(), (int) b.getHeight(), b.getRowStride());
+  }
+}

http://git-wip-us.apache.org/repos/asf/pdfbox-jbig2/blob/4619d28b/src/test/java/org/apache/pdfbox/jbig2/image/BitmapsBlitTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/pdfbox/jbig2/image/BitmapsBlitTest.java b/src/test/java/org/apache/pdfbox/jbig2/image/BitmapsBlitTest.java
new file mode 100644
index 0000000..eb3f095
--- /dev/null
+++ b/src/test/java/org/apache/pdfbox/jbig2/image/BitmapsBlitTest.java
@@ -0,0 +1,78 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.pdfbox.jbig2.image;
+
+import static org.junit.Assert.assertArrayEquals;
+
+import java.awt.Rectangle;
+import java.io.IOException;
+import java.io.InputStream;
+
+import javax.imageio.stream.ImageInputStream;
+
+import org.apache.pdfbox.jbig2.Bitmap;
+import org.apache.pdfbox.jbig2.JBIG2DocumentFacade;
+import org.apache.pdfbox.jbig2.err.JBIG2Exception;
+import org.apache.pdfbox.jbig2.image.Bitmaps;
+import org.apache.pdfbox.jbig2.io.DefaultInputStreamFactory;
+import org.apache.pdfbox.jbig2.util.CombinationOperator;
+import org.junit.Test;
+
+public class BitmapsBlitTest {
+
+  @Test
+  public void testCompleteBitmapTransfer() throws IOException, JBIG2Exception {
+    final InputStream inputStream = getClass().getResourceAsStream("/images/042_1.jb2");
+    final DefaultInputStreamFactory disf = new DefaultInputStreamFactory();
+    final ImageInputStream iis = disf.getInputStream(inputStream);
+
+    final JBIG2DocumentFacade doc = new JBIG2DocumentFacade(iis);
+
+    final Bitmap src = doc.getPageBitmap(1);
+    final Bitmap dst = new Bitmap(src.getWidth(), src.getHeight());
+    Bitmaps.blit(src, dst, 0, 0, CombinationOperator.REPLACE);
+
+    final byte[] srcData = src.getByteArray();
+    final byte[] dstData = dst.getByteArray();
+
+    assertArrayEquals(srcData, dstData);
+  }
+
+  @Test
+  public void test() throws IOException, JBIG2Exception {
+    final InputStream inputStream = getClass().getResourceAsStream("/images/042_1.jb2");
+    final DefaultInputStreamFactory disf = new DefaultInputStreamFactory();
+    final ImageInputStream iis = disf.getInputStream(inputStream);
+
+    final JBIG2DocumentFacade doc = new JBIG2DocumentFacade(iis);
+
+    final Bitmap dst = doc.getPageBitmap(1);
+
+    final Rectangle roi = new Rectangle(100, 100, 100, 100);
+    final Bitmap src = new Bitmap(roi.width, roi.height);
+    Bitmaps.blit(src, dst, roi.x, roi.y, CombinationOperator.REPLACE);
+
+    final Bitmap dstRegionBitmap = Bitmaps.extract(roi, dst);
+
+    final byte[] srcData = src.getByteArray();
+    final byte[] dstRegionData = dstRegionBitmap.getByteArray();
+
+    assertArrayEquals(srcData, dstRegionData);
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/pdfbox-jbig2/blob/4619d28b/src/test/java/org/apache/pdfbox/jbig2/image/BitmapsByteCombinationTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/pdfbox/jbig2/image/BitmapsByteCombinationTest.java b/src/test/java/org/apache/pdfbox/jbig2/image/BitmapsByteCombinationTest.java
new file mode 100644
index 0000000..b1baed5
--- /dev/null
+++ b/src/test/java/org/apache/pdfbox/jbig2/image/BitmapsByteCombinationTest.java
@@ -0,0 +1,69 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.pdfbox.jbig2.image;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.Arrays;
+import java.util.Collection;
+
+import org.apache.pdfbox.jbig2.image.Bitmaps;
+import org.apache.pdfbox.jbig2.util.CombinationOperator;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+
+@RunWith(Parameterized.class)
+public class BitmapsByteCombinationTest {
+
+  private static final byte value1 = 0xA;
+  private static final byte value2 = 0xD;
+
+  private final int expected;
+  private final CombinationOperator operator;
+
+  @Parameters
+  public static Collection<Object[]> data() {
+    return Arrays.asList(new Object[][]{
+        {
+            0xF, CombinationOperator.OR
+        }, {
+            0x8, CombinationOperator.AND
+        }, {
+            0x7, CombinationOperator.XOR
+        }, {
+            -8, CombinationOperator.XNOR
+        }, {
+            value2, CombinationOperator.REPLACE
+        }
+    });
+  }
+
+  public BitmapsByteCombinationTest(final int expected, final CombinationOperator operator) {
+    this.expected = expected;
+    this.operator = operator;
+  }
+
+
+  @Test
+  public void test() {
+    assertEquals(expected, Bitmaps.combineBytes(value1, value2, operator));
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/pdfbox-jbig2/blob/4619d28b/src/test/java/org/apache/pdfbox/jbig2/image/BitmapsChecksumTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/pdfbox/jbig2/image/BitmapsChecksumTest.java b/src/test/java/org/apache/pdfbox/jbig2/image/BitmapsChecksumTest.java
new file mode 100644
index 0000000..8c8ccf8
--- /dev/null
+++ b/src/test/java/org/apache/pdfbox/jbig2/image/BitmapsChecksumTest.java
@@ -0,0 +1,177 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.pdfbox.jbig2.image;
+
+import static org.junit.Assert.assertArrayEquals;
+
+import java.awt.Dimension;
+import java.awt.Rectangle;
+import java.awt.image.DataBufferByte;
+import java.awt.image.WritableRaster;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+import java.util.Arrays;
+import java.util.Collection;
+
+import javax.imageio.ImageReadParam;
+import javax.imageio.stream.ImageInputStream;
+
+import org.apache.pdfbox.jbig2.Bitmap;
+import org.apache.pdfbox.jbig2.JBIG2DocumentFacade;
+import org.apache.pdfbox.jbig2.JBIG2ImageReaderDemo;
+import org.apache.pdfbox.jbig2.PreconfiguredImageReadParam;
+import org.apache.pdfbox.jbig2.err.JBIG2Exception;
+import org.apache.pdfbox.jbig2.image.Bitmaps;
+import org.apache.pdfbox.jbig2.image.FilterType;
+import org.apache.pdfbox.jbig2.io.DefaultInputStreamFactory;
+import org.apache.pdfbox.jbig2.io.InputStreamFactory;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+
+
+@RunWith(Parameterized.class)
+public class BitmapsChecksumTest {
+
+  private String resourcePath;
+  private ImageReadParam param;
+  private FilterType filterType;
+  private String checksum;
+  private int pageNumber;
+
+  @Parameters
+  public static Collection<Object[]> data() {
+    return Arrays.asList(new Object[][]{
+        {
+            "/images/042_1.jb2", 1, new PreconfiguredImageReadParam(new Dimension(500, 500)), FilterType.Bessel,
+            "101-6467-126-3534108-8927-58-26-37248672"
+        },
+        {
+            "/images/042_1.jb2", 1, new PreconfiguredImageReadParam(new Dimension(500, 800)), FilterType.Box,
+            "-748135-126-6412111-11925-1038826-95-32-6-104"
+        },
+        {
+            "/images/042_1.jb2", 1, new PreconfiguredImageReadParam(new Dimension(4000, 5500)), FilterType.Box,
+            "-646510160-466410970-77-1031184396-8-23-18"
+        },
+        {
+            "/images/042_1.jb2", 1, new PreconfiguredImageReadParam(new Dimension(600, 300)), FilterType.Bessel,
+            "-69-11478-721003586-100-72-85-1559101-118-24-94"
+        },
+        {
+            "/images/042_1.jb2", 1, new PreconfiguredImageReadParam(2, 2, 0, 0), FilterType.Bessel,
+            "-4979-94-68-125645751-2111712617-59-295"
+        },
+        {
+            "/images/042_1.jb2", 1, new PreconfiguredImageReadParam(2, 2, 0, 0), FilterType.Lanczos,
+            "-4979-94-68-125645751-2111712617-59-295"
+        },
+        {
+            "/images/042_1.jb2", 1, new PreconfiguredImageReadParam(3, 3, 1, 1), FilterType.Lanczos,
+            "84-1069410599-9575-7934-1279-80-85127-18-128"
+        },
+        {
+            "/images/042_1.jb2", 1, new PreconfiguredImageReadParam(new Rectangle(100, 100, 500, 500)),
+            FilterType.Lanczos, "1245-23-127954634-1232173-109-5739-303-48"
+        },
+        {
+            "/images/042_1.jb2", 1, new PreconfiguredImageReadParam(new Rectangle(500, 500, 2000, 2000)),
+            FilterType.Lanczos, "-60-45-117-90-6596-11556-47-30-112-741138412082"
+        },
+        {
+            "/images/042_1.jb2", 1,
+            new PreconfiguredImageReadParam(new Rectangle(500, 500, 2000, 2000), new Dimension(678, 931)),
+            FilterType.Lanczos, "-17-95-5543-12062-625054-94-88-31-4-120-1971"
+        },
+        {
+            "/images/042_1.jb2", 1,
+            new PreconfiguredImageReadParam(new Rectangle(500, 500, 2000, 2000), new Dimension(678, 931), 3, 3, 1, 1),
+            FilterType.Lanczos, "-109-60118-41999255-94113-5019-2818-10-39-71"
+        }
+    });
+  }
+
+  public BitmapsChecksumTest(String resourcePath, int pageNumber, ImageReadParam param, FilterType filterType,
+      String checksum) {
+    this.resourcePath = resourcePath;
+    this.pageNumber = pageNumber;
+    this.param = param;
+    this.filterType = filterType;
+    this.checksum = checksum;
+  }
+
+  @Test
+  public void test() throws IOException, JBIG2Exception, NoSuchAlgorithmException {
+    final InputStream inputStream = JBIG2ImageReaderDemo.class.getResourceAsStream(resourcePath);
+    final InputStreamFactory disf = new DefaultInputStreamFactory();
+    final ImageInputStream iis = disf.getInputStream(inputStream);
+
+    final JBIG2DocumentFacade doc = new JBIG2DocumentFacade(iis);
+    final Bitmap b = doc.getPageBitmap(pageNumber);
+    final WritableRaster raster = Bitmaps.asRaster(b, param, filterType);
+
+    final DataBufferByte dataBufferByte = (DataBufferByte) raster.getDataBuffer();
+    final byte[] bytes = dataBufferByte.getData();
+
+    final MessageDigest md = MessageDigest.getInstance("MD5");
+
+    final byte[] digest = md.digest(bytes);
+    final StringBuilder sb = new StringBuilder();
+    for (byte toAppend : digest) {
+      sb.append(toAppend);
+    }
+
+    assertArrayEquals(checksum.getBytes(), sb.toString().getBytes());
+  }
+
+  static class RasterChecksumCalculator {
+    public static void main(String[] args) throws IOException, JBIG2Exception, NoSuchAlgorithmException {
+      final String resourcePath = "/images/042_1.jb2";
+
+      final int pageNumber = 1;
+
+      final URL imageUrl = JBIG2ImageReaderDemo.class.getResource(resourcePath);
+
+      final InputStream inputStream = new FileInputStream(new File(imageUrl.getPath()));
+      final InputStreamFactory disf = new DefaultInputStreamFactory();
+      final ImageInputStream iis = disf.getInputStream(inputStream);
+
+      final JBIG2DocumentFacade doc = new JBIG2DocumentFacade(iis);
+      final Bitmap b = doc.getPageBitmap(pageNumber);
+
+      final ImageReadParam param = new PreconfiguredImageReadParam(new Rectangle(100, 100, 500, 500));
+
+      final WritableRaster raster = Bitmaps.asRaster(b, param, FilterType.Lanczos);
+      final DataBufferByte dataBufferByte = (DataBufferByte) raster.getDataBuffer();
+      final byte[] bytes = dataBufferByte.getData();
+
+      final MessageDigest md = MessageDigest.getInstance("MD5");
+
+      final byte[] digest = md.digest(bytes);
+      for (byte d : digest) {
+        System.out.print(d);
+      }
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/pdfbox-jbig2/blob/4619d28b/src/test/java/org/apache/pdfbox/jbig2/segments/GenericRegionTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/pdfbox/jbig2/segments/GenericRegionTest.java b/src/test/java/org/apache/pdfbox/jbig2/segments/GenericRegionTest.java
new file mode 100644
index 0000000..8692c6c
--- /dev/null
+++ b/src/test/java/org/apache/pdfbox/jbig2/segments/GenericRegionTest.java
@@ -0,0 +1,117 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.pdfbox.jbig2.segments;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import javax.imageio.stream.ImageInputStream;
+
+import junit.framework.Assert;
+
+import org.apache.pdfbox.jbig2.TestImage;
+import org.apache.pdfbox.jbig2.err.InvalidHeaderValueException;
+import org.apache.pdfbox.jbig2.image.Bitmaps;
+import org.apache.pdfbox.jbig2.io.DefaultInputStreamFactory;
+import org.apache.pdfbox.jbig2.io.SubInputStream;
+import org.apache.pdfbox.jbig2.segments.GenericRegion;
+import org.apache.pdfbox.jbig2.util.CombinationOperator;
+import org.junit.Ignore;
+import org.junit.Test;
+
+public class GenericRegionTest {
+
+  @Test
+  public void parseHeaderTest() throws IOException, InvalidHeaderValueException {
+    InputStream is = getClass().getResourceAsStream("/images/sampledata.jb2");
+    DefaultInputStreamFactory disf = new DefaultInputStreamFactory();
+    ImageInputStream iis = disf.getInputStream(is);
+
+    // Twelfth Segment (number 11)
+    SubInputStream sis = new SubInputStream(iis, 523, 35);
+    GenericRegion gr = new GenericRegion();
+    gr.init(null, sis);
+
+    Assert.assertEquals(54, gr.getRegionInfo().getBitmapWidth());
+    Assert.assertEquals(44, gr.getRegionInfo().getBitmapHeight());
+    Assert.assertEquals(4, gr.getRegionInfo().getXLocation());
+    Assert.assertEquals(11, gr.getRegionInfo().getYLocation());
+    Assert.assertEquals(CombinationOperator.OR, gr.getRegionInfo().getCombinationOperator());
+
+    Assert.assertFalse(gr.useExtTemplates());
+    Assert.assertFalse(gr.isMMREncoded());
+    Assert.assertEquals(0, gr.getGbTemplate());
+    Assert.assertTrue(gr.isTPGDon());
+
+    short[] gbAtX = gr.getGbAtX();
+    short[] gbAtY = gr.getGbAtY();
+    Assert.assertEquals(3, gbAtX[0]);
+    Assert.assertEquals(-1, gbAtY[0]);
+    Assert.assertEquals(-3, gbAtX[1]);
+    Assert.assertEquals(-1, gbAtY[1]);
+    Assert.assertEquals(2, gbAtX[2]);
+    Assert.assertEquals(-2, gbAtY[2]);
+    Assert.assertEquals(-2, gbAtX[3]);
+    Assert.assertEquals(-2, gbAtY[3]);
+  }
+
+  // TESTS WITH TESTOUTPUT
+  // Ignore in build process
+
+  @Ignore
+  @Test
+  public void decodeTemplate0Test() throws Throwable {
+    InputStream is = getClass().getResourceAsStream("/images/sampledata.jb2");
+    DefaultInputStreamFactory disf = new DefaultInputStreamFactory();
+    ImageInputStream iis = disf.getInputStream(is);
+    // Twelfth Segment (number 11)
+    SubInputStream sis = new SubInputStream(iis, 523, 35);
+    GenericRegion gr = new GenericRegion();
+
+    gr.init(null, sis);
+    new TestImage(Bitmaps.asBufferedImage(gr.getRegionBitmap()));
+  }
+
+  @Ignore
+  @Test
+  public void decodeWithArithmetichCoding() throws Throwable {
+
+    InputStream is = getClass().getResourceAsStream("/images/sampledata.jb2");
+    DefaultInputStreamFactory disf = new DefaultInputStreamFactory();
+    ImageInputStream iis = disf.getInputStream(is);
+    // Twelfth Segment (number 11)
+    SubInputStream sis = new SubInputStream(iis, 523, 35);
+    GenericRegion gr = new GenericRegion(sis);
+
+    gr.init(null, sis);
+    new TestImage(Bitmaps.asBufferedImage(gr.getRegionBitmap()));
+  }
+
+  @Ignore
+  @Test
+  public void decodeWithMMR() throws Throwable {
+    InputStream is = getClass().getResourceAsStream("/images/sampledata.jb2");
+    DefaultInputStreamFactory disf = new DefaultInputStreamFactory();
+    ImageInputStream iis = disf.getInputStream(is);
+    // Fifth Segment (number 4)
+    SubInputStream sis = new SubInputStream(iis, 190, 59);
+    GenericRegion gr = new GenericRegion(sis);
+    gr.init(null, sis);
+    new TestImage(Bitmaps.asBufferedImage(gr.getRegionBitmap()));
+  }
+}

http://git-wip-us.apache.org/repos/asf/pdfbox-jbig2/blob/4619d28b/src/test/java/org/apache/pdfbox/jbig2/segments/HalftoneRegionTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/pdfbox/jbig2/segments/HalftoneRegionTest.java b/src/test/java/org/apache/pdfbox/jbig2/segments/HalftoneRegionTest.java
new file mode 100644
index 0000000..64eae08
--- /dev/null
+++ b/src/test/java/org/apache/pdfbox/jbig2/segments/HalftoneRegionTest.java
@@ -0,0 +1,61 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.pdfbox.jbig2.segments;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import javax.imageio.stream.ImageInputStream;
+
+import junit.framework.Assert;
+
+import org.apache.pdfbox.jbig2.err.InvalidHeaderValueException;
+import org.apache.pdfbox.jbig2.io.DefaultInputStreamFactory;
+import org.apache.pdfbox.jbig2.io.SubInputStream;
+import org.apache.pdfbox.jbig2.segments.HalftoneRegion;
+import org.apache.pdfbox.jbig2.util.CombinationOperator;
+import org.junit.Test;
+
+public class HalftoneRegionTest {
+
+  @Test
+  public void parseHeaderTest() throws IOException, InvalidHeaderValueException {
+    InputStream is = getClass().getResourceAsStream("/images/sampledata.jb2");
+    DefaultInputStreamFactory disf = new DefaultInputStreamFactory();
+    ImageInputStream iis = disf.getInputStream(is);
+    // Seventh Segment (number 6)
+    SubInputStream sis = new SubInputStream(iis, 302, 87);
+    HalftoneRegion hr = new HalftoneRegion(sis);
+    hr.init(null, sis);
+
+    Assert.assertEquals(true, hr.isMMREncoded());
+    Assert.assertEquals(0, hr.getHTemplate());
+    Assert.assertEquals(false, hr.isHSkipEnabled());
+    Assert.assertEquals(CombinationOperator.OR, hr.getCombinationOperator());
+    Assert.assertEquals(0, hr.getHDefaultPixel());
+
+    Assert.assertEquals(8, hr.getHGridWidth());
+    Assert.assertEquals(9, hr.getHGridHeight());
+    Assert.assertEquals(0, hr.getHGridX());
+    Assert.assertEquals(0, hr.getHGridY());
+    Assert.assertEquals(1024, hr.getHRegionX());
+    Assert.assertEquals(0, hr.getHRegionY());
+
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/pdfbox-jbig2/blob/4619d28b/src/test/java/org/apache/pdfbox/jbig2/segments/PageInformationTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/pdfbox/jbig2/segments/PageInformationTest.java b/src/test/java/org/apache/pdfbox/jbig2/segments/PageInformationTest.java
new file mode 100644
index 0000000..2ef2cc2
--- /dev/null
+++ b/src/test/java/org/apache/pdfbox/jbig2/segments/PageInformationTest.java
@@ -0,0 +1,91 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.pdfbox.jbig2.segments;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import javax.imageio.stream.ImageInputStream;
+import junit.framework.Assert;
+
+import org.apache.pdfbox.jbig2.err.InvalidHeaderValueException;
+import org.apache.pdfbox.jbig2.io.*;
+import org.apache.pdfbox.jbig2.segments.PageInformation;
+import org.apache.pdfbox.jbig2.util.CombinationOperator;
+import org.junit.Ignore;
+import org.junit.Test;
+
+public class PageInformationTest {
+
+	@Test
+	public void parseHeaderCompleteTest() throws IOException,
+			InvalidHeaderValueException {
+		InputStream is = getClass().getResourceAsStream("/images/sampledata.jb2");
+		DefaultInputStreamFactory disf = new DefaultInputStreamFactory();
+		ImageInputStream iis = disf.getInputStream(is);
+		// Second Segment (number 1)
+		SubInputStream sis = new SubInputStream(iis, 59, 19);
+		PageInformation pi = new PageInformation();
+		pi.init(null, sis);
+		Assert.assertEquals(64, pi.getBitmapWidth());
+		Assert.assertEquals(56, pi.getBitmapHeight());
+		Assert.assertEquals(0, pi.getResolutionX());
+		Assert.assertEquals(0, pi.getResolutionY());
+		Assert.assertEquals(true, pi.isLossless());
+		Assert.assertEquals(false, pi.mightContainRefinements());
+		Assert.assertEquals(0, pi.getDefaultPixelValue());
+		Assert.assertEquals(CombinationOperator.OR, pi.getCombinationOperator());
+		Assert.assertEquals(false, pi.isAuxiliaryBufferRequired());
+		Assert.assertEquals(false, pi.isCombinationOperatorOverrideAllowed());
+		Assert.assertEquals(false, pi.isStriped());
+		Assert.assertEquals(0, pi.getMaxStripeSize());
+	}
+
+	@Ignore
+	@Test
+	public void parseHeaderXOROperatorTest() throws IOException,
+			InvalidHeaderValueException {
+		InputStream is = getClass().getResourceAsStream(
+				"/sampledata_pageinformation_with_xor-opartor.jb2");
+		DefaultInputStreamFactory disf = new DefaultInputStreamFactory();
+		ImageInputStream iis = disf.getInputStream(is);
+		// Second Segment (number 1)
+		SubInputStream sis = new SubInputStream(iis, 59, 19);
+		PageInformation pi = new PageInformation();
+		pi.init(null, sis);
+		// XOR (2) als Operator erwartet
+		Assert.assertEquals(2, pi.getCombinationOperator());
+	}
+
+	@Ignore
+	@Test
+	public void parseHeaderANDOperatorTest() throws IOException,
+			InvalidHeaderValueException {
+		InputStream is = getClass().getResourceAsStream(
+				"/sampledata_pageinformation_with_and-opartor.jb2");
+		DefaultInputStreamFactory disf = new DefaultInputStreamFactory();
+		ImageInputStream iis = disf.getInputStream(is);
+		// Second Segment (number 1)
+		SubInputStream sis = new SubInputStream(iis, 59, 19);
+		PageInformation pi = new PageInformation();
+		pi.init(null, sis);
+		Assert.assertEquals(true, pi.isLossless());
+		// AND (1) als Operator erwartet
+		Assert.assertEquals(1, pi.getCombinationOperator());
+	}
+}

http://git-wip-us.apache.org/repos/asf/pdfbox-jbig2/blob/4619d28b/src/test/java/org/apache/pdfbox/jbig2/segments/PatternDictionaryTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/pdfbox/jbig2/segments/PatternDictionaryTest.java b/src/test/java/org/apache/pdfbox/jbig2/segments/PatternDictionaryTest.java
new file mode 100644
index 0000000..0f32f0a
--- /dev/null
+++ b/src/test/java/org/apache/pdfbox/jbig2/segments/PatternDictionaryTest.java
@@ -0,0 +1,96 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.pdfbox.jbig2.segments;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+
+import javax.imageio.stream.ImageInputStream;
+
+import junit.framework.Assert;
+
+import org.apache.pdfbox.jbig2.*;
+import org.apache.pdfbox.jbig2.err.InvalidHeaderValueException;
+import org.apache.pdfbox.jbig2.io.*;
+import org.apache.pdfbox.jbig2.segments.*;
+import org.junit.Ignore;
+import org.junit.Test;
+
+public class PatternDictionaryTest {
+  @Test
+  public void parseHeaderTest() throws IOException, InvalidHeaderValueException {
+    InputStream is = getClass().getResourceAsStream("/images/sampledata.jb2");
+    DefaultInputStreamFactory disf = new DefaultInputStreamFactory();
+    ImageInputStream iis = disf.getInputStream(is);
+    // Sixth Segment (number 5)
+    SubInputStream sis = new SubInputStream(iis, 245, 45);
+    PatternDictionary pd = new PatternDictionary();
+    pd.init(null, sis);
+    Assert.assertEquals(true, pd.isMMREncoded());
+    Assert.assertEquals(0, pd.getHdTemplate());
+    Assert.assertEquals(4, pd.getHdpWidth());
+    Assert.assertEquals(4, pd.getHdpHeight());
+    Assert.assertEquals(15, pd.getGrayMax());
+  }
+
+  // TESTS WITH TESTOUTPUT
+  // Ignore in build process
+
+  @Ignore
+  @Test
+  public void decodeTestWithOutput() throws Throwable {
+    InputStream is = getClass().getResourceAsStream("/images/sampledata.jb2");
+    DefaultInputStreamFactory disf = new DefaultInputStreamFactory();
+    ImageInputStream iis = disf.getInputStream(is);
+    // Sixth Segment (number 5)
+    SubInputStream sis = new SubInputStream(iis, 245, 45);
+
+    PatternDictionary pd = new PatternDictionary();
+    pd.init(null, sis);
+
+    ArrayList<Bitmap> b = pd.getDictionary();
+
+    int i = 5;
+    // for (int i = 0; i < 8; i++) {
+    new TestImage(b.get(i).getByteArray(), (int) b.get(i).getWidth(), (int) b.get(i).getHeight(),
+        b.get(i).getRowStride());
+    // }
+  }
+
+  @Ignore
+  @Test
+  public void decodeTestWithOutput2() throws Throwable {
+    InputStream is = getClass().getResourceAsStream("/images/sampledata.jb2");
+    DefaultInputStreamFactory disf = new DefaultInputStreamFactory();
+    ImageInputStream iis = disf.getInputStream(is);
+    // Twelfth Segment (number 12)
+    SubInputStream sis = new SubInputStream(iis, 569, 28);
+
+    PatternDictionary pd = new PatternDictionary();
+    pd.init(null, sis);
+
+    ArrayList<Bitmap> b = pd.getDictionary();
+
+    int i = 2;
+    // for (int i = 0; i < 8; i++) {
+    new TestImage(b.get(i).getByteArray(), (int) b.get(i).getWidth(), (int) b.get(i).getHeight(),
+        b.get(i).getRowStride());
+    // }
+  }
+}

http://git-wip-us.apache.org/repos/asf/pdfbox-jbig2/blob/4619d28b/src/test/java/org/apache/pdfbox/jbig2/segments/RegionSegmentInformationTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/pdfbox/jbig2/segments/RegionSegmentInformationTest.java b/src/test/java/org/apache/pdfbox/jbig2/segments/RegionSegmentInformationTest.java
new file mode 100644
index 0000000..84b555a
--- /dev/null
+++ b/src/test/java/org/apache/pdfbox/jbig2/segments/RegionSegmentInformationTest.java
@@ -0,0 +1,50 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.pdfbox.jbig2.segments;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import javax.imageio.stream.ImageInputStream;
+
+import junit.framework.Assert;
+
+import org.apache.pdfbox.jbig2.io.DefaultInputStreamFactory;
+import org.apache.pdfbox.jbig2.io.SubInputStream;
+import org.apache.pdfbox.jbig2.segments.RegionSegmentInformation;
+import org.apache.pdfbox.jbig2.util.CombinationOperator;
+import org.junit.Ignore;
+import org.junit.Test;
+
+public class RegionSegmentInformationTest {
+
+  @Test
+  public void parseHeaderTest() throws IOException {
+    InputStream is = getClass().getResourceAsStream("/images/sampledata.jb2");
+    DefaultInputStreamFactory disf = new DefaultInputStreamFactory();
+    ImageInputStream iis = disf.getInputStream(is);
+    SubInputStream sis = new SubInputStream(iis, 130, 49);
+    RegionSegmentInformation rsi = new RegionSegmentInformation(sis);
+    rsi.parseHeader();
+    Assert.assertEquals(37, rsi.getBitmapWidth());
+    Assert.assertEquals(8, rsi.getBitmapHeight());
+    Assert.assertEquals(4, rsi.getXLocation());
+    Assert.assertEquals(1, rsi.getYLocation());
+    Assert.assertEquals(CombinationOperator.OR, rsi.getCombinationOperator());
+  }
+}

http://git-wip-us.apache.org/repos/asf/pdfbox-jbig2/blob/4619d28b/src/test/java/org/apache/pdfbox/jbig2/segments/SymbolDictionaryTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/pdfbox/jbig2/segments/SymbolDictionaryTest.java b/src/test/java/org/apache/pdfbox/jbig2/segments/SymbolDictionaryTest.java
new file mode 100644
index 0000000..8babe4b
--- /dev/null
+++ b/src/test/java/org/apache/pdfbox/jbig2/segments/SymbolDictionaryTest.java
@@ -0,0 +1,24 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.pdfbox.jbig2.segments;
+
+import org.junit.Ignore;
+
+@Ignore
+public class SymbolDictionaryTest {
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/pdfbox-jbig2/blob/4619d28b/src/test/java/org/apache/pdfbox/jbig2/segments/TextRegionTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/pdfbox/jbig2/segments/TextRegionTest.java b/src/test/java/org/apache/pdfbox/jbig2/segments/TextRegionTest.java
new file mode 100644
index 0000000..da6f961
--- /dev/null
+++ b/src/test/java/org/apache/pdfbox/jbig2/segments/TextRegionTest.java
@@ -0,0 +1,54 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.pdfbox.jbig2.segments;
+
+import java.awt.image.BufferedImage;
+import java.io.IOException;
+import java.io.InputStream;
+
+import javax.imageio.stream.ImageInputStream;
+
+import org.apache.pdfbox.jbig2.JBIG2ImageReader;
+import org.apache.pdfbox.jbig2.JBIG2ImageReaderSpi;
+import org.apache.pdfbox.jbig2.TestImage;
+import org.apache.pdfbox.jbig2.err.IntegerMaxValueException;
+import org.apache.pdfbox.jbig2.err.InvalidHeaderValueException;
+import org.apache.pdfbox.jbig2.io.DefaultInputStreamFactory;
+import org.junit.Ignore;
+import org.junit.Test;
+
+public class TextRegionTest {
+
+  // TESTS WITH TESTOUTPUT
+  // Ignore for in build process
+
+  @Ignore
+  @Test
+  public void textRegionWith() throws IOException, InvalidHeaderValueException, IntegerMaxValueException {
+    String filepath = "/images/042_11.jb2";
+    int pageNumber = 1;
+
+    InputStream is = getClass().getResourceAsStream(filepath);
+    DefaultInputStreamFactory disf = new DefaultInputStreamFactory();
+    ImageInputStream iis = disf.getInputStream(is);
+    JBIG2ImageReader jb2 = new JBIG2ImageReader(new JBIG2ImageReaderSpi());
+    jb2.setInput(iis);
+    BufferedImage b = jb2.read(pageNumber);
+    new TestImage(b);
+  }
+}

http://git-wip-us.apache.org/repos/asf/pdfbox-jbig2/blob/4619d28b/src/test/java/org/apache/pdfbox/jbig2/util/CacheFactoryTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/pdfbox/jbig2/util/CacheFactoryTest.java b/src/test/java/org/apache/pdfbox/jbig2/util/CacheFactoryTest.java
new file mode 100644
index 0000000..0f15338
--- /dev/null
+++ b/src/test/java/org/apache/pdfbox/jbig2/util/CacheFactoryTest.java
@@ -0,0 +1,41 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.pdfbox.jbig2.util;
+
+import static org.junit.Assert.assertNotNull;
+
+import org.apache.pdfbox.jbig2.util.cache.CacheBridge;
+import org.apache.pdfbox.jbig2.util.cache.CacheFactory;
+import org.junit.Test;
+
+public class CacheFactoryTest {
+
+  @Test
+  public void testWithDefaultClassLoader() {
+    CacheFactory.setClassLoader(CacheBridge.class.getClassLoader());
+    assertNotNull(CacheFactory.getCache());
+  }
+
+  @Test
+  public void testWithContextClassLoader() {
+    CacheFactory.setClassLoader(Thread.currentThread().getContextClassLoader());
+    assertNotNull(CacheFactory.getCache());
+  }
+
+
+}

http://git-wip-us.apache.org/repos/asf/pdfbox-jbig2/blob/4619d28b/src/test/java/org/apache/pdfbox/jbig2/util/LoggerFactoryTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/pdfbox/jbig2/util/LoggerFactoryTest.java b/src/test/java/org/apache/pdfbox/jbig2/util/LoggerFactoryTest.java
new file mode 100644
index 0000000..0fc89b6
--- /dev/null
+++ b/src/test/java/org/apache/pdfbox/jbig2/util/LoggerFactoryTest.java
@@ -0,0 +1,41 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.pdfbox.jbig2.util;
+
+import static org.junit.Assert.assertNotNull;
+
+import org.apache.pdfbox.jbig2.util.log.LoggerBridge;
+import org.apache.pdfbox.jbig2.util.log.LoggerFactory;
+import org.junit.Test;
+
+public class LoggerFactoryTest {
+
+  @Test
+  public void testWithDefaultClassLoader() {
+    LoggerFactory.setClassLoader(LoggerBridge.class.getClassLoader());
+    assertNotNull(LoggerFactory.getLogger(LoggerFactoryTest.class));
+  }
+  
+  @Test
+  public void testWithContextClassLoader() {
+    LoggerFactory.setClassLoader(Thread.currentThread().getContextClassLoader());
+    assertNotNull(LoggerFactory.getLogger(LoggerFactoryTest.class));
+  }
+  
+
+}

http://git-wip-us.apache.org/repos/asf/pdfbox-jbig2/blob/4619d28b/src/test/java/org/apache/pdfbox/jbig2/util/ServiceLookupTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/pdfbox/jbig2/util/ServiceLookupTest.java b/src/test/java/org/apache/pdfbox/jbig2/util/ServiceLookupTest.java
new file mode 100644
index 0000000..72c86ef
--- /dev/null
+++ b/src/test/java/org/apache/pdfbox/jbig2/util/ServiceLookupTest.java
@@ -0,0 +1,56 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.pdfbox.jbig2.util;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Iterator;
+
+import org.apache.pdfbox.jbig2.util.ServiceLookup;
+import org.junit.Test;
+
+public class ServiceLookupTest {
+
+  @Test
+  public void withDefaultClassLoader() {
+    runTest(null);
+  }
+
+  @Test
+  public void withContextClassLoader() {
+    runTest(Thread.currentThread().getContextClassLoader());
+  }
+
+  @Test
+  public void withClassLoaderFromClass() {
+    runTest(TestService.class.getClassLoader());
+  }
+  
+  private void runTest(ClassLoader clsLoader) {
+    ServiceLookup<TestService> serviceLookup = new ServiceLookup<TestService>();
+
+    Iterator<TestService> services = clsLoader != null
+        ? serviceLookup.getServices(TestService.class, clsLoader)
+        : serviceLookup.getServices(TestService.class);
+
+    assertTrue(services.hasNext());
+    assertEquals(TestServiceImpl.class, services.next().getClass());
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/pdfbox-jbig2/blob/4619d28b/src/test/java/org/apache/pdfbox/jbig2/util/TestService.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/pdfbox/jbig2/util/TestService.java b/src/test/java/org/apache/pdfbox/jbig2/util/TestService.java
new file mode 100644
index 0000000..1bb8b13
--- /dev/null
+++ b/src/test/java/org/apache/pdfbox/jbig2/util/TestService.java
@@ -0,0 +1,22 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.pdfbox.jbig2.util;
+
+public interface TestService {
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/pdfbox-jbig2/blob/4619d28b/src/test/java/org/apache/pdfbox/jbig2/util/TestServiceImpl.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/pdfbox/jbig2/util/TestServiceImpl.java b/src/test/java/org/apache/pdfbox/jbig2/util/TestServiceImpl.java
new file mode 100644
index 0000000..da1f608
--- /dev/null
+++ b/src/test/java/org/apache/pdfbox/jbig2/util/TestServiceImpl.java
@@ -0,0 +1,22 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.pdfbox.jbig2.util;
+
+public class TestServiceImpl implements TestService {
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/pdfbox-jbig2/blob/4619d28b/src/test/resources/META-INF/services/org.apache.pdfbox.jbig2.util.TestService
----------------------------------------------------------------------
diff --git a/src/test/resources/META-INF/services/org.apache.pdfbox.jbig2.util.TestService b/src/test/resources/META-INF/services/org.apache.pdfbox.jbig2.util.TestService
new file mode 100644
index 0000000..c916bc9
--- /dev/null
+++ b/src/test/resources/META-INF/services/org.apache.pdfbox.jbig2.util.TestService
@@ -0,0 +1,18 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+org.apache.pdfbox.jbig2.util.TestServiceImpl
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/pdfbox-jbig2/blob/4619d28b/src/test/resources/com/levigo/jbig2/github/21.glob
----------------------------------------------------------------------
diff --git a/src/test/resources/com/levigo/jbig2/github/21.glob b/src/test/resources/com/levigo/jbig2/github/21.glob
new file mode 100644
index 0000000..2261edf
Binary files /dev/null and b/src/test/resources/com/levigo/jbig2/github/21.glob differ

http://git-wip-us.apache.org/repos/asf/pdfbox-jbig2/blob/4619d28b/src/test/resources/com/levigo/jbig2/github/21.jb2
----------------------------------------------------------------------
diff --git a/src/test/resources/com/levigo/jbig2/github/21.jb2 b/src/test/resources/com/levigo/jbig2/github/21.jb2
new file mode 100644
index 0000000..25f8f05
Binary files /dev/null and b/src/test/resources/com/levigo/jbig2/github/21.jb2 differ

http://git-wip-us.apache.org/repos/asf/pdfbox-jbig2/blob/4619d28b/src/test/resources/images/001.jb2
----------------------------------------------------------------------
diff --git a/src/test/resources/images/001.jb2 b/src/test/resources/images/001.jb2
new file mode 100644
index 0000000..aad904f
Binary files /dev/null and b/src/test/resources/images/001.jb2 differ


Mime
View raw message