/* * Copyright (c) 2007, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions.
*/
/** * @test * @bug 4413109 4418221 6607198 8147448 8204187 * @run main BitDepth * @summary Checks that ImageIO writers for standard formats can handle * various BufferedImage RGB types. An optional list of arguments * may be used to test the writers for a different list of formats.
*/
publicstaticvoid main(String[] args) throws IOException { new BitDepth(args);
}
// Check that the PNG writer can write an all-white image correctly privatestaticboolean testPNGByteBinary() throws IOException { int width = 10; int height = 10;
File f = new File("BlackStripe.png");
BufferedImage bi = new BufferedImage(width, height,
BufferedImage.TYPE_BYTE_BINARY);
Graphics2D g = bi.createGraphics();
g.setColor(new Color(255, 255, 255));
g.fillRect(0, 0, width, height);
for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { int rgb = bi2.getRGB(x, y); if (rgb != 0xffffffff) {
System.out.println("Found a non-white pixel!"); returnfalse;
}
}
}
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 ) ||
(type == BufferedImage.TYPE_4BYTE_ABGR_PRE ))) {
System.err.println("cannot use " + biTypeNames[type] + " 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;
}
if (!allOK) { thrownew RuntimeException("Test failed");
}
}
private File testWriteRGB(String format, int type) throws IOException {
BufferedImage bi = new BufferedImage(width, height, type);
Graphics2D g = bi.createGraphics();
Color white = new Color(255, 255, 255);
Color red = new Color(255, 0, 0);
Color green = new Color(0, 255, 0);
Color blue = new Color(0, 0, 255);
BufferedImage bi = ImageIO.read(file); if (bi == null) {
System.out.println("Couldn't read image!"); returnfalse;
} int r = bi.getRGB(15, 15); if (colorDistance(r, 255, 0, 0) > 20) {
System.out.println("Red was distorted!"); returnfalse;
} int g = bi.getRGB(35, 35); if (colorDistance(g, 0, 255, 0) > 20) {
System.out.println("Green was distorted!"); returnfalse;
} int b = bi.getRGB(55, 55); if (colorDistance(b, 0, 0, 255) > 20) {
System.out.println("Blue was distorted!"); returnfalse;
} int w = bi.getRGB(55, 15); if (colorDistance(w, 255, 255, 255) > 20) {
System.out.println("White was distorted!"); returnfalse;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.