< prev index next >

test/javax/imageio/plugins/shared/BitDepth.java

Print this page

        

*** 33,43 **** --- 33,47 ---- import java.awt.Color; import java.awt.Graphics2D; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; + import java.util.Iterator; import javax.imageio.ImageIO; + import javax.imageio.ImageTypeSpecifier; + import javax.imageio.ImageWriter; + import javax.imageio.stream.ImageOutputStream; public class BitDepth { public static void main(String[] args) throws IOException { new BitDepth(args);
*** 112,142 **** "BYTE_INDEXED" }; private int width = 80; private int height = 80; ! private String[] format = { "png", "jpeg", "tif", "bmp", "gif" }; public BitDepth(String[] args) throws IOException { if (args.length > 0) { ! format = args; } ! for (int i = 0; i < format.length; i++) { ! testFormat(format[i]); } } private void testFormat(String format) throws IOException { boolean allOK = true; ! for (int i = 0; i < biRGBTypes.length; i++) { ! ! int type = biRGBTypes[i]; ! ! // TODO: remove the following 'if' block after the 8147448 fix if ( format.toLowerCase().equals("bmp") && ( (type == BufferedImage.TYPE_INT_ARGB ) || (type == BufferedImage.TYPE_INT_ARGB_PRE ) || (type == BufferedImage.TYPE_4BYTE_ABGR ) || --- 116,142 ---- "BYTE_INDEXED" }; private int width = 80; private int height = 80; ! private String[] formats = { "png", "jpeg", "tif", "bmp", "gif" }; public BitDepth(String[] args) throws IOException { if (args.length > 0) { ! formats = args; } ! for (String format : formats) { ! testFormat(format); } } private void testFormat(String format) throws IOException { boolean allOK = true; ! for (int type : biRGBTypes) { // TODO: remove the following 'if' block after the 8147448 fix if ( format.toLowerCase().equals("bmp") && ( (type == BufferedImage.TYPE_INT_ARGB ) || (type == BufferedImage.TYPE_INT_ARGB_PRE ) || (type == BufferedImage.TYPE_4BYTE_ABGR ) ||
*** 146,168 **** " for bmp because of JDK-8147448.\t" + " please update the test after fix of this bug!"); continue; } - System.out.println("Testing " + format + " writer for type " + biTypeNames[type]); File f = testWriteRGB(format, type); boolean ok = testReadRGB(f); if (ok) { f.delete(); } allOK = allOK && ok; } - - if (format.equals("png")) { System.out.println("Testing png writer for black stripe"); boolean ok = testPNGByteBinary(); allOK = allOK && ok; } --- 146,168 ---- " for bmp because of JDK-8147448.\t" + " please update the test after fix of this bug!"); continue; } System.out.println("Testing " + format + " writer for type " + biTypeNames[type]); File f = testWriteRGB(format, type); + if (f == null) + continue; + boolean ok = testReadRGB(f); if (ok) { f.delete(); } allOK = allOK && ok; } if (format.equals("png")) { System.out.println("Testing png writer for black stripe"); boolean ok = testPNGByteBinary(); allOK = allOK && ok; }
*** 189,205 **** g.setColor(green); g.fillRect(30, 30, 20, 20); g.setColor(blue); g.fillRect(50, 50, 20, 20); File file = new File("BitDepth_" + biTypeNames[type] + "." + format); ! try { ! ImageIO.write(bi, format, file); ! } catch (RuntimeException re) { ! System.out.println("Can't write a type " ! + biTypeNames[type] + ! " BufferedImage!"); } return file; } --- 189,214 ---- g.setColor(green); g.fillRect(30, 30, 20, 20); g.setColor(blue); g.fillRect(50, 50, 20, 20); + ImageTypeSpecifier spec = new ImageTypeSpecifier(bi); + Iterator<ImageWriter> writers = ImageIO.getImageWriters(spec, format); File file = new File("BitDepth_" + biTypeNames[type] + "." + format); ! if (!writers.hasNext()) { ! System.out.println("\tNo writers available for type " + biTypeNames[type] ! + " BufferedImage!"); ! } else { ! ImageWriter writer = writers.next(); ! try (ImageOutputStream out = ImageIO.createImageOutputStream(file)) { ! writer.setOutput(out); ! writer.write(bi); ! } catch (Exception e) { ! System.out.println("\tCan't write a type " + biTypeNames[type] ! + " BufferedImage!"); ! return null; ! } } return file; }
< prev index next >