modules/graphics/src/test/java/com/sun/javafx/iio/BMPImageLoaderTest.java

Print this page
rev 7652 : BI_BITFIELDS

*** 30,41 **** import java.awt.image.BufferedImage; import java.awt.image.DataBuffer; import java.awt.image.IndexColorModel; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; - import java.io.File; - import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import javax.imageio.ImageIO; import javax.imageio.stream.MemoryCacheImageInputStream; import static org.junit.Assert.*; --- 30,39 ----
*** 87,113 **** } } } } ! Image loadImage(InputStream stream) { ImageLoaderFactory loaderFactory = BMPImageLoaderFactory.getInstance(); ! ImageLoader loader = null; ! try { ! loader = loaderFactory.createImageLoader(stream); ! } catch (IOException ioEx) { ! fail("unexpected IOException: " + ioEx); ! } assertNotNull(loader); - try { ImageFrame frame = loader.load(0, 0, 0, true, true); return Image.convertImageFrame(frame); - } catch (IOException e) { - fail("unexpected IOException: " + e); - } - return null; } BufferedImage create4BitImage() { int[] cmap = new int[16]; int i = 0; --- 85,101 ---- } } } } ! Image loadImage(InputStream stream) throws IOException { ImageLoaderFactory loaderFactory = BMPImageLoaderFactory.getInstance(); ! ImageLoader loader = loaderFactory.createImageLoader(stream); assertNotNull(loader); ImageFrame frame = loader.load(0, 0, 0, true, true); return Image.convertImageFrame(frame); } BufferedImage create4BitImage() { int[] cmap = new int[16]; int i = 0;
*** 129,171 **** BufferedImage createImage(int type) { return new BufferedImage(testWidth, testHeight, type); } ! void writeBMPImage(BufferedImage bImg, String fileName, String compression) { ImageTestHelper.writeImage(bImg, fileName, "bmp", compression); } ! Image getImage(BufferedImage bImg, String compression) { ByteArrayInputStream stream = ! ImageTestHelper.writeImageToStream(bImg, "bmp", compression, null); return loadImage(stream); } ! void testImageType(int type, String fileName, String compression) { BufferedImage bImg = createImage(type); testImage(bImg, fileName, compression); } ! void testImageType(int type, String fileName) { BufferedImage bImg = createImage(type); testImage(bImg, fileName, null); } ! void testImage(BufferedImage bImg, String fileName, String compression) { //ImageTestHelper.drawImageHue(bImg); //ImageTestHelper.drawImageAll(bImg); ImageTestHelper.drawImageRandom(bImg); if (writeFiles) { ! writeBMPImage(bImg, fileName, compression); } Image image = getImage(bImg, compression); compare(image, bImg); } @Test ! public void testRT32213() { final int[] bytes = { 0x42, 0x4d, 0x42, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, --- 117,163 ---- BufferedImage createImage(int type) { return new BufferedImage(testWidth, testHeight, type); } ! void writeBMPFile(BufferedImage bImg, String fileName, String compression) { ! try { ImageTestHelper.writeImage(bImg, fileName, "bmp", compression); + } catch (IOException e) { + System.out.println("writeBMPFile " + fileName + " failed: " + e); + } } ! Image getImage(BufferedImage bImg, String compression) throws IOException { ByteArrayInputStream stream = ! ImageTestHelper.writeImageToStream(bImg, "bmp", compression); return loadImage(stream); } ! void testImageType(int type, String fileName, String compression) throws IOException { BufferedImage bImg = createImage(type); testImage(bImg, fileName, compression); } ! void testImageType(int type, String fileName) throws IOException { BufferedImage bImg = createImage(type); testImage(bImg, fileName, null); } ! void testImage(BufferedImage bImg, String fileName, String compression) throws IOException { //ImageTestHelper.drawImageHue(bImg); //ImageTestHelper.drawImageAll(bImg); ImageTestHelper.drawImageRandom(bImg); if (writeFiles) { ! writeBMPFile(bImg, fileName, compression); } Image image = getImage(bImg, compression); compare(image, bImg); } @Test ! public void testRT32213() throws IOException { final int[] bytes = { 0x42, 0x4d, 0x42, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00,
*** 177,192 **** }; ByteArrayInputStream stream = constructStream(bytes); Image image = loadImage(stream); stream.reset(); - try { BufferedImage bImg = ImageIO.read(new MemoryCacheImageInputStream(stream)); compare(image, bImg); - } catch (IOException e) { - fail("unexpected IOException: " + e); - } } private static class RT15619InputStream extends InputStream { private final InputStream delegate; --- 169,180 ----
*** 206,275 **** return delegate.read(b, off, 1); } } @Test ! public void testRT15619() { BufferedImage bImg = createImage(BufferedImage.TYPE_INT_RGB); ImageTestHelper.drawImageRandom(bImg); ByteArrayInputStream stream = ! ImageTestHelper.writeImageToStream(bImg, "bmp", null, null); RT15619InputStream testStream = new RT15619InputStream(stream); Image image = loadImage(testStream); compare(image, bImg); } @Test ! public void test1Bit() { testImageType(BufferedImage.TYPE_BYTE_BINARY, "out1bit.bmp"); } @Test ! public void test4Bit() { testImage(create4BitImage(), "out4bit.bmp", null); } //@Test ! public void test4BitRLE() { testImage(create4BitImage(), "out4bitRLE.bmp", "BI_RLE4"); } @Test ! public void test8Bit() { testImageType(BufferedImage.TYPE_BYTE_INDEXED, "out8bit.bmp"); } @Test ! public void test8BitRLE() { testImageType(BufferedImage.TYPE_BYTE_INDEXED, "out8bitRLE.bmp", "BI_RLE8"); } @Test ! public void test16Bit() { testImageType(BufferedImage.TYPE_USHORT_555_RGB, "out16bit.bmp"); } @Test ! public void test24Bit() { testImageType(BufferedImage.TYPE_INT_RGB, "out24bit.bmp"); } ! void testFile(String fileName, String outFileName, String compression) { ! try { ! Image image = loadImage(new FileInputStream(fileName)); ! BufferedImage bImg = ImageIO.read(new File(fileName)); ! if (writeFiles) { ! writeBMPImage(bImg, outFileName, compression); ! } ! compare(image, bImg); ! } catch (IOException e) { ! fail("unexpected IOException: " + e); ! } ! } ! ! //@Test ! public void testFiles() { ! testFile("pal4rle.bmp", "pal4rleOut.bmp", "BI_RLE4"); ! testFile("out4bitRLE.bmp", "out4bitRLEOut.bmp", "BI_RLE4"); ! testFile("pal8rletrns.bmp", "pal8rletrnsOut.bmp", null); } } --- 194,249 ---- return delegate.read(b, off, 1); } } @Test ! public void testRT15619() throws IOException { BufferedImage bImg = createImage(BufferedImage.TYPE_INT_RGB); ImageTestHelper.drawImageRandom(bImg); ByteArrayInputStream stream = ! ImageTestHelper.writeImageToStream(bImg, "bmp", null); RT15619InputStream testStream = new RT15619InputStream(stream); Image image = loadImage(testStream); compare(image, bImg); } @Test ! public void test1Bit() throws IOException { testImageType(BufferedImage.TYPE_BYTE_BINARY, "out1bit.bmp"); } @Test ! public void test4Bit() throws IOException { testImage(create4BitImage(), "out4bit.bmp", null); } //@Test ! public void test4BitRLE() throws IOException { testImage(create4BitImage(), "out4bitRLE.bmp", "BI_RLE4"); } @Test ! public void test8Bit() throws IOException { testImageType(BufferedImage.TYPE_BYTE_INDEXED, "out8bit.bmp"); } @Test ! public void test8BitRLE() throws IOException { testImageType(BufferedImage.TYPE_BYTE_INDEXED, "out8bitRLE.bmp", "BI_RLE8"); } @Test ! public void test16Bit() throws IOException { testImageType(BufferedImage.TYPE_USHORT_555_RGB, "out16bit.bmp"); } @Test ! public void test24Bit() throws IOException { testImageType(BufferedImage.TYPE_INT_RGB, "out24bit.bmp"); } ! @Test ! public void testBitfields() throws IOException { ! testImageType(BufferedImage.TYPE_USHORT_555_RGB, "out16bit555.bmp", "BI_BITFIELDS"); ! testImageType(BufferedImage.TYPE_USHORT_565_RGB, "out16bit565.bmp", "BI_BITFIELDS"); } }