mirror of
https://github.com/haraldk/TwelveMonkeys.git
synced 2026-04-30 00:00:01 -04:00
TMI-PNM: Initial commit.
This commit is contained in:
Executable
+110
@@ -0,0 +1,110 @@
|
||||
package com.twelvemonkeys.imageio.plugins.pnm;
|
||||
|
||||
import com.twelvemonkeys.imageio.util.ImageReaderAbstractTestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.imageio.ImageReader;
|
||||
import javax.imageio.spi.ImageReaderSpi;
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class PNMImageReaderTest extends ImageReaderAbstractTestCase<PNMImageReader>{
|
||||
@Override protected List<TestData> getTestData() {
|
||||
return Arrays.asList(
|
||||
new TestData(getClassLoaderResource("/ppm/lena.ppm"), new Dimension(128, 128)), // P6 (PPM RAW)
|
||||
new TestData(getClassLoaderResource("/ppm/colors.ppm"), new Dimension(3, 2)), // P3 (PPM PLAIN)
|
||||
new TestData(getClassLoaderResource("/pbm/j.pbm"), new Dimension(6, 10)), // P1 (PBM PLAIN)
|
||||
new TestData(getClassLoaderResource("/pgm/feep.pgm"), new Dimension(24, 7)), // P2 (PGM PLAIN)
|
||||
new TestData(getClassLoaderResource("/pgm/feep16.pgm"), new Dimension(24, 7)), // P2 (PGM PLAIN, 16 bits/sample)
|
||||
new TestData(getClassLoaderResource("/pgm/house.l.pgm"), new Dimension(367, 241)), // P5 (PGM RAW)
|
||||
new TestData(getClassLoaderResource("/ppm/lighthouse_rgb48.ppm"), new Dimension(768, 512)), // P6 (PPM RAW, 16 bits/sample)
|
||||
new TestData(getClassLoaderResource("/pam/lena.pam"), new Dimension(128, 128)), // P7 RGB
|
||||
new TestData(getClassLoaderResource("/pam/rgba.pam"), new Dimension(4, 2)) // P7 RGB_ALPHA
|
||||
);
|
||||
}
|
||||
|
||||
@Override protected ImageReaderSpi createProvider() {
|
||||
return new PNMImageReaderSpi();
|
||||
}
|
||||
|
||||
@Override protected Class<PNMImageReader> getReaderClass() {
|
||||
return PNMImageReader.class;
|
||||
}
|
||||
|
||||
@Override protected PNMImageReader createReader() {
|
||||
return new PNMImageReader(createProvider());
|
||||
}
|
||||
|
||||
@Override protected List<String> getFormatNames() {
|
||||
return Arrays.asList(
|
||||
"pnm", "pbm", "pgm", "ppm", "pam",
|
||||
"PNM", "PBM", "PGM", "PPM", "PAM"
|
||||
);
|
||||
}
|
||||
|
||||
@Override protected List<String> getSuffixes() {
|
||||
return Arrays.asList(
|
||||
"pbm", "pgm", "ppm", "pam"
|
||||
);
|
||||
}
|
||||
|
||||
@Override protected List<String> getMIMETypes() {
|
||||
return Arrays.asList(
|
||||
"image/x-portable-pixmap",
|
||||
"image/x-portable-anymap",
|
||||
"image/x-portable-arbitrarymap"
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testColorsVsReference() throws IOException {
|
||||
ImageReader reader = createReader();
|
||||
TestData data = new TestData(getClassLoaderResource("/ppm/colors.ppm"), new Dimension(3, 2));
|
||||
reader.setInput(data.getInputStream());
|
||||
|
||||
BufferedImage expected = new BufferedImage(3, 2, BufferedImage.TYPE_3BYTE_BGR);
|
||||
|
||||
expected.setRGB(0, 0, new Color(255, 0, 0).getRGB());
|
||||
expected.setRGB(1, 0, new Color(0, 255, 0).getRGB());
|
||||
expected.setRGB(2, 0, new Color(0, 0, 255).getRGB());
|
||||
|
||||
expected.setRGB(0, 1, new Color(255, 255, 0).getRGB());
|
||||
expected.setRGB(1, 1, new Color(255, 255, 255).getRGB());
|
||||
expected.setRGB(2, 1, new Color(0, 0, 0).getRGB());
|
||||
|
||||
assertImageDataEquals("Images differ from reference", expected, reader.read(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRGBAVsReference() throws IOException {
|
||||
ImageReader reader = createReader();
|
||||
TestData data = new TestData(getClassLoaderResource("/pam/rgba.pam"), new Dimension(4, 2));
|
||||
reader.setInput(data.getInputStream());
|
||||
|
||||
BufferedImage expected = new BufferedImage(4, 2, BufferedImage.TYPE_4BYTE_ABGR);
|
||||
|
||||
expected.setRGB(0, 0, new Color(0, 0, 255).getRGB());
|
||||
expected.setRGB(1, 0, new Color(0, 255, 0).getRGB());
|
||||
expected.setRGB(2, 0, new Color(255, 0, 0).getRGB());
|
||||
expected.setRGB(3, 0, new Color(255, 255, 255).getRGB());
|
||||
|
||||
expected.setRGB(0, 1, new Color(0, 0, 255, 127).getRGB());
|
||||
expected.setRGB(1, 1, new Color(0, 255, 0, 127).getRGB());
|
||||
expected.setRGB(2, 1, new Color(255, 0, 0, 127).getRGB());
|
||||
expected.setRGB(3, 1, new Color(255, 255, 255, 127).getRGB());
|
||||
|
||||
assertImageDataEquals("Images differ from reference", expected, reader.read(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testXVThumbNotIncorrectlyRecognizedAsPAM() throws IOException {
|
||||
ImageReaderSpi provider = createProvider();
|
||||
assertTrue("Should recognize PAM format", provider.canDecodeInput(new TestData(getClassLoaderResource("/pam/rgba.pam"), new Dimension()).getInputStream())); // Sanity
|
||||
assertFalse("Should distinguish xv-thumbs from PAM format", provider.canDecodeInput(new TestData(getClassLoaderResource("/xv-thumb/xv-thumb.xvt"), new Dimension()).getInputStream()));
|
||||
}
|
||||
}
|
||||
+8
File diff suppressed because one or more lines are too long
BIN
Binary file not shown.
BIN
Binary file not shown.
+13
@@ -0,0 +1,13 @@
|
||||
P1
|
||||
# This is an example bitmap of the letter "J"
|
||||
6 10
|
||||
0 0 0 0 1 0
|
||||
0 0 0 0 1 0
|
||||
0 0 0 0 1 0
|
||||
0 0 0 0 1 0
|
||||
0 0 0 0 1 0
|
||||
0 0 0 0 1 0
|
||||
1 0 0 0 1 0
|
||||
0 1 1 1 0 0
|
||||
0 0 0 0 0 0
|
||||
0 0 0 0 0 0
|
||||
BIN
Binary file not shown.
+11
@@ -0,0 +1,11 @@
|
||||
P2
|
||||
# Shows the word "FEEP" (example from Netpbm man page on PGM)
|
||||
24 7
|
||||
15
|
||||
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
0 3 3 3 3 0 0 7 7 7 7 0 0 11 11 11 11 0 0 15 15 15 15 0
|
||||
0 3 0 0 0 0 0 7 0 0 0 0 0 11 0 0 0 0 0 15 0 0 15 0
|
||||
0 3 3 3 0 0 0 7 7 7 0 0 0 11 11 11 0 0 0 15 15 15 15 0
|
||||
0 3 0 0 0 0 0 7 0 0 0 0 0 11 0 0 0 0 0 15 0 0 0 0
|
||||
0 3 0 0 0 0 0 7 7 7 7 0 0 11 11 11 11 0 0 15 0 0 0 0
|
||||
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
P2
|
||||
# Shows the word "FEEP" (modified example from Netpbm man page on PGM)
|
||||
24 7
|
||||
4095
|
||||
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
0 1023 1023 1023 1023 0 0 2047 2047 2047 2047 0 0 3071
|
||||
3071 3071 3071 0 0 4095 4095 4095 4095 0
|
||||
0 1023 0 0 0 0 0 2047 0 0 0 0 0 3071 0 0 0 0 0 4095
|
||||
0 0 4095 0 0 1023 1023 1023 0 0 0 2047 2047 2047 0 0 0
|
||||
3071 3071 3071 0 0 0 4095 4095 4095 4095 0
|
||||
0 1023 0 0 0 0 0 2047 0 0 0 0 0 3071 0 0 0 0 0 4095
|
||||
0 0 0 0 0 1023 0 0 0 0 0 2047 2047 2047 2047 0 0 3071
|
||||
3071 3071 3071 0 0 4095 0 0 0 0
|
||||
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
BIN
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,7 @@
|
||||
P3
|
||||
# The P3 means colors are in ASCII, then 3 columns and 2 rows,
|
||||
# then 255 for max color, then RGB triplets
|
||||
3 2
|
||||
255
|
||||
255 0 0 0 255 0 0 0 255
|
||||
255 255 0 255 255 255 0 0 0
|
||||
File diff suppressed because one or more lines are too long
+4
File diff suppressed because one or more lines are too long
+8225
File diff suppressed because one or more lines are too long
@@ -0,0 +1,2 @@
|
||||
P7 332
|
||||
Garbage here, that we don't really care about.
|
||||
Reference in New Issue
Block a user