On 2/15/2016 1:58 PM, Phil Race wrote:
Assuming it works, this approach seems better.
A slightly modified version of Brian's change does the trick.
Patch below and updated webrev at
http://cr.openjdk.java.net/~darcy/8148914.1/
Thanks,
-Joe
diff -r 10e298cb4ef1 test/javax/imageio/plugins/shared/BitDepth.java
--- a/test/javax/imageio/plugins/shared/BitDepth.java Mon Feb 15
18:41:23 2016 -0800
+++ b/test/javax/imageio/plugins/shared/BitDepth.java Mon Feb 15
23:13:43 2016 -0800
@@ -35,7 +35,11 @@
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 {
@@ -114,15 +118,15 @@
private int width = 80;
private int height = 80;
- private String[] format = { "png", "jpeg", "tif", "bmp", "gif" };
+ private String[] formats = { "png", "jpeg", "tif", "bmp", "gif" };
public BitDepth(String[] args) throws IOException {
if (args.length > 0) {
- format = args;
+ formats = args;
}
- for (int i = 0; i < format.length; i++) {
- testFormat(format[i]);
+ for (String format : formats) {
+ testFormat(format);
}
}
@@ -130,11 +134,7 @@
boolean allOK = true;
- for (int i = 0; i < biRGBTypes.length; i++) {
-
- int type = biRGBTypes[i];
-
-
+ for (int type : biRGBTypes) {
// TODO: remove the following 'if' block after the 8147448 fix
if ( format.toLowerCase().equals("bmp") && (
(type == BufferedImage.TYPE_INT_ARGB ) ||
@@ -148,10 +148,12 @@
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();
@@ -159,8 +161,6 @@
allOK = allOK && ok;
}
-
-
if (format.equals("png")) {
System.out.println("Testing png writer for black stripe");
boolean ok = testPNGByteBinary();
@@ -191,13 +191,22 @@
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);
- try {
- ImageIO.write(bi, format, file);
- } catch (RuntimeException re) {
- System.out.println("Can't write a type "
- + biTypeNames[type] +
- " BufferedImage!");
+ 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;
-phil.
On 02/15/2016 11:39 AM, Brian Burkhalter wrote:
Hi Joe,
Might it not be better to modify testWriteRGB() to do something like
this (code neither compiled nor tested):
ImageTypeSpecifier spec = new ImageTypeSpecifier(bi);
Iterator<ImageWriter> writers = ImageIO.getImageWriters(spec,
format).next();
File file = new File("BitDepth_" + biTypeNames[type] + "." + format);
if (!writers.hasNext()) {
System.out.println(“No 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("Can't write a type “ + biTypeNames[type]
+ " BufferedImage!");
}
}
return file;
Thanks,
Brian
On Feb 15, 2016, at 9:35 AM, joe darcy <joe.da...@oracle.com
<mailto:joe.da...@oracle.com>> wrote:
Any comments on this?
Thanks,
-Joe
On 2/11/2016 6:00 PM, joe darcy wrote:
Hello,
Please review a candidate fix for
JDK-8148914: BitDepth.java test fails
In brief, OpenJDK supports two fewer buffered image formats for jpg
than the closed JDK does. I've modified the BitDepth test to allow
for this difference. Patch below; webrev at
http://cr.openjdk.java.net/~darcy/8148914.0/
<http://cr.openjdk.java.net/%7Edarcy/8148914.0/>
Thanks,
-Joe
--- a/test/javax/imageio/plugins/shared/BitDepth.java Thu Feb 11
16:24:55 2016 -0800
+++ b/test/javax/imageio/plugins/shared/BitDepth.java Thu Feb 11
17:26:23 2016 -0800
@@ -130,11 +130,7 @@
boolean allOK = true;
- for (int i = 0; i < biRGBTypes.length; i++) {
-
- int type = biRGBTypes[i];
-
-
+ for (int type : biRGBTypes) {
// TODO: remove the following 'if' block after the
8147448 fix
if ( format.toLowerCase().equals("bmp") && (
(type == BufferedImage.TYPE_INT_ARGB ) ||
@@ -151,12 +147,23 @@
System.out.println("Testing " + format +
" writer for type " +
biTypeNames[type]);
- File f = testWriteRGB(format, type);
- boolean ok = testReadRGB(f);
- if (ok) {
- f.delete();
+ boolean ok = false;
+ File f = null;
+ try {
+ f = testWriteRGB(format, type);
+ ok = testReadRGB(f);
+ } catch (javax.imageio.IIOException e) {
+ // The follow two formats are not supported on OpenJDK
+ if (format.toLowerCase().equals("jpg") &&
+ (type == BufferedImage.TYPE_4BYTE_ABGR ||
+ type == BufferedImage.TYPE_4BYTE_ABGR_PRE))
+ continue;
+ } finally {
+ if (ok) {
+ f.delete();
+ }
+ allOK = allOK && (ok || f == null);
}
- allOK = allOK && ok;
}