8177628: Opensource unit/regression tests for ImageIO
Reviewed-by: prr, pnarayanan
This commit is contained in:
parent
a89cb1d937
commit
edb00726d3
77
jdk/test/javax/imageio/AllowSearch.java
Normal file
77
jdk/test/javax/imageio/AllowSearch.java
Normal file
@ -0,0 +1,77 @@
|
||||
/*
|
||||
* Copyright (c) 2001, 2017, 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 4420318
|
||||
* @summary Checks that an IllegalStateException is thrown by getNumImages(true)
|
||||
* when seekForwardOnly is true
|
||||
* @modules java.desktop/com.sun.imageio.plugins.gif
|
||||
* java.desktop/com.sun.imageio.plugins.jpeg
|
||||
* java.desktop/com.sun.imageio.plugins.png
|
||||
*/
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.ImageReader;
|
||||
import javax.imageio.stream.ImageInputStream;
|
||||
|
||||
import com.sun.imageio.plugins.gif.GIFImageReader;
|
||||
import com.sun.imageio.plugins.jpeg.JPEGImageReader;
|
||||
import com.sun.imageio.plugins.png.PNGImageReader;
|
||||
|
||||
public class AllowSearch {
|
||||
|
||||
private static void test(ImageReader reader, String format)
|
||||
throws IOException {
|
||||
File f = File.createTempFile("imageio", ".tmp");
|
||||
ImageInputStream stream = ImageIO.createImageInputStream(f);
|
||||
reader.setInput(stream, true);
|
||||
|
||||
boolean gotISE = false;
|
||||
try {
|
||||
int numImages = reader.getNumImages(true);
|
||||
} catch (IOException ioe) {
|
||||
gotISE = false;
|
||||
} catch (IllegalStateException ise) {
|
||||
gotISE = true;
|
||||
}
|
||||
|
||||
if (!gotISE) {
|
||||
throw new RuntimeException("Failed to get desired exception for " +
|
||||
format + " reader!");
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
ImageReader gifReader = new GIFImageReader(null);
|
||||
ImageReader jpegReader = new JPEGImageReader(null);
|
||||
ImageReader pngReader = new PNGImageReader(null);
|
||||
|
||||
test(gifReader, "GIF");
|
||||
test(jpegReader, "JPEG");
|
||||
test(pngReader, "PNG");
|
||||
}
|
||||
}
|
141
jdk/test/javax/imageio/AppContextTest.java
Normal file
141
jdk/test/javax/imageio/AppContextTest.java
Normal file
@ -0,0 +1,141 @@
|
||||
/*
|
||||
* Copyright (c) 2001, 2017, 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 4421190
|
||||
* @summary Tests that Image I/O statics may be referenced properly from
|
||||
* multiple AppContexts, as would be the case for multiple Applets in a
|
||||
* single VM. Each AppContext should get its own copy of the registry
|
||||
* and the caching parameters in the ImageIO class.
|
||||
* @modules java.desktop/sun.awt
|
||||
*/
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.spi.IIORegistry;
|
||||
|
||||
import sun.awt.SunToolkit;
|
||||
|
||||
class TestThread extends Thread {
|
||||
|
||||
IIORegistry registry;
|
||||
boolean useCache;
|
||||
File cacheDirectory;
|
||||
boolean cacheSettingsOK = false;
|
||||
String threadName;
|
||||
|
||||
boolean gotCrosstalk = false;
|
||||
|
||||
public TestThread(ThreadGroup tg,
|
||||
boolean useCache, File cacheDirectory,
|
||||
String threadName) {
|
||||
super(tg, threadName);
|
||||
this.useCache = useCache;
|
||||
this.cacheDirectory = cacheDirectory;
|
||||
this.threadName = threadName;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
// System.out.println("Thread " + threadName + " in thread group " +
|
||||
// getThreadGroup().getName());
|
||||
|
||||
// Create a new AppContext as though we were an applet
|
||||
SunToolkit.createNewAppContext();
|
||||
|
||||
// Get default registry and store reference
|
||||
this.registry = IIORegistry.getDefaultInstance();
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
// System.out.println(threadName +
|
||||
// ": setting cache parameters to " +
|
||||
// useCache + ", " + cacheDirectory);
|
||||
ImageIO.setUseCache(useCache);
|
||||
ImageIO.setCacheDirectory(cacheDirectory);
|
||||
|
||||
try {
|
||||
sleep(1000L);
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
|
||||
// System.out.println(threadName + ": reading cache parameters");
|
||||
boolean newUseCache = ImageIO.getUseCache();
|
||||
File newCacheDirectory = ImageIO.getCacheDirectory();
|
||||
if (newUseCache != useCache ||
|
||||
newCacheDirectory != cacheDirectory) {
|
||||
// System.out.println(threadName + ": got " +
|
||||
// newUseCache + ", " +
|
||||
// newCacheDirectory);
|
||||
// System.out.println(threadName + ": crosstalk encountered!");
|
||||
gotCrosstalk = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public IIORegistry getRegistry() {
|
||||
return registry;
|
||||
}
|
||||
|
||||
public boolean gotCrosstalk() {
|
||||
return gotCrosstalk;
|
||||
}
|
||||
}
|
||||
|
||||
public class AppContextTest {
|
||||
|
||||
public AppContextTest() {
|
||||
ThreadGroup tg0 = new ThreadGroup("ThreadGroup0");
|
||||
ThreadGroup tg1 = new ThreadGroup("ThreadGroup1");
|
||||
|
||||
TestThread t0 =
|
||||
new TestThread(tg0, false, null, "TestThread 0");
|
||||
TestThread t1 =
|
||||
new TestThread(tg1, true, new File("."), "TestThread 1");
|
||||
|
||||
t0.start();
|
||||
t1.start();
|
||||
|
||||
try {
|
||||
t0.join();
|
||||
} catch (InterruptedException ie0) {
|
||||
}
|
||||
try {
|
||||
t1.join();
|
||||
} catch (InterruptedException ie1) {
|
||||
}
|
||||
|
||||
if (t0.gotCrosstalk() || t1.gotCrosstalk()) {
|
||||
throw new RuntimeException("ImageIO methods had crosstalk!");
|
||||
}
|
||||
|
||||
if (t0.getRegistry() == t1.getRegistry()) {
|
||||
throw new RuntimeException("ThreadGroups had same IIORegistry!");
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
new AppContextTest();
|
||||
}
|
||||
}
|
40
jdk/test/javax/imageio/AppletResourceTest.html
Normal file
40
jdk/test/javax/imageio/AppletResourceTest.html
Normal file
@ -0,0 +1,40 @@
|
||||
<!--
|
||||
~ Copyright (c) 2003, 2017, 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.
|
||||
-->
|
||||
|
||||
<html>
|
||||
<!--
|
||||
test
|
||||
@bug 4481957
|
||||
@run main AppletResourceTest
|
||||
@run applet RestrictedBundleTest.html
|
||||
@summary Tests that applet-supplied ImageReader, ImageWriter, and
|
||||
IIOMetadataFormat implementations do not throw unexpected exceptions
|
||||
when indirectly attempting to access ResourceBundles.
|
||||
-->
|
||||
<head>
|
||||
<title> AppletResourceTest </title>
|
||||
</head>
|
||||
<body>
|
||||
<applet code=AppletResourceTest.class width=400 height=400></applet>
|
||||
</body>
|
||||
</html>
|
439
jdk/test/javax/imageio/AppletResourceTest.java
Normal file
439
jdk/test/javax/imageio/AppletResourceTest.java
Normal file
@ -0,0 +1,439 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 2017, 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 4481957
|
||||
* @key headful
|
||||
* @summary Tests that applet-supplied ImageReader, ImageWriter, and
|
||||
* IIOMetadataFormat implementations do not throw unexpected exceptions
|
||||
* when indirectly attempting to access ResourceBundles
|
||||
* @run main AppletResourceTest
|
||||
* @run applet AppletResourceTest.html
|
||||
*/
|
||||
|
||||
import java.applet.Applet;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.IOException;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListResourceBundle;
|
||||
import java.util.Locale;
|
||||
import java.util.MissingResourceException;
|
||||
import java.util.Vector;
|
||||
|
||||
import javax.imageio.IIOException;
|
||||
import javax.imageio.ImageReadParam;
|
||||
import javax.imageio.ImageReader;
|
||||
import javax.imageio.ImageTypeSpecifier;
|
||||
import javax.imageio.event.IIOReadWarningListener;
|
||||
import javax.imageio.metadata.IIOInvalidTreeException;
|
||||
import javax.imageio.metadata.IIOMetadata;
|
||||
import javax.imageio.spi.ImageReaderSpi;
|
||||
|
||||
import org.w3c.dom.Node;
|
||||
|
||||
public class AppletResourceTest extends Applet {
|
||||
|
||||
public static void main(String[] argv) {
|
||||
new AppletResourceTest().init();
|
||||
}
|
||||
|
||||
public void init() {
|
||||
DummyImageReaderImpl reader;
|
||||
MyReadWarningListener listener = new MyReadWarningListener();
|
||||
Locale[] locales = {new Locale("ru"),
|
||||
new Locale("fr"),
|
||||
new Locale("uk")};
|
||||
|
||||
reader = new DummyImageReaderImpl(new DummyImageReaderSpiImpl());
|
||||
reader.setAvailableLocales(locales);
|
||||
reader.setLocale(new Locale("fr"));
|
||||
reader.addIIOReadWarningListener(listener);
|
||||
|
||||
String baseName = "AppletResourceTest$BugStats";
|
||||
try {
|
||||
reader.processWarningOccurred("WarningMessage");
|
||||
reader.processWarningOccurred(baseName, "water");
|
||||
} catch (MissingResourceException mre) {
|
||||
throw new RuntimeException("Test failed: couldn't load resource");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private class MyReadWarningListener implements IIOReadWarningListener {
|
||||
public void warningOccurred(ImageReader source,
|
||||
String warning)
|
||||
{
|
||||
System.out.println("warning occurred: " + warning);
|
||||
}
|
||||
}
|
||||
|
||||
public static class BugStats extends ListResourceBundle {
|
||||
|
||||
public Object[][] getContents(){
|
||||
return contents;
|
||||
}
|
||||
|
||||
private Object[][] contents = {
|
||||
{"coffee", new String("coffee from Stats class")},
|
||||
{"tea", new String("tea from Stats class")},
|
||||
{"water", new String("water from Stats class")}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public static class DummyImageReaderImpl extends ImageReader {
|
||||
|
||||
public DummyImageReaderImpl(ImageReaderSpi originatingProvider) {
|
||||
super(originatingProvider);
|
||||
}
|
||||
|
||||
public int getNumImages(boolean allowSearch) throws IOException {
|
||||
return 5;
|
||||
}
|
||||
|
||||
public int getWidth(int imageIndex) throws IOException {
|
||||
if (input == null)
|
||||
throw new IllegalStateException();
|
||||
if (imageIndex >= 5 || imageIndex < 0)
|
||||
throw new IndexOutOfBoundsException();
|
||||
|
||||
return 10;
|
||||
}
|
||||
|
||||
public int getHeight(int imageIndex) throws IOException {
|
||||
if (input == null)
|
||||
throw new IllegalStateException();
|
||||
if (imageIndex >= 5 || imageIndex < 0)
|
||||
throw new IndexOutOfBoundsException();
|
||||
|
||||
return 15;
|
||||
}
|
||||
|
||||
public Iterator getImageTypes(int imageIndex) throws IOException {
|
||||
if (input == null)
|
||||
throw new IllegalStateException();
|
||||
if (imageIndex >= 5 || imageIndex < 0)
|
||||
throw new IndexOutOfBoundsException();
|
||||
|
||||
Vector imageTypes = new Vector();
|
||||
imageTypes.add(ImageTypeSpecifier.createFromBufferedImageType
|
||||
(BufferedImage.TYPE_BYTE_GRAY ));
|
||||
return imageTypes.iterator();
|
||||
}
|
||||
|
||||
public IIOMetadata getStreamMetadata() throws IOException {
|
||||
return new DummyIIOMetadataImpl(true, null, null, null, null);
|
||||
}
|
||||
|
||||
public IIOMetadata getImageMetadata(int imageIndex)
|
||||
throws IOException {
|
||||
|
||||
if (input == null)
|
||||
throw new IllegalStateException();
|
||||
if (imageIndex >= 5 || imageIndex < 0)
|
||||
throw new IndexOutOfBoundsException();
|
||||
if (seekForwardOnly) {
|
||||
if (imageIndex < minIndex)
|
||||
throw new IndexOutOfBoundsException();
|
||||
minIndex = imageIndex;
|
||||
}
|
||||
return new DummyIIOMetadataImpl(true, null, null, null, null);
|
||||
}
|
||||
|
||||
|
||||
public BufferedImage read(int imageIndex, ImageReadParam param)
|
||||
throws IOException {
|
||||
if (input == null)
|
||||
throw new IllegalStateException();
|
||||
if (imageIndex >= 5 || imageIndex < 0)
|
||||
throw new IndexOutOfBoundsException();
|
||||
if (seekForwardOnly) {
|
||||
if (imageIndex < minIndex)
|
||||
throw new IndexOutOfBoundsException();
|
||||
minIndex = imageIndex;
|
||||
}
|
||||
|
||||
return getDestination(param, getImageTypes(imageIndex), 10, 15);
|
||||
}
|
||||
|
||||
// protected methods - now public
|
||||
|
||||
public boolean abortRequested() {
|
||||
return super.abortRequested();
|
||||
}
|
||||
|
||||
public void clearAbortRequest() {
|
||||
super.clearAbortRequest();
|
||||
}
|
||||
|
||||
public void processImageComplete() {
|
||||
super.processImageComplete();
|
||||
}
|
||||
|
||||
public void processImageProgress(float percentageDone) {
|
||||
super.processImageProgress(percentageDone);
|
||||
}
|
||||
|
||||
public void processImageStarted(int imageIndex) {
|
||||
super.processImageStarted(imageIndex);
|
||||
}
|
||||
|
||||
public void processImageUpdate(BufferedImage theImage,
|
||||
int minX,
|
||||
int minY,
|
||||
int width,
|
||||
int height,
|
||||
int periodX,
|
||||
int periodY,
|
||||
int[] bands) {
|
||||
super.processImageUpdate(theImage,
|
||||
minX,
|
||||
minY,
|
||||
width,
|
||||
height,
|
||||
periodX,
|
||||
periodY,
|
||||
bands);
|
||||
}
|
||||
|
||||
public void processPassComplete(BufferedImage theImage) {
|
||||
super. processPassComplete(theImage);
|
||||
}
|
||||
|
||||
public void processPassStarted(BufferedImage theImage,
|
||||
int pass, int minPass,
|
||||
int maxPass,
|
||||
int minX,
|
||||
int minY,
|
||||
int periodX,
|
||||
int periodY,
|
||||
int[] bands) {
|
||||
super.processPassStarted(theImage,
|
||||
pass,
|
||||
minPass,
|
||||
maxPass,
|
||||
minX,
|
||||
minY,
|
||||
periodX,
|
||||
periodY,
|
||||
bands);
|
||||
}
|
||||
|
||||
public void processReadAborted() {
|
||||
super.processReadAborted();
|
||||
}
|
||||
|
||||
public void processSequenceComplete() {
|
||||
super.processSequenceComplete();
|
||||
}
|
||||
|
||||
public void processSequenceStarted(int minIndex) {
|
||||
super.processSequenceStarted(minIndex);
|
||||
}
|
||||
|
||||
public void processThumbnailComplete() {
|
||||
super.processThumbnailComplete();
|
||||
}
|
||||
|
||||
public void processThumbnailPassComplete(BufferedImage theThumbnail) {
|
||||
super.processThumbnailPassComplete(theThumbnail);
|
||||
}
|
||||
|
||||
public void processThumbnailPassStarted(BufferedImage theThumbnail,
|
||||
int pass,
|
||||
int minPass,
|
||||
int maxPass,
|
||||
int minX,
|
||||
int minY,
|
||||
int periodX,
|
||||
int periodY,
|
||||
int[] bands) {
|
||||
super.processThumbnailPassStarted(theThumbnail,
|
||||
pass,
|
||||
minPass,
|
||||
maxPass,
|
||||
minX,
|
||||
minY,
|
||||
periodX,
|
||||
periodY,
|
||||
bands);
|
||||
}
|
||||
|
||||
public void processThumbnailProgress(float percentageDone) {
|
||||
super.processThumbnailProgress(percentageDone);
|
||||
}
|
||||
|
||||
public void processThumbnailStarted(int imageIndex, int thumbnailIndex) {
|
||||
super.processThumbnailStarted(imageIndex, thumbnailIndex);
|
||||
}
|
||||
|
||||
public void processThumbnailUpdate(BufferedImage theThumbnail,
|
||||
int minX,
|
||||
int minY,
|
||||
int width,
|
||||
int height,
|
||||
int periodX,
|
||||
int periodY,
|
||||
int[] bands) {
|
||||
super.processThumbnailUpdate(theThumbnail,
|
||||
minX,
|
||||
minY,
|
||||
width,
|
||||
height,
|
||||
periodX,
|
||||
periodY,
|
||||
bands);
|
||||
}
|
||||
|
||||
public void processWarningOccurred(String warning) {
|
||||
super.processWarningOccurred(warning);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static Rectangle getSourceRegion(ImageReadParam param,
|
||||
int srcWidth,
|
||||
int srcHeight) {
|
||||
return ImageReader.getSourceRegion(param, srcWidth, srcHeight);
|
||||
}
|
||||
|
||||
public static void computeRegions(ImageReadParam param,
|
||||
int srcWidth,
|
||||
int srcHeight,
|
||||
BufferedImage image,
|
||||
Rectangle srcRegion,
|
||||
Rectangle destRegion) {
|
||||
ImageReader.computeRegions(param,
|
||||
srcWidth,
|
||||
srcHeight,
|
||||
image,
|
||||
srcRegion,
|
||||
destRegion);
|
||||
}
|
||||
|
||||
public static void checkReadParamBandSettings(ImageReadParam param,
|
||||
int numSrcBands,
|
||||
int numDstBands) {
|
||||
ImageReader.checkReadParamBandSettings( param,
|
||||
numSrcBands,
|
||||
numDstBands);
|
||||
}
|
||||
|
||||
public static BufferedImage getDestination(ImageReadParam param,
|
||||
Iterator imageTypes,
|
||||
int width,
|
||||
int height) throws IIOException {
|
||||
return ImageReader.getDestination(param,
|
||||
imageTypes,
|
||||
width,
|
||||
height);
|
||||
}
|
||||
|
||||
public void setAvailableLocales(Locale[] locales) {
|
||||
if (locales == null || locales.length == 0)
|
||||
availableLocales = null;
|
||||
else
|
||||
availableLocales = (Locale[])locales.clone();
|
||||
}
|
||||
|
||||
public void processWarningOccurred(String baseName, String keyword) {
|
||||
super.processWarningOccurred(baseName, keyword);
|
||||
}
|
||||
}
|
||||
|
||||
public static class DummyIIOMetadataImpl extends IIOMetadata {
|
||||
|
||||
public DummyIIOMetadataImpl() {
|
||||
super();
|
||||
}
|
||||
|
||||
public DummyIIOMetadataImpl(boolean standardMetadataFormatSupported,
|
||||
String nativeMetadataFormatName,
|
||||
String nativeMetadataFormatClassName,
|
||||
String[] extraMetadataFormatNames,
|
||||
String[] extraMetadataFormatClassNames) {
|
||||
super(standardMetadataFormatSupported,
|
||||
nativeMetadataFormatName,
|
||||
nativeMetadataFormatClassName,
|
||||
extraMetadataFormatNames,
|
||||
extraMetadataFormatClassNames);
|
||||
}
|
||||
|
||||
public boolean isReadOnly() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public Node getAsTree(String formatName) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void mergeTree(String formatName, Node root)
|
||||
throws IIOInvalidTreeException {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
}
|
||||
|
||||
public static class DummyImageReaderSpiImpl extends ImageReaderSpi {
|
||||
|
||||
static final String[] names ={ "myformat" };
|
||||
|
||||
public DummyImageReaderSpiImpl() {
|
||||
super("vendorName",
|
||||
"version",
|
||||
names,
|
||||
null,
|
||||
null,
|
||||
"DummyImageReaderImpl",
|
||||
STANDARD_INPUT_TYPE,
|
||||
null,
|
||||
true,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
true,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null);
|
||||
}
|
||||
public boolean canDecodeInput(Object source)
|
||||
throws IOException {
|
||||
return true;
|
||||
}
|
||||
public ImageReader createReaderInstance(Object extension)
|
||||
throws IOException {
|
||||
return new DummyImageReaderImpl(this);
|
||||
}
|
||||
public String getDescription(Locale locale) {
|
||||
return "DummyImageReaderSpiImpl";
|
||||
}
|
||||
}
|
||||
}
|
96
jdk/test/javax/imageio/GetNumImages.java
Normal file
96
jdk/test/javax/imageio/GetNumImages.java
Normal file
@ -0,0 +1,96 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 2017, 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 4892609
|
||||
* @summary Tests that the appropriate IllegalStateException is thrown if
|
||||
* ImageReader.getNumImages() is called with a null source or if
|
||||
* allowSearch is specified at the same time that seekForwardOnly is
|
||||
* true
|
||||
*/
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.util.Iterator;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.ImageReader;
|
||||
import javax.imageio.spi.IIORegistry;
|
||||
import javax.imageio.spi.ImageReaderSpi;
|
||||
import javax.imageio.stream.ImageInputStream;
|
||||
|
||||
public class GetNumImages {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
IIORegistry registry = IIORegistry.getDefaultInstance();
|
||||
|
||||
// test ImageReader.getNumImages() for all available ImageReaders,
|
||||
// with no source set
|
||||
Iterator readerspis = registry.getServiceProviders(ImageReaderSpi.class,
|
||||
false);
|
||||
while (readerspis.hasNext()) {
|
||||
boolean caughtEx = false;
|
||||
ImageReaderSpi readerspi = (ImageReaderSpi)readerspis.next();
|
||||
ImageReader reader = readerspi.createReaderInstance();
|
||||
try {
|
||||
reader.getNumImages(false);
|
||||
} catch (IllegalStateException ise) {
|
||||
// caught exception, everything's okay
|
||||
caughtEx = true;
|
||||
}
|
||||
|
||||
if (!caughtEx) {
|
||||
throw new RuntimeException("Test failed: exception was not " +
|
||||
"thrown for null input: " +
|
||||
reader);
|
||||
}
|
||||
}
|
||||
|
||||
// test ImageReader.getNumImages() for all available ImageReaders,
|
||||
// with source set, seekForwardOnly and allowSearch both true
|
||||
readerspis = registry.getServiceProviders(ImageReaderSpi.class,
|
||||
false);
|
||||
while (readerspis.hasNext()) {
|
||||
boolean caughtEx = false;
|
||||
ImageReaderSpi readerspi = (ImageReaderSpi)readerspis.next();
|
||||
ImageReader reader = readerspi.createReaderInstance();
|
||||
byte[] barr = new byte[100];
|
||||
ByteArrayInputStream bais = new ByteArrayInputStream(barr);
|
||||
ImageInputStream iis = ImageIO.createImageInputStream(bais);
|
||||
try {
|
||||
reader.setInput(iis, true);
|
||||
reader.getNumImages(true);
|
||||
} catch (IllegalStateException ise) {
|
||||
// caught exception, everything's okay
|
||||
caughtEx = true;
|
||||
}
|
||||
|
||||
if (!caughtEx) {
|
||||
throw new RuntimeException("Test failed: exception was not " +
|
||||
"thrown when allowSearch and " +
|
||||
"seekForwardOnly are both true: " +
|
||||
reader);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
113
jdk/test/javax/imageio/GetReaderWriterInfo.java
Normal file
113
jdk/test/javax/imageio/GetReaderWriterInfo.java
Normal file
@ -0,0 +1,113 @@
|
||||
/*
|
||||
* Copyright (c) 2006, 2017, 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 4703112
|
||||
* @summary Verifies that ImageIO.getReaderFileSuffixes() and similar methods
|
||||
* return appropriate values
|
||||
*/
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.ImageReader;
|
||||
import javax.imageio.ImageWriter;
|
||||
|
||||
public class GetReaderWriterInfo {
|
||||
|
||||
private static void testGetReaderFormatNames() {
|
||||
String[] names = ImageIO.getReaderFormatNames();
|
||||
for (String n : names) {
|
||||
Iterator<ImageReader> it = ImageIO.getImageReadersByFormatName(n);
|
||||
if (!it.hasNext()) {
|
||||
throw new RuntimeException("getReaderFormatNames returned " +
|
||||
"an unknown name: " + n);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void testGetReaderMIMETypes() {
|
||||
String[] types = ImageIO.getReaderMIMETypes();
|
||||
for (String t : types) {
|
||||
Iterator<ImageReader> it = ImageIO.getImageReadersByMIMEType(t);
|
||||
if (!it.hasNext()) {
|
||||
throw new RuntimeException("getReaderMIMETypes returned " +
|
||||
"an unknown type: " + t);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void testGetReaderFileSuffixes() {
|
||||
String[] suffixes = ImageIO.getReaderFileSuffixes();
|
||||
for (String s : suffixes) {
|
||||
Iterator<ImageReader> it = ImageIO.getImageReadersBySuffix(s);
|
||||
if (!it.hasNext()) {
|
||||
throw new RuntimeException("getReaderFileSuffixes returned " +
|
||||
"an unknown suffix: " + s);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void testGetWriterFormatNames() {
|
||||
String[] names = ImageIO.getWriterFormatNames();
|
||||
for (String n : names) {
|
||||
Iterator<ImageWriter> it = ImageIO.getImageWritersByFormatName(n);
|
||||
if (!it.hasNext()) {
|
||||
throw new RuntimeException("getWriterFormatNames returned " +
|
||||
"an unknown name: " + n);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void testGetWriterMIMETypes() {
|
||||
String[] types = ImageIO.getWriterMIMETypes();
|
||||
for (String t : types) {
|
||||
Iterator<ImageWriter> it = ImageIO.getImageWritersByMIMEType(t);
|
||||
if (!it.hasNext()) {
|
||||
throw new RuntimeException("getWriterMIMETypes returned " +
|
||||
"an unknown type: " + t);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void testGetWriterFileSuffixes() {
|
||||
String[] suffixes = ImageIO.getWriterFileSuffixes();
|
||||
for (String s : suffixes) {
|
||||
Iterator<ImageWriter> it = ImageIO.getImageWritersBySuffix(s);
|
||||
if (!it.hasNext()) {
|
||||
throw new RuntimeException("getWriterFileSuffixes returned " +
|
||||
"an unknown suffix: " + s);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
testGetReaderFormatNames();
|
||||
testGetReaderMIMETypes();
|
||||
testGetReaderFileSuffixes();
|
||||
testGetWriterFormatNames();
|
||||
testGetWriterMIMETypes();
|
||||
testGetWriterFileSuffixes();
|
||||
}
|
||||
}
|
46
jdk/test/javax/imageio/IIOImageConstructor.java
Normal file
46
jdk/test/javax/imageio/IIOImageConstructor.java
Normal file
@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (c) 2000, 2017, 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 4392024
|
||||
* @summary Checks for IllegalArgumentException in IIOImage constructor
|
||||
*/
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
import javax.imageio.IIOImage;
|
||||
|
||||
public class IIOImageConstructor {
|
||||
|
||||
public static void main(String[] args) {
|
||||
BufferedImage image = new BufferedImage(1, 1,
|
||||
BufferedImage.TYPE_INT_RGB);
|
||||
try {
|
||||
IIOImage iioi = new IIOImage(image, null, null);
|
||||
} catch (IllegalArgumentException iae) {
|
||||
throw new RuntimeException
|
||||
("IIOImage constructor taking a RenderedImage fails!");
|
||||
}
|
||||
}
|
||||
}
|
79
jdk/test/javax/imageio/ITSDataType.java
Normal file
79
jdk/test/javax/imageio/ITSDataType.java
Normal file
@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Copyright (c) 2002, 2017, 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 4506450
|
||||
* @summary Tests whether ImageTypeSpecifier.createBanded() and
|
||||
* ImageTypeSpecifier.createInterleaved() can accept all supported
|
||||
* DataBuffer types
|
||||
*/
|
||||
|
||||
import java.awt.color.ColorSpace;
|
||||
import java.awt.image.DataBuffer;
|
||||
|
||||
import javax.imageio.ImageTypeSpecifier;
|
||||
|
||||
public class ITSDataType {
|
||||
|
||||
public static final int[] dataTypes = new int[] {
|
||||
DataBuffer.TYPE_BYTE,
|
||||
DataBuffer.TYPE_SHORT,
|
||||
DataBuffer.TYPE_USHORT,
|
||||
DataBuffer.TYPE_INT,
|
||||
DataBuffer.TYPE_FLOAT,
|
||||
DataBuffer.TYPE_DOUBLE,
|
||||
};
|
||||
|
||||
public static void main(String[] args) {
|
||||
ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_GRAY);
|
||||
int[] bankIndices = new int[] { 1 };
|
||||
int[] bandOffsets = new int[] { 0 };
|
||||
|
||||
// test createBanded()
|
||||
for (int i = 0; i < dataTypes.length; i++) {
|
||||
int dataType = dataTypes[i];
|
||||
|
||||
try {
|
||||
ImageTypeSpecifier.createBanded(cs, bankIndices, bandOffsets,
|
||||
dataType, false, false);
|
||||
} catch (IllegalArgumentException e) {
|
||||
throw new RuntimeException("createBanded() test failed for " +
|
||||
"dataType = " + dataType);
|
||||
}
|
||||
}
|
||||
|
||||
// test createInterleaved()
|
||||
for (int i = 0; i < dataTypes.length; i++) {
|
||||
int dataType = dataTypes[i];
|
||||
|
||||
try {
|
||||
ImageTypeSpecifier.createInterleaved(cs, bandOffsets,
|
||||
dataType, false, false);
|
||||
} catch (IllegalArgumentException e) {
|
||||
throw new RuntimeException("createInterleaved() test failed " +
|
||||
"for dataType = " + dataType);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
46
jdk/test/javax/imageio/ImageIOGetImageReaders.java
Normal file
46
jdk/test/javax/imageio/ImageIOGetImageReaders.java
Normal file
@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (c) 2001, 2017, 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 4432107
|
||||
* @summary Checks if ImageIO.getImageReaders(null) throws an IAE
|
||||
*/
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
public class ImageIOGetImageReaders {
|
||||
|
||||
public static void main(String[] args) {
|
||||
boolean gotIAE = false;
|
||||
try {
|
||||
ImageIO.getImageReaders(null);
|
||||
} catch (IllegalArgumentException e) {
|
||||
gotIAE = true;
|
||||
}
|
||||
|
||||
if (!gotIAE) {
|
||||
throw new RuntimeException("Failed to get IAE!");
|
||||
}
|
||||
}
|
||||
}
|
78
jdk/test/javax/imageio/ImageIOWriteFile.java
Normal file
78
jdk/test/javax/imageio/ImageIOWriteFile.java
Normal file
@ -0,0 +1,78 @@
|
||||
/*
|
||||
* Copyright (c) 2000, 2017, 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 4393174
|
||||
* @summary Checks that ImageIO.write(..., ..., File) truncates the file
|
||||
*/
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
public class ImageIOWriteFile {
|
||||
|
||||
public static void main(String[] args) {
|
||||
long length0 = -1L;
|
||||
long length1 = -1L;
|
||||
|
||||
try {
|
||||
BufferedImage bi =
|
||||
new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB);
|
||||
|
||||
File outFile = File.createTempFile("imageiowritefile", ".tmp");
|
||||
|
||||
// Write image to an empty file
|
||||
outFile.delete();
|
||||
ImageIO.write(bi, "png", outFile);
|
||||
length0 = outFile.length();
|
||||
|
||||
// Write a larger file full of junk
|
||||
outFile.delete();
|
||||
FileOutputStream fos = new FileOutputStream(outFile);
|
||||
for (int i = 0; i < length0*2; i++) {
|
||||
fos.write(1);
|
||||
}
|
||||
fos.close();
|
||||
|
||||
// Write image again
|
||||
ImageIO.write(bi, "png", outFile);
|
||||
length1 = outFile.length();
|
||||
|
||||
outFile.delete();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException("Unexpected exception!");
|
||||
}
|
||||
|
||||
if (length0 == 0) {
|
||||
throw new RuntimeException("File length is zero!");
|
||||
}
|
||||
if (length1 != length0) {
|
||||
throw new RuntimeException("File length changed!");
|
||||
}
|
||||
}
|
||||
}
|
45
jdk/test/javax/imageio/ImageIOWriteNull.java
Normal file
45
jdk/test/javax/imageio/ImageIOWriteNull.java
Normal file
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (c) 2001, 2017, 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 4434855
|
||||
* @summary Checks that ImageIO.write(null, null, (File)null) throws an IAE
|
||||
*/
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
public class ImageIOWriteNull {
|
||||
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
ImageIO.write(null, null, (File)null);
|
||||
throw new RuntimeException("Failed to get IAE!");
|
||||
} catch (IllegalArgumentException iae) {
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Unexpected exception: " + e);
|
||||
}
|
||||
}
|
||||
}
|
101
jdk/test/javax/imageio/ImageReadParamPasses.java
Normal file
101
jdk/test/javax/imageio/ImageReadParamPasses.java
Normal file
@ -0,0 +1,101 @@
|
||||
/*
|
||||
* Copyright (c) 2001, 2017, 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 4429365
|
||||
* @summary Checks that ImageReadParam.setSourceProgressivePasses handles
|
||||
* overflow correctly
|
||||
*/
|
||||
|
||||
import javax.imageio.ImageReadParam;
|
||||
|
||||
public class ImageReadParamPasses {
|
||||
|
||||
private static final int maxint = Integer.MAX_VALUE;
|
||||
|
||||
private static void expect(int i, int j) {
|
||||
if (i != j) {
|
||||
throw new RuntimeException("Expected " + i + ", got " + j);
|
||||
}
|
||||
}
|
||||
|
||||
private static void checkForIAE(int minPass, int numPasses) {
|
||||
ImageReadParam param = new ImageReadParam();
|
||||
|
||||
boolean gotIAE = false;
|
||||
try {
|
||||
param.setSourceProgressivePasses(minPass, numPasses);
|
||||
} catch (IllegalArgumentException iae) {
|
||||
gotIAE = true;
|
||||
}
|
||||
if (!gotIAE) {
|
||||
throw new RuntimeException("Failed to get IAE for wraparound!");
|
||||
}
|
||||
}
|
||||
|
||||
private static void test(int minPass, int numPasses) {
|
||||
ImageReadParam param = new ImageReadParam();
|
||||
|
||||
param.setSourceProgressivePasses(minPass, numPasses);
|
||||
expect(param.getSourceMinProgressivePass(), minPass);
|
||||
expect(param.getSourceNumProgressivePasses(), numPasses);
|
||||
|
||||
int maxPass = numPasses == maxint ? maxint : minPass + numPasses - 1;
|
||||
expect(param.getSourceMaxProgressivePass(), maxPass);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
// Typical case
|
||||
test(17, 30);
|
||||
|
||||
// Read all passes
|
||||
test(0, maxint);
|
||||
|
||||
// Start at pass 17, continue indefinitely
|
||||
test(17, maxint);
|
||||
|
||||
// Start at pass maxint - 10, continue indefinitely
|
||||
test(maxint - 10, maxint);
|
||||
|
||||
// Start at pass maxint - 10, go up to maxint - 1
|
||||
test(maxint - 10, 10);
|
||||
|
||||
// Start at pass maxint - 10, go up to maxint
|
||||
test(maxint - 10, 11);
|
||||
|
||||
// Start at maxint, continue indefinitely :-)
|
||||
test(maxint, maxint);
|
||||
|
||||
// Start at maxint, go up to maxint
|
||||
test(maxint, 1);
|
||||
|
||||
// Check that an IllegalArgumentException is thrown if
|
||||
// wraparound occurs
|
||||
checkForIAE(maxint, 2);
|
||||
checkForIAE(maxint - 5, 10);
|
||||
checkForIAE(10, maxint - 5);
|
||||
checkForIAE(maxint - 1000, maxint - 1000);
|
||||
checkForIAE(maxint - 1, maxint - 1);
|
||||
}
|
||||
}
|
132
jdk/test/javax/imageio/ImageReaderGetDestination.java
Normal file
132
jdk/test/javax/imageio/ImageReaderGetDestination.java
Normal file
@ -0,0 +1,132 @@
|
||||
/*
|
||||
* Copyright (c) 2001, 2017, 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 4449211
|
||||
* @summary Checks that ImageReader.getDestination throws correct exceptions
|
||||
*/
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.IOException;
|
||||
import java.util.Iterator;
|
||||
import java.util.Vector;
|
||||
|
||||
import javax.imageio.IIOException;
|
||||
import javax.imageio.ImageReadParam;
|
||||
import javax.imageio.ImageReader;
|
||||
import javax.imageio.ImageTypeSpecifier;
|
||||
import javax.imageio.metadata.IIOMetadata;
|
||||
import javax.imageio.spi.ImageReaderSpi;
|
||||
|
||||
public class ImageReaderGetDestination {
|
||||
|
||||
public static void main(String argv[]) {
|
||||
Vector imageTypes = new Vector();
|
||||
boolean gotIAE1 = false;
|
||||
boolean gotIAE2 = false;
|
||||
boolean gotIAE3 = false;
|
||||
boolean gotIAE4 = false;
|
||||
|
||||
try {
|
||||
DummyImageReaderImpl.getDestination(null, null, 5, 10);
|
||||
} catch (IllegalArgumentException iae) {
|
||||
gotIAE1 = true;
|
||||
} catch (Throwable ee) {
|
||||
System.out.println("Unexpected exception 1:");
|
||||
ee.printStackTrace();
|
||||
}
|
||||
if (!gotIAE1) {
|
||||
throw new RuntimeException("Failed to get IAE #1!");
|
||||
}
|
||||
|
||||
try {
|
||||
DummyImageReaderImpl.getDestination(null, imageTypes.iterator(),
|
||||
5, 10);
|
||||
} catch (IllegalArgumentException iae) {
|
||||
gotIAE2 = true;
|
||||
} catch (Throwable ee) {
|
||||
System.out.println("Unexpected exception 2:");
|
||||
ee.printStackTrace();
|
||||
}
|
||||
if (!gotIAE2) {
|
||||
throw new RuntimeException("Failed to get IAE #2!");
|
||||
}
|
||||
|
||||
imageTypes.add("abc");
|
||||
try {
|
||||
DummyImageReaderImpl.getDestination(null, imageTypes.iterator(),
|
||||
5, 10);
|
||||
} catch (IllegalArgumentException iae) {
|
||||
gotIAE3 = true;
|
||||
} catch (Throwable ee) {
|
||||
System.out.println("Unexpected exception 3:");
|
||||
ee.printStackTrace();
|
||||
}
|
||||
if (!gotIAE3) {
|
||||
throw new RuntimeException("Failed to get IAE #3!");
|
||||
}
|
||||
|
||||
imageTypes.clear();
|
||||
ImageTypeSpecifier its = ImageTypeSpecifier.createFromBufferedImageType
|
||||
(BufferedImage.TYPE_INT_RGB);
|
||||
imageTypes.add(its);
|
||||
try {
|
||||
DummyImageReaderImpl.getDestination(null,
|
||||
imageTypes.iterator(),
|
||||
Integer.MAX_VALUE,
|
||||
Integer.MAX_VALUE);
|
||||
} catch (IllegalArgumentException iae) {
|
||||
gotIAE4 = true;
|
||||
} catch (Throwable ee) {
|
||||
System.out.println("Unexpected exception 4: ");
|
||||
ee.printStackTrace();
|
||||
}
|
||||
if (!gotIAE4) {
|
||||
throw new RuntimeException("Failed to get IAE #4!");
|
||||
}
|
||||
}
|
||||
|
||||
public static class DummyImageReaderImpl extends ImageReader {
|
||||
public DummyImageReaderImpl(ImageReaderSpi originatingProvider) {
|
||||
super(originatingProvider);
|
||||
}
|
||||
public static BufferedImage getDestination(ImageReadParam param,
|
||||
Iterator imageTypes,
|
||||
int width,
|
||||
int height)
|
||||
throws IIOException {
|
||||
return ImageReader.getDestination(param, imageTypes, width, height);
|
||||
}
|
||||
public int getNumImages(boolean allowSearch) throws IOException {return 1;}
|
||||
public int getWidth(int imageIndex) throws IOException {return 1;}
|
||||
public int getHeight(int imageIndex) throws IOException {return 1;}
|
||||
public Iterator getImageTypes(int imageIndex)
|
||||
throws IOException {return null;}
|
||||
public IIOMetadata getStreamMetadata() throws IOException {return null;}
|
||||
public IIOMetadata getImageMetadata(int imageIndex)
|
||||
throws IOException {return null;}
|
||||
public BufferedImage read(int imageIndex, ImageReadParam param)
|
||||
throws IOException {return null;}
|
||||
}
|
||||
}
|
120
jdk/test/javax/imageio/ImageReaderReadAll.java
Normal file
120
jdk/test/javax/imageio/ImageReaderReadAll.java
Normal file
@ -0,0 +1,120 @@
|
||||
/*
|
||||
* Copyright (c) 2001, 2017, 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 4450319
|
||||
* @summary Checks that ImageReader.readAll(int, ImageReadParam) makes use of
|
||||
* the ImageReadParam object
|
||||
*/
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Iterator;
|
||||
import java.util.Vector;
|
||||
|
||||
import javax.imageio.IIOImage;
|
||||
import javax.imageio.ImageReadParam;
|
||||
import javax.imageio.ImageReader;
|
||||
import javax.imageio.ImageTypeSpecifier;
|
||||
import javax.imageio.metadata.IIOMetadata;
|
||||
import javax.imageio.spi.ImageReaderSpi;
|
||||
import javax.imageio.stream.MemoryCacheImageInputStream;
|
||||
|
||||
public class ImageReaderReadAll {
|
||||
|
||||
private final static byte[] ba = {};
|
||||
|
||||
public static void main(String argv[]) {
|
||||
ImageReader ireader;
|
||||
ImageReadParam irp;
|
||||
IIOImage image;
|
||||
BufferedImage bi;
|
||||
BufferedImage bi_1;
|
||||
BufferedImage bi_2;
|
||||
|
||||
ireader = new DummyImageReaderImpl(null);
|
||||
MemoryCacheImageInputStream mciis = new MemoryCacheImageInputStream
|
||||
(new ByteArrayInputStream(ba));
|
||||
ireader.setInput(mciis);
|
||||
|
||||
irp = new ImageReadParam();
|
||||
irp.setDestination(new BufferedImage(10, 10,
|
||||
BufferedImage.TYPE_3BYTE_BGR));
|
||||
try {
|
||||
image = ireader.readAll(0, irp);
|
||||
bi_1 = ireader.read(0, irp);
|
||||
bi_2 = ireader.read(0);
|
||||
} catch (java.io.IOException ee) {
|
||||
throw new RuntimeException("Unexpected exception: " + ee);
|
||||
}
|
||||
|
||||
bi = (BufferedImage)image.getRenderedImage();
|
||||
if (bi.getType() != bi_1.getType()) {
|
||||
throw new RuntimeException("Images have different type!");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class DummyImageReaderImpl extends ImageReader {
|
||||
|
||||
public DummyImageReaderImpl(ImageReaderSpi originatingProvider) {
|
||||
super(originatingProvider);
|
||||
}
|
||||
|
||||
public BufferedImage read(int imageIndex, ImageReadParam param)
|
||||
throws IOException {
|
||||
if (input == null)
|
||||
throw new IllegalStateException();
|
||||
if (imageIndex >= 1 || imageIndex < 0)
|
||||
throw new IndexOutOfBoundsException();
|
||||
if (seekForwardOnly) {
|
||||
if (imageIndex < minIndex)
|
||||
throw new IndexOutOfBoundsException();
|
||||
minIndex = imageIndex;
|
||||
}
|
||||
|
||||
return getDestination(param, getImageTypes(imageIndex), 10, 15);
|
||||
}
|
||||
|
||||
public Iterator getImageTypes(int imageIndex) throws IOException {
|
||||
if (input == null)
|
||||
throw new IllegalStateException();
|
||||
if (imageIndex >= 1 || imageIndex < 0)
|
||||
throw new IndexOutOfBoundsException();
|
||||
|
||||
Vector imageTypes = new Vector();
|
||||
imageTypes.add(ImageTypeSpecifier.createFromBufferedImageType
|
||||
(BufferedImage.TYPE_BYTE_GRAY ));
|
||||
return imageTypes.iterator();
|
||||
}
|
||||
|
||||
public int getNumImages(boolean allowSearch) throws IOException {return 1;}
|
||||
public int getWidth(int imageIndex) throws IOException {return 1;}
|
||||
public int getHeight(int imageIndex) throws IOException {return 1;}
|
||||
public IIOMetadata getStreamMetadata() throws IOException {return null;}
|
||||
public IIOMetadata getImageMetadata(int imageIndex)
|
||||
throws IOException {return null;}
|
||||
}
|
||||
}
|
67
jdk/test/javax/imageio/ImageStreamFromRAF.java
Normal file
67
jdk/test/javax/imageio/ImageStreamFromRAF.java
Normal file
@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright (c) 2001, 2017, 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 4395378
|
||||
* @summary Checks that ImageIO.createImageInputStream and
|
||||
* createImageOutputStream produce correct output when given a
|
||||
* RandomAccessFile
|
||||
*/
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.RandomAccessFile;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.stream.FileImageInputStream;
|
||||
import javax.imageio.stream.FileImageOutputStream;
|
||||
import javax.imageio.stream.ImageInputStream;
|
||||
import javax.imageio.stream.ImageOutputStream;
|
||||
|
||||
public class ImageStreamFromRAF {
|
||||
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
File f = new File("ImageInputStreamFromRAF.tmp");
|
||||
RandomAccessFile raf = new RandomAccessFile(f, "rw");
|
||||
ImageInputStream istream = ImageIO.createImageInputStream(raf);
|
||||
ImageOutputStream ostream = ImageIO.createImageOutputStream(raf);
|
||||
f.delete();
|
||||
if (istream == null) {
|
||||
throw new RuntimeException("ImageIO.createImageInputStream(RandomAccessFile) returned null!");
|
||||
}
|
||||
if (ostream == null) {
|
||||
throw new RuntimeException("ImageIO.createImageOutputStream(RandomAccessFile) returned null!");
|
||||
}
|
||||
if (!(istream instanceof FileImageInputStream)) {
|
||||
throw new RuntimeException("ImageIO.createImageInputStream(RandomAccessFile) did not return a FileImageInputStream!");
|
||||
}
|
||||
if (!(ostream instanceof FileImageOutputStream)) {
|
||||
throw new RuntimeException("ImageIO.createImageOutputStream(RandomAccessFile) did not return a FileImageOutputStream!");
|
||||
}
|
||||
} catch (IOException ioe) {
|
||||
throw new RuntimeException("Unexpected IOException: " + ioe);
|
||||
}
|
||||
}
|
||||
}
|
60
jdk/test/javax/imageio/ImageTypeSpecifierBitsPerBand.java
Normal file
60
jdk/test/javax/imageio/ImageTypeSpecifierBitsPerBand.java
Normal file
@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright (c) 2000, 2017, 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 4392669
|
||||
* @summary Checks contract of ImageTypeSpecifier.getBitsPerBand
|
||||
*/
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
import javax.imageio.ImageTypeSpecifier;
|
||||
|
||||
public class ImageTypeSpecifierBitsPerBand {
|
||||
|
||||
public static void main(String[] args) {
|
||||
int biType = BufferedImage.TYPE_USHORT_565_RGB;
|
||||
ImageTypeSpecifier type =
|
||||
ImageTypeSpecifier.createFromBufferedImageType(biType);
|
||||
|
||||
int b0 = type.getBitsPerBand(0);
|
||||
int b1 = type.getBitsPerBand(1);
|
||||
int b2 = type.getBitsPerBand(2);
|
||||
|
||||
if (b0 != 5 || b1 != 6 || b2 != 5) {
|
||||
throw new RuntimeException("Got incorrect bits per band value!");
|
||||
}
|
||||
|
||||
boolean gotIAE = false;
|
||||
try {
|
||||
int b3 = type.getBitsPerBand(3);
|
||||
} catch (IllegalArgumentException e) {
|
||||
gotIAE = true;
|
||||
}
|
||||
if (!gotIAE) {
|
||||
throw new RuntimeException
|
||||
("Failed to get IllegalArgumentException for band == 3!");
|
||||
}
|
||||
}
|
||||
}
|
310
jdk/test/javax/imageio/ImageTypeSpecifierTest.java
Normal file
310
jdk/test/javax/imageio/ImageTypeSpecifierTest.java
Normal file
@ -0,0 +1,310 @@
|
||||
/*
|
||||
* Copyright (c) 2001, 2017, 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 4429934 4429950 4430991 4430993
|
||||
* @summary Checks various aspects of ImageTypeSpecifier functionality
|
||||
*/
|
||||
|
||||
import java.awt.color.ColorSpace;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.image.ColorModel;
|
||||
import java.awt.image.DataBuffer;
|
||||
import java.awt.image.SampleModel;
|
||||
|
||||
import javax.imageio.ImageTypeSpecifier;
|
||||
|
||||
public class ImageTypeSpecifierTest {
|
||||
|
||||
private static void fail(String message) {
|
||||
throw new RuntimeException(message);
|
||||
}
|
||||
|
||||
private static void test4429934() {
|
||||
try {
|
||||
ImageTypeSpecifier itspecifier =
|
||||
new ImageTypeSpecifier(null, null);
|
||||
fail("Failed to get IAE!");
|
||||
} catch( IllegalArgumentException e ) {
|
||||
}
|
||||
|
||||
try {
|
||||
ImageTypeSpecifier itspecifier = new ImageTypeSpecifier(null);
|
||||
fail("Failed to get IAE!");
|
||||
} catch (IllegalArgumentException e ) {
|
||||
}
|
||||
}
|
||||
|
||||
private static void test4429950() {
|
||||
createPackedTest();
|
||||
createInterleavedTest();
|
||||
createBandedTest();
|
||||
createIndexedTest();
|
||||
}
|
||||
|
||||
public static void createPackedTest() {
|
||||
ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
|
||||
int rmask = 0x00ff0000;
|
||||
int gmask = 0x0000ff00;
|
||||
int bmask = 0x000000ff;
|
||||
int amask = 0xff000000;
|
||||
try {
|
||||
ImageTypeSpecifier.createPacked(null, rmask, gmask, bmask, amask, 0,
|
||||
false);
|
||||
fail("Failed to get IAE!");
|
||||
} catch (IllegalArgumentException e) {
|
||||
}
|
||||
|
||||
ColorSpace cs1 = ColorSpace.getInstance(ColorSpace.CS_GRAY);
|
||||
try {
|
||||
ImageTypeSpecifier.createPacked
|
||||
(cs1, rmask, gmask, bmask, amask, 0, false);
|
||||
fail("Failed to get IAE!");
|
||||
} catch (IllegalArgumentException e) {
|
||||
}
|
||||
|
||||
try {
|
||||
ImageTypeSpecifier.createPacked(cs, 0, 0, 0, 0, 0, false);
|
||||
fail("Failed to get IAE!");
|
||||
} catch (IllegalArgumentException e) {
|
||||
}
|
||||
|
||||
try {
|
||||
ImageTypeSpecifier.createPacked(cs, rmask, gmask, bmask, amask, -1,
|
||||
false);
|
||||
fail("Failed to get IAE!");
|
||||
} catch (IllegalArgumentException e) {
|
||||
}
|
||||
}
|
||||
|
||||
public static void createInterleavedTest() {
|
||||
ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
|
||||
int[] bandOffsets = {0,0,0,0};
|
||||
int dataType = 0;
|
||||
boolean hasAlpha = true;
|
||||
boolean isAlphaPremultiplied = true;
|
||||
|
||||
try {
|
||||
ImageTypeSpecifier.createInterleaved
|
||||
(null, bandOffsets, dataType, hasAlpha, isAlphaPremultiplied);
|
||||
fail("Failed to get IAE!");
|
||||
} catch (IllegalArgumentException e) {
|
||||
}
|
||||
|
||||
try {
|
||||
ImageTypeSpecifier.createInterleaved
|
||||
(cs, null, dataType, hasAlpha, isAlphaPremultiplied);
|
||||
fail("Failed to get IAE!");
|
||||
} catch (IllegalArgumentException e) {
|
||||
}
|
||||
|
||||
int[] bad_bandOffsets = {0,100,1000};
|
||||
try {
|
||||
ImageTypeSpecifier.createInterleaved
|
||||
(cs, bad_bandOffsets, dataType, hasAlpha, isAlphaPremultiplied);
|
||||
fail("Failed to get IAE!");
|
||||
} catch (IllegalArgumentException e) {
|
||||
}
|
||||
|
||||
int[] bad_bandOffsets_1 = {};
|
||||
try {
|
||||
ImageTypeSpecifier.createInterleaved
|
||||
(cs, bad_bandOffsets_1, dataType, hasAlpha, isAlphaPremultiplied);
|
||||
fail("Failed to get IAE!");
|
||||
} catch (IllegalArgumentException e) {
|
||||
}
|
||||
}
|
||||
|
||||
public static void createBandedTest() {
|
||||
ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
|
||||
int[] bankIndices = {0, 100, 1000, 10000};
|
||||
int[] bandOffsets = {0, 100, 1000, 10000};
|
||||
int dataType = 0;
|
||||
boolean hasAlpha = true;
|
||||
boolean isAlphaPremultiplied = true;
|
||||
|
||||
try {
|
||||
ImageTypeSpecifier.createBanded(null, bankIndices, bandOffsets,
|
||||
dataType, hasAlpha, isAlphaPremultiplied);
|
||||
fail("Failed to get IAE!");
|
||||
} catch (IllegalArgumentException e) {
|
||||
}
|
||||
|
||||
int[] bad_bankIndices = {};
|
||||
int[] bad_bandOffsets = {};
|
||||
try {
|
||||
ImageTypeSpecifier.createBanded(cs, bad_bankIndices, bad_bandOffsets,
|
||||
dataType, hasAlpha, isAlphaPremultiplied);
|
||||
fail("Failed to get IAE!");
|
||||
} catch (IllegalArgumentException e) {
|
||||
}
|
||||
|
||||
try {
|
||||
ImageTypeSpecifier.createBanded(cs, bankIndices, bandOffsets,
|
||||
99999, hasAlpha, isAlphaPremultiplied);
|
||||
fail("Failed to get IAE!");
|
||||
} catch (IllegalArgumentException e) {
|
||||
}
|
||||
}
|
||||
|
||||
public static void createGrayscaleTest() {
|
||||
int bits = 8;
|
||||
int dataType = DataBuffer.TYPE_BYTE;
|
||||
boolean isSigned = true;
|
||||
// testcase 1
|
||||
try {
|
||||
ImageTypeSpecifier.createGrayscale(100, dataType, isSigned);
|
||||
fail("Failed to get IAE!");
|
||||
} catch (IllegalArgumentException e) {
|
||||
}
|
||||
|
||||
try {
|
||||
ImageTypeSpecifier.createGrayscale(10, dataType, isSigned);
|
||||
fail("Failed to get IAE!");
|
||||
} catch (IllegalArgumentException e) {
|
||||
}
|
||||
|
||||
try {
|
||||
ImageTypeSpecifier.createGrayscale(bits, 100, isSigned);
|
||||
fail("Failed to get IAE!");
|
||||
} catch (IllegalArgumentException e) {
|
||||
}
|
||||
}
|
||||
|
||||
public static void createIndexedTest() {
|
||||
byte[] redLUT = {0};
|
||||
byte[] greenLUT = {0};
|
||||
byte[] blueLUT = {0};
|
||||
byte[] alphaLUT = {0};
|
||||
int bits = 8;
|
||||
int dataType = DataBuffer.TYPE_BYTE;
|
||||
|
||||
try {
|
||||
ImageTypeSpecifier.createIndexed(redLUT, greenLUT,
|
||||
blueLUT, alphaLUT, 0, dataType);
|
||||
fail("Failed to get IAE!");
|
||||
} catch (IllegalArgumentException e) {
|
||||
}
|
||||
|
||||
try {
|
||||
ImageTypeSpecifier.createIndexed(redLUT, greenLUT,
|
||||
blueLUT, alphaLUT, 17, dataType);
|
||||
fail("Failed to get IAE!");
|
||||
} catch (IllegalArgumentException e) {
|
||||
}
|
||||
|
||||
try {
|
||||
ImageTypeSpecifier.createIndexed(redLUT, greenLUT,
|
||||
blueLUT, alphaLUT, 10, dataType);
|
||||
fail("Failed to get IAE!");
|
||||
} catch (IllegalArgumentException e) {
|
||||
}
|
||||
|
||||
byte[] greenLUT_4 = {};
|
||||
try {
|
||||
ImageTypeSpecifier.createIndexed(redLUT, greenLUT_4,
|
||||
blueLUT, alphaLUT, bits, dataType);
|
||||
fail("Failed to get IAE!");
|
||||
} catch (IllegalArgumentException e) {
|
||||
}
|
||||
|
||||
byte[] redLUT_5 = {};
|
||||
try {
|
||||
ImageTypeSpecifier.createIndexed(redLUT_5, greenLUT,
|
||||
blueLUT, alphaLUT, bits, dataType);
|
||||
fail("Failed to get IAE!");
|
||||
} catch (IllegalArgumentException e) {
|
||||
}
|
||||
|
||||
byte[] alphaLUT_6 = {};
|
||||
try {
|
||||
ImageTypeSpecifier.createIndexed(redLUT, greenLUT,
|
||||
blueLUT, alphaLUT_6 , bits, dataType);
|
||||
fail("Failed to get IAE!");
|
||||
} catch (IllegalArgumentException e) {
|
||||
}
|
||||
|
||||
try {
|
||||
ImageTypeSpecifier.createIndexed(redLUT, greenLUT,
|
||||
blueLUT, alphaLUT , bits, 100);
|
||||
fail("Failed to get IAE!");
|
||||
} catch (IllegalArgumentException e) {
|
||||
}
|
||||
}
|
||||
|
||||
private static void test4430991() {
|
||||
ImageTypeSpecifier itspecifier;
|
||||
|
||||
itspecifier = ImageTypeSpecifier.createFromBufferedImageType
|
||||
(BufferedImage.TYPE_INT_RGB);
|
||||
|
||||
try {
|
||||
itspecifier.createBufferedImage(Integer.MAX_VALUE,
|
||||
Integer.MAX_VALUE);
|
||||
fail("Failed to get IAE!");
|
||||
} catch (IllegalArgumentException e) {
|
||||
}
|
||||
|
||||
try {
|
||||
itspecifier.getSampleModel(Integer.MAX_VALUE, Integer.MAX_VALUE);
|
||||
fail("Failed to get IAE!");
|
||||
} catch (IllegalArgumentException e) {
|
||||
}
|
||||
}
|
||||
|
||||
private static void test4430993() {
|
||||
ImageTypeSpecifier itspecifier;
|
||||
|
||||
int bits = 32;
|
||||
int rmask = 0x00ff0000;
|
||||
int gmask = 0x0000ff00;
|
||||
int bmask = 0x000000ff;
|
||||
ColorModel dcm = new java.awt.image.DirectColorModel
|
||||
(bits, rmask, gmask, bmask);
|
||||
int[] bandOffsets = new int[2];
|
||||
bandOffsets[1] = 1;
|
||||
SampleModel sm = new java.awt.image.ComponentSampleModel
|
||||
(DataBuffer.TYPE_SHORT, 1, 1, 2, 2, bandOffsets);
|
||||
|
||||
try {
|
||||
itspecifier = new ImageTypeSpecifier(dcm, sm);
|
||||
fail("Failed to get IAE!");
|
||||
} catch (IllegalArgumentException e) {
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
test4429934();
|
||||
test4429950();
|
||||
test4430991();
|
||||
test4430993();
|
||||
} catch (RuntimeException e) {
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
System.out.println("Unexpected exception: " + e);
|
||||
}
|
||||
}
|
||||
}
|
105
jdk/test/javax/imageio/ImageWriteParamMisc.java
Normal file
105
jdk/test/javax/imageio/ImageWriteParamMisc.java
Normal file
@ -0,0 +1,105 @@
|
||||
/*
|
||||
* Copyright (c) 2001, 2017, 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 4434870 4434886 4441315 4446842
|
||||
* @summary Checks that miscellaneous ImageWriteParam methods work properly
|
||||
*/
|
||||
|
||||
import java.awt.Dimension;
|
||||
|
||||
import javax.imageio.ImageWriteParam;
|
||||
|
||||
public class ImageWriteParamMisc {
|
||||
|
||||
public static void main(String[] args) {
|
||||
test4434870();
|
||||
test4434886();
|
||||
test4441315();
|
||||
test4446842();
|
||||
}
|
||||
|
||||
public static class ImageWriteParam4434870 extends ImageWriteParam {
|
||||
public ImageWriteParam4434870() {
|
||||
super(null);
|
||||
super.canWriteTiles = true;
|
||||
super.preferredTileSizes =
|
||||
new Dimension[] {new Dimension(1, 2), new Dimension(5, 6)};
|
||||
}
|
||||
}
|
||||
|
||||
private static void test4434870() {
|
||||
ImageWriteParam iwp = new ImageWriteParam4434870();
|
||||
try {
|
||||
Dimension[] dimensions = iwp.getPreferredTileSizes();
|
||||
iwp.setTilingMode(ImageWriteParam.MODE_EXPLICIT);
|
||||
iwp.setTiling(100, 100, 0,0);
|
||||
throw new RuntimeException("Failed to get IAE!");
|
||||
} catch (IllegalArgumentException e) {
|
||||
}
|
||||
}
|
||||
|
||||
public static class ImageWriteParam4434886 extends ImageWriteParam {
|
||||
public ImageWriteParam4434886() {
|
||||
super(null);
|
||||
super.canWriteTiles = true;
|
||||
super.canOffsetTiles = true;
|
||||
}
|
||||
}
|
||||
|
||||
private static void test4434886() {
|
||||
ImageWriteParam iwp = new ImageWriteParam4434886();
|
||||
iwp.setTilingMode(ImageWriteParam.MODE_EXPLICIT);
|
||||
try {
|
||||
iwp.setTiling(-1,-2,-3,-4);
|
||||
throw new RuntimeException("Failed to get IAE!");
|
||||
} catch (IllegalArgumentException e) {
|
||||
}
|
||||
}
|
||||
|
||||
public static class ImageWriteParam4441315 extends ImageWriteParam {
|
||||
public ImageWriteParam4441315() {
|
||||
super(null);
|
||||
super.canWriteProgressive = true;
|
||||
}
|
||||
}
|
||||
|
||||
private static void test4441315() {
|
||||
ImageWriteParam iwp = new ImageWriteParam4441315();
|
||||
try {
|
||||
iwp.setProgressiveMode(ImageWriteParam.MODE_EXPLICIT);
|
||||
throw new RuntimeException("Failed to get IAE!");
|
||||
} catch (IllegalArgumentException e) {
|
||||
}
|
||||
}
|
||||
|
||||
private static void test4446842() {
|
||||
ImageWriteParam iwp = new ImageWriteParam(null);
|
||||
try {
|
||||
iwp.getCompressionTypes();
|
||||
throw new RuntimeException("Failed to get UOE!");
|
||||
} catch (UnsupportedOperationException e) {
|
||||
}
|
||||
}
|
||||
}
|
73
jdk/test/javax/imageio/NullInputOutput.java
Normal file
73
jdk/test/javax/imageio/NullInputOutput.java
Normal file
@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 2017, 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 4892682 4892698
|
||||
* @summary Tests that the appropriate IllegalStateException is thrown if
|
||||
* ImageReader.read() or ImageWriter.write() is called without having
|
||||
* first set the input/output stream
|
||||
*/
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.Iterator;
|
||||
|
||||
import javax.imageio.ImageReader;
|
||||
import javax.imageio.ImageWriter;
|
||||
import javax.imageio.spi.IIORegistry;
|
||||
import javax.imageio.spi.ImageReaderSpi;
|
||||
import javax.imageio.spi.ImageWriterSpi;
|
||||
|
||||
public class NullInputOutput {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
IIORegistry registry = IIORegistry.getDefaultInstance();
|
||||
|
||||
// test ImageReader.read() for all available ImageReaders
|
||||
Iterator readerspis = registry.getServiceProviders(ImageReaderSpi.class,
|
||||
false);
|
||||
while (readerspis.hasNext()) {
|
||||
ImageReaderSpi readerspi = (ImageReaderSpi)readerspis.next();
|
||||
ImageReader reader = readerspi.createReaderInstance();
|
||||
try {
|
||||
reader.read(0);
|
||||
} catch (IllegalStateException ise) {
|
||||
// caught exception, everything's okay
|
||||
}
|
||||
}
|
||||
|
||||
// test ImageWriter.write() for all available ImageWriters
|
||||
BufferedImage bi = new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB);
|
||||
Iterator writerspis = registry.getServiceProviders(ImageWriterSpi.class,
|
||||
false);
|
||||
while (writerspis.hasNext()) {
|
||||
ImageWriterSpi writerspi = (ImageWriterSpi)writerspis.next();
|
||||
ImageWriter writer = writerspi.createWriterInstance();
|
||||
try {
|
||||
writer.write(bi);
|
||||
} catch (IllegalStateException ise) {
|
||||
// caught exception, everything's okay
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
67
jdk/test/javax/imageio/PNGSpiStreamMetadata.java
Normal file
67
jdk/test/javax/imageio/PNGSpiStreamMetadata.java
Normal file
@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright (c) 2001, 2017, 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 4403355
|
||||
* @summary Checks that PNGImage{Reader,Writer}Spi.getStreamMetadataFormatNames
|
||||
* and getNativeStreamMetadataFormatName return null
|
||||
* @modules java.desktop/com.sun.imageio.plugins.png
|
||||
*/
|
||||
|
||||
import javax.imageio.spi.ImageReaderSpi;
|
||||
import javax.imageio.spi.ImageWriterSpi;
|
||||
|
||||
import com.sun.imageio.plugins.png.PNGImageReaderSpi;
|
||||
import com.sun.imageio.plugins.png.PNGImageWriterSpi;
|
||||
|
||||
public class PNGSpiStreamMetadata {
|
||||
|
||||
private static void fatal() {
|
||||
throw new RuntimeException("Got a non-null stream metadata format!");
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
ImageReaderSpi rspi = new PNGImageReaderSpi();
|
||||
if (rspi.getNativeStreamMetadataFormatName() != null) {
|
||||
fatal();
|
||||
}
|
||||
if (rspi.isStandardStreamMetadataFormatSupported() != false) {
|
||||
fatal();
|
||||
}
|
||||
if (rspi.getExtraStreamMetadataFormatNames() != null) {
|
||||
fatal();
|
||||
}
|
||||
|
||||
ImageWriterSpi wspi = new PNGImageWriterSpi();
|
||||
if (wspi.getNativeStreamMetadataFormatName() != null) {
|
||||
fatal();
|
||||
}
|
||||
if (wspi.isStandardStreamMetadataFormatSupported() != false) {
|
||||
fatal();
|
||||
}
|
||||
if (wspi.getExtraStreamMetadataFormatNames() != null) {
|
||||
fatal();
|
||||
}
|
||||
}
|
||||
}
|
43
jdk/test/javax/imageio/PNGSuffixes.java
Normal file
43
jdk/test/javax/imageio/PNGSuffixes.java
Normal file
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright (c) 2000, 2017, 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 4394924
|
||||
* @summary Checks for spurious leading "." in PNG file suffixes
|
||||
* @modules java.desktop/com.sun.imageio.plugins.png
|
||||
*/
|
||||
|
||||
import com.sun.imageio.plugins.png.PNGImageWriterSpi;
|
||||
|
||||
public class PNGSuffixes {
|
||||
|
||||
public static void main(String[] args) {
|
||||
String[] suffixes = new PNGImageWriterSpi().getFileSuffixes();
|
||||
for (int i = 0; i < suffixes.length; i++) {
|
||||
if (suffixes[i].startsWith(".")) {
|
||||
throw new RuntimeException("Found a \".\" in a suffix!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
90
jdk/test/javax/imageio/ReadBitsTest.java
Normal file
90
jdk/test/javax/imageio/ReadBitsTest.java
Normal file
@ -0,0 +1,90 @@
|
||||
/*
|
||||
* Copyright (c) 2001, 2017, 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 4416800
|
||||
* @summary Checks that ImageInputStreamImpl.readBit and readBits handle the bit
|
||||
* offset correctly
|
||||
*/
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import javax.imageio.stream.FileCacheImageInputStream;
|
||||
import javax.imageio.stream.ImageInputStream;
|
||||
|
||||
public class ReadBitsTest {
|
||||
public static void main(String[] args) throws IOException {
|
||||
byte[] buffer = new byte[] {(byte)169, (byte)85}; // 10101001 01010101
|
||||
InputStream ins = new ByteArrayInputStream(buffer);
|
||||
ImageInputStream in = new FileCacheImageInputStream(ins,null);
|
||||
|
||||
if (in.getBitOffset() != 0) {
|
||||
throw new RuntimeException("Initial bit offset != 0!");
|
||||
}
|
||||
|
||||
int bit0 = in.readBit(); // 1
|
||||
if (bit0 != 1) {
|
||||
throw new RuntimeException("First bit != 1");
|
||||
}
|
||||
if (in.getBitOffset() != 1) {
|
||||
throw new RuntimeException("Second bit offset != 1");
|
||||
}
|
||||
|
||||
long bits1 = in.readBits(5); // 01010 = 10
|
||||
if (bits1 != 10) {
|
||||
throw new RuntimeException("Bits 1-5 != 10 (= " + bits1 + ")");
|
||||
}
|
||||
if (in.getBitOffset() != 6) {
|
||||
throw new RuntimeException("Third bit offset != 6");
|
||||
}
|
||||
|
||||
int bit1 = in.readBit(); // 0
|
||||
if (bit1 != 0) {
|
||||
throw new RuntimeException("Bit 6 != 0");
|
||||
}
|
||||
if (in.getBitOffset() != 7) {
|
||||
throw new RuntimeException("Third bit offset != 7");
|
||||
}
|
||||
|
||||
long bits2 = in.readBits(8); // 10101010 = 170
|
||||
if (bits2 != 170) {
|
||||
throw new RuntimeException("Bits 7-14 != 170 (= " + bits2 + ")");
|
||||
}
|
||||
if (in.getBitOffset() != 7) {
|
||||
throw new RuntimeException("Fourth bit offset != 7");
|
||||
}
|
||||
|
||||
int bit2 = in.readBit(); // 1
|
||||
if (bit2 != 1) {
|
||||
throw new RuntimeException("Bit 15 != 1");
|
||||
}
|
||||
if (in.getBitOffset() != 0) {
|
||||
throw new RuntimeException("Fifth bit offset != 0");
|
||||
}
|
||||
|
||||
in.close();
|
||||
}
|
||||
}
|
55
jdk/test/javax/imageio/SetOutput.java
Normal file
55
jdk/test/javax/imageio/SetOutput.java
Normal file
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright (c) 2001, 2017, 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 4414455
|
||||
* @summary Checks for NPE from ImageWriter.setOutput when the writer has no
|
||||
* originating service provider
|
||||
* @modules java.desktop/com.sun.imageio.plugins.png
|
||||
*/
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.ImageWriter;
|
||||
import javax.imageio.stream.ImageOutputStream;
|
||||
|
||||
import com.sun.imageio.plugins.png.PNGImageWriter;
|
||||
|
||||
public class SetOutput {
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
ImageWriter iw = new PNGImageWriter(null);
|
||||
File f = File.createTempFile("imageio", "tmp");
|
||||
ImageOutputStream ios = ImageIO.createImageOutputStream(f);
|
||||
try {
|
||||
iw.setOutput(ios);
|
||||
} catch (NullPointerException npe) {
|
||||
f.delete();
|
||||
throw new RuntimeException("Got NullPointerException!");
|
||||
}
|
||||
f.delete();
|
||||
}
|
||||
}
|
89
jdk/test/javax/imageio/WriteNullImageTest.java
Normal file
89
jdk/test/javax/imageio/WriteNullImageTest.java
Normal file
@ -0,0 +1,89 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 2017, 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 4954545
|
||||
* @summary This test verifies whether the ImageWriter implementations throw
|
||||
* IllegalArgumentException when a null image is passed to the write
|
||||
* method. This is tested for all the image writers available with the
|
||||
* IIORegistry.
|
||||
*/
|
||||
|
||||
import java.io.FileOutputStream;
|
||||
import java.util.Iterator;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.ImageWriter;
|
||||
import javax.imageio.spi.IIORegistry;
|
||||
import javax.imageio.spi.ImageWriterSpi;
|
||||
import javax.imageio.stream.ImageOutputStream;
|
||||
|
||||
public class WriteNullImageTest {
|
||||
|
||||
public WriteNullImageTest() {
|
||||
boolean testFailed = false;
|
||||
String failMsg = "FAIL: IllegalArgumentException is not thrown by the " +
|
||||
"ImageWriter when the image passed to the write() method is " +
|
||||
"null, for the image formats: ";
|
||||
|
||||
try {
|
||||
IIORegistry reg = IIORegistry.getDefaultInstance();
|
||||
ImageWriter writer = null;
|
||||
Iterator writerSpiIter = reg.getServiceProviders(ImageWriterSpi.class, true);
|
||||
|
||||
while (writerSpiIter.hasNext()) {
|
||||
ImageWriterSpi writerSpi = (ImageWriterSpi) writerSpiIter.next();
|
||||
writer = writerSpi.createWriterInstance();
|
||||
String names[] = writerSpi.getFormatNames();
|
||||
|
||||
FileOutputStream fos = new FileOutputStream("temp");
|
||||
ImageOutputStream ios = ImageIO.createImageOutputStream(fos);
|
||||
writer.setOutput(ios);
|
||||
|
||||
try {
|
||||
writer.write(null, null, null);
|
||||
} catch (IllegalArgumentException iae) {
|
||||
System.out.println("PASS: Expected exception is thrown when null img is passed " +
|
||||
"to the write method, for the image format: " + names[0]);
|
||||
System.out.println("\n");
|
||||
} catch (Exception e) {
|
||||
testFailed = true;
|
||||
failMsg = failMsg + names[0] + ", ";
|
||||
}
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
testFailed = true;
|
||||
throw new RuntimeException("Test Failed. Exception thrown: " + e.toString());
|
||||
}
|
||||
if (testFailed) {
|
||||
failMsg = failMsg.substring(0, failMsg.lastIndexOf(","));
|
||||
throw new RuntimeException(failMsg);
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String args[]) {
|
||||
WriteNullImageTest test = new WriteNullImageTest();
|
||||
}
|
||||
}
|
154
jdk/test/javax/imageio/event/WriteProgressListenerTest.java
Normal file
154
jdk/test/javax/imageio/event/WriteProgressListenerTest.java
Normal file
@ -0,0 +1,154 @@
|
||||
/*
|
||||
* Copyright (c) 2001, 2017, 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 4420342 4421831
|
||||
* @summary Checks that IIOWriteProgressListener methods are called in proper
|
||||
* sequence for the JPEG and PNG writers
|
||||
*/
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Iterator;
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.ImageWriter;
|
||||
import javax.imageio.event.IIOWriteProgressListener;
|
||||
import javax.imageio.stream.ImageOutputStream;
|
||||
|
||||
public class WriteProgressListenerTest implements IIOWriteProgressListener {
|
||||
|
||||
final static int UNINITIALIZED = 0;
|
||||
final static int IMAGE_STARTED = 1;
|
||||
final static int IMAGE_COMPLETE = 2;
|
||||
|
||||
int state = UNINITIALIZED;
|
||||
float prevPercentageDone = 0.0F;
|
||||
File tempFile = null;
|
||||
|
||||
public WriteProgressListenerTest(String format) throws IOException {
|
||||
ImageWriter writer = null;
|
||||
Iterator witer = ImageIO.getImageWritersByFormatName(format);
|
||||
if (!witer.hasNext()) {
|
||||
error("No writer for format " + format + "!");
|
||||
}
|
||||
writer = (ImageWriter)witer.next();
|
||||
|
||||
System.out.println("Got writer " + writer);
|
||||
writer.addIIOWriteProgressListener(this);
|
||||
|
||||
this.tempFile = File.createTempFile("imageio", ".tmp");
|
||||
tempFile.deleteOnExit();
|
||||
ImageOutputStream stream = ImageIO.createImageOutputStream(tempFile);
|
||||
writer.setOutput(stream);
|
||||
|
||||
BufferedImage im =
|
||||
new BufferedImage(100, 100, BufferedImage.TYPE_3BYTE_BGR);
|
||||
|
||||
this.state = UNINITIALIZED;
|
||||
|
||||
writer.write(im);
|
||||
|
||||
if (this.state == UNINITIALIZED) {
|
||||
error("imageStarted never called!");
|
||||
}
|
||||
if (this.state != IMAGE_COMPLETE) {
|
||||
error("imageComplete not called!");
|
||||
}
|
||||
|
||||
print("Passed!");
|
||||
}
|
||||
|
||||
private void error(String s) {
|
||||
if (tempFile != null) {
|
||||
tempFile.delete();
|
||||
}
|
||||
throw new RuntimeException(s);
|
||||
}
|
||||
|
||||
private void print(String s) {
|
||||
System.out.println(s);
|
||||
}
|
||||
|
||||
public void sequenceStarted(ImageWriter source) {
|
||||
error("Obsolete method sequenceStarted was called!");
|
||||
}
|
||||
|
||||
public void sequenceComplete(ImageWriter source) {
|
||||
error("Obsolete method sequenceComplete was called!");
|
||||
}
|
||||
|
||||
public void imageStarted(ImageWriter source, int imageIndex) {
|
||||
print("imageStarted: imageIndex = " + imageIndex);
|
||||
|
||||
if (state != UNINITIALIZED) {
|
||||
error("imageStarted not called first!");
|
||||
}
|
||||
state = IMAGE_STARTED;
|
||||
prevPercentageDone = 0.0F;
|
||||
}
|
||||
|
||||
public void imageProgress(ImageWriter source,
|
||||
float percentageDone) {
|
||||
print("imageProgress: percentageDone = " + percentageDone);
|
||||
|
||||
if (state != IMAGE_STARTED) {
|
||||
error("imageProgress called without prior imageStarted!");
|
||||
}
|
||||
if (percentageDone < prevPercentageDone) {
|
||||
error("percentageDone did not increase!");
|
||||
}
|
||||
prevPercentageDone = percentageDone;
|
||||
}
|
||||
|
||||
public void imageComplete(ImageWriter source) {
|
||||
print("imageComplete");
|
||||
|
||||
if (state != IMAGE_STARTED) {
|
||||
error("imageComplete called without imageStarted!");
|
||||
}
|
||||
if (prevPercentageDone == 0.0F) {
|
||||
error("percentageDone was never updated!");
|
||||
}
|
||||
state = IMAGE_COMPLETE;
|
||||
}
|
||||
|
||||
public void thumbnailStarted(ImageWriter source,
|
||||
int imageIndex, int thumbnailIndex) {
|
||||
}
|
||||
|
||||
public void thumbnailProgress(ImageWriter source, float percentageDone) {
|
||||
}
|
||||
|
||||
public void thumbnailComplete(ImageWriter source) {
|
||||
}
|
||||
|
||||
public void writeAborted(ImageWriter source) {
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
new WriteProgressListenerTest("jpeg");
|
||||
new WriteProgressListenerTest("png");
|
||||
}
|
||||
}
|
433
jdk/test/javax/imageio/plugins/bmp/BMPCompressionTest.java
Normal file
433
jdk/test/javax/imageio/plugins/bmp/BMPCompressionTest.java
Normal file
@ -0,0 +1,433 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 2017, 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 4641872
|
||||
* @summary Tests writing compression modes of BMP plugin
|
||||
* @modules java.desktop/com.sun.imageio.plugins.bmp
|
||||
*/
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Transparency;
|
||||
import java.awt.color.ColorSpace;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.image.ColorModel;
|
||||
import java.awt.image.ComponentColorModel;
|
||||
import java.awt.image.DataBuffer;
|
||||
import java.awt.image.DirectColorModel;
|
||||
import java.awt.image.IndexColorModel;
|
||||
import java.awt.image.PixelInterleavedSampleModel;
|
||||
import java.awt.image.Raster;
|
||||
import java.awt.image.SampleModel;
|
||||
import java.awt.image.SinglePixelPackedSampleModel;
|
||||
import java.awt.image.WritableRaster;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.imageio.IIOImage;
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.ImageReader;
|
||||
import javax.imageio.ImageTypeSpecifier;
|
||||
import javax.imageio.ImageWriteParam;
|
||||
import javax.imageio.ImageWriter;
|
||||
import javax.imageio.metadata.IIOMetadata;
|
||||
import javax.imageio.plugins.bmp.BMPImageWriteParam;
|
||||
import javax.imageio.stream.ImageOutputStream;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JFrame;
|
||||
|
||||
import com.sun.imageio.plugins.bmp.BMPMetadata;
|
||||
|
||||
public class BMPCompressionTest {
|
||||
|
||||
static final String format = "BMP";
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
ImageWriter iw = null;
|
||||
Iterator writers = ImageIO.getImageWritersByFormatName(format);
|
||||
if (!writers.hasNext()) {
|
||||
throw new RuntimeException("No available Image writer for "+format);
|
||||
}
|
||||
iw = (ImageWriter)writers.next();
|
||||
|
||||
|
||||
Iterator tests = Test.createTestSet(iw);
|
||||
|
||||
while(tests.hasNext()) {
|
||||
|
||||
Test t = (Test)tests.next();
|
||||
System.out.println(t.getDescription());
|
||||
t.doTest();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
static class Test {
|
||||
static ImageWriter iw;
|
||||
private BufferedImage img;
|
||||
private String description;
|
||||
private BMPImageWriteParam param;
|
||||
private IIOMetadata meta;
|
||||
|
||||
|
||||
public static Iterator createTestSet(ImageWriter w) {
|
||||
List l = new LinkedList();
|
||||
|
||||
Test.iw = w;
|
||||
|
||||
// variate compression types
|
||||
BMPImageWriteParam param = (BMPImageWriteParam)iw.getDefaultWriteParam();
|
||||
param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
|
||||
param.setCompressionType("BI_RGB");
|
||||
if (param.canWriteCompressed()) {
|
||||
String[] cTypes = param.getCompressionTypes();
|
||||
String[] cDescr = param.getCompressionQualityDescriptions();
|
||||
float[] cValues = param.getCompressionQualityValues();
|
||||
|
||||
if (cDescr == null) {
|
||||
System.out.println("There are no compression quality description!");
|
||||
} else {
|
||||
for(int i=0; i<cDescr.length; i++) {
|
||||
System.out.println("Quality[" + i + "]=\""+cDescr[i]+"\"");
|
||||
}
|
||||
}
|
||||
if (cValues == null) {
|
||||
System.out.println("There are no compression quality values!");
|
||||
} else {
|
||||
for(int i=0; i<cValues.length; i++) {
|
||||
System.out.println("Value["+i+"]=\""+cValues[i]+"\"");
|
||||
}
|
||||
}
|
||||
|
||||
for(int i=0; i<cTypes.length; i++) {
|
||||
String compressionType = cTypes[i];
|
||||
BufferedImage img = null;
|
||||
|
||||
int type = BufferedImage.TYPE_INT_BGR;
|
||||
try {
|
||||
img = createTestImage(type);
|
||||
if (compressionType.equals("BI_RLE8")) {
|
||||
img = createTestImage2(8, DataBuffer.TYPE_BYTE);
|
||||
} else if (compressionType.equals("BI_RLE4")) {
|
||||
img = createTestImage3(4, DataBuffer.TYPE_BYTE);
|
||||
} else if (compressionType.equals("BI_BITFIELDS")) {
|
||||
img = createTestImage4(32);
|
||||
}
|
||||
|
||||
} catch (IOException ex) {
|
||||
throw new RuntimeException("Unable to create test image");
|
||||
}
|
||||
BMPImageWriteParam p = (BMPImageWriteParam)iw.getDefaultWriteParam();
|
||||
System.out.println("Current compression type is \""+cTypes[i]+"\"");
|
||||
p.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
|
||||
p.setCompressionType(compressionType);
|
||||
|
||||
IIOMetadata md = iw.getDefaultImageMetadata(new ImageTypeSpecifier(img), p);
|
||||
|
||||
l.add( new Test(p, md, img));
|
||||
}
|
||||
}
|
||||
// }
|
||||
return l.iterator();
|
||||
|
||||
}
|
||||
|
||||
private Test(BMPImageWriteParam p, IIOMetadata md, BufferedImage i) {
|
||||
param = p;
|
||||
meta = md;
|
||||
img = i;
|
||||
|
||||
|
||||
description = "Compression type is " + p.getCompressionType();
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void doTest() {
|
||||
try {
|
||||
System.out.println(this.getDescription());
|
||||
if (param.getCompressionMode() != ImageWriteParam.MODE_EXPLICIT) {
|
||||
System.out.println("Warning: compression mode is not MODE_EXPLICIT");
|
||||
}
|
||||
// change metadata according to ImageWriteParam
|
||||
IIOMetadata new_meta = iw.convertImageMetadata(meta, new ImageTypeSpecifier(img), param);
|
||||
|
||||
IIOImage iio_img = new IIOImage(img, null, new_meta);
|
||||
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
|
||||
iw.setOutput(ios);
|
||||
System.out.print("write image...");
|
||||
System.out.println("Current compression Type is \""+param.getCompressionType()+"\"");
|
||||
iw.write(new_meta, iio_img, param);
|
||||
//iw.write(iio_img);
|
||||
System.out.println("OK");
|
||||
System.out.print("read image ... ");
|
||||
ios.flush();
|
||||
|
||||
byte[] ba_image = baos.toByteArray();
|
||||
|
||||
System.out.println("Array length=" + ba_image.length);
|
||||
FileOutputStream fos = new FileOutputStream(new File(param.getCompressionType()+".bmp"));
|
||||
fos.write(ba_image);
|
||||
fos.flush();
|
||||
fos = null;
|
||||
ByteArrayInputStream bais = new ByteArrayInputStream(ba_image);
|
||||
|
||||
ImageReader ir = ImageIO.getImageReader(iw);
|
||||
ir.setInput(ImageIO.createImageInputStream(bais));
|
||||
|
||||
BufferedImage res = ir.read(0);
|
||||
System.out.println("OK");
|
||||
|
||||
if (!param.getCompressionType().equals("BI_JPEG")) {
|
||||
System.out.print("compare images ... ");
|
||||
boolean r = compare(img,res);
|
||||
System.out.println(r?"OK":"FAILED");
|
||||
if (!r) {
|
||||
throw new RuntimeException("Compared images are not equals. Test failed.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
BMPMetadata mdata = (BMPMetadata)ir.getImageMetadata(0);
|
||||
|
||||
if (!param.getCompressionType().equals(param.getCompressionTypes()[mdata.compression])) {
|
||||
throw new RuntimeException("Different compression value");
|
||||
}
|
||||
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
throw new RuntimeException("Unexpected exception: " + ex);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private boolean compare(final BufferedImage in, final BufferedImage out) {
|
||||
|
||||
final int width = in.getWidth();
|
||||
int height = in.getHeight();
|
||||
if (out.getWidth() != width || out.getHeight() != height) {
|
||||
throw new RuntimeException("Dimensions changed!");
|
||||
}
|
||||
|
||||
Raster oldras = in.getRaster();
|
||||
ColorModel oldcm = in.getColorModel();
|
||||
Raster newras = out.getRaster();
|
||||
ColorModel newcm = out.getColorModel();
|
||||
|
||||
for (int j = 0; j < height; j++) {
|
||||
for (int i = 0; i < width; i++) {
|
||||
Object oldpixel = oldras.getDataElements(i, j, null);
|
||||
int oldrgb = oldcm.getRGB(oldpixel);
|
||||
int oldalpha = oldcm.getAlpha(oldpixel);
|
||||
|
||||
Object newpixel = newras.getDataElements(i, j, null);
|
||||
int newrgb = newcm.getRGB(newpixel);
|
||||
int newalpha = newcm.getAlpha(newpixel);
|
||||
|
||||
if (newrgb != oldrgb ||
|
||||
newalpha != oldalpha) {
|
||||
// showDiff(in, out);
|
||||
throw new RuntimeException("Pixels differ at " + i +
|
||||
", " + j + " new = " + Integer.toHexString(newrgb) + " old = " + Integer.toHexString(oldrgb));
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private static BufferedImage createTestImage2(int nbits, int transfertype) {
|
||||
final int colorShift = 2;
|
||||
int SIZE = 256;
|
||||
BufferedImage image = null;
|
||||
|
||||
ColorSpace colorSpace =
|
||||
ColorSpace.getInstance(ColorSpace.CS_GRAY);
|
||||
ColorModel colorModel =
|
||||
new ComponentColorModel(colorSpace,
|
||||
new int[] {nbits},
|
||||
false,
|
||||
false,
|
||||
Transparency.OPAQUE,
|
||||
transfertype);
|
||||
|
||||
SampleModel sampleModel =
|
||||
new PixelInterleavedSampleModel(transfertype,
|
||||
SIZE,
|
||||
SIZE,
|
||||
1,
|
||||
SIZE,
|
||||
new int[] {0});
|
||||
|
||||
image =
|
||||
new BufferedImage(colorModel,
|
||||
Raster.createWritableRaster(sampleModel, null),
|
||||
false, null);
|
||||
WritableRaster raster = image.getWritableTile(0, 0);
|
||||
int[] samples = raster.getSamples(0, 0, SIZE, SIZE, 0, (int[])null);
|
||||
int off = 0;
|
||||
int[] row = new int[SIZE];
|
||||
for(int i = 0; i < SIZE; i++) {
|
||||
Arrays.fill(row, i << colorShift);
|
||||
System.arraycopy(row, 0, samples, off, SIZE);
|
||||
off += SIZE;
|
||||
}
|
||||
raster.setSamples(0, 0, SIZE, SIZE, 0, samples);
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
|
||||
private static BufferedImage createTestImage3(int nbits, int transfertype) {
|
||||
final int colorShift = 2;
|
||||
int SIZE = 256;
|
||||
BufferedImage image = null;
|
||||
|
||||
ColorSpace colorSpace =
|
||||
ColorSpace.getInstance(ColorSpace.CS_sRGB);
|
||||
ColorModel colorModel =
|
||||
new IndexColorModel(nbits,
|
||||
4,
|
||||
new byte[] { (byte)255, 0, 0, (byte)255},
|
||||
new byte[] { 0, (byte)255, 0, (byte)255},
|
||||
new byte[] { 0, 0, (byte)255, (byte)255});
|
||||
|
||||
SampleModel sampleModel =
|
||||
new PixelInterleavedSampleModel(transfertype,
|
||||
SIZE,
|
||||
SIZE,
|
||||
1,
|
||||
SIZE,
|
||||
new int[] {0});
|
||||
|
||||
image =
|
||||
new BufferedImage(colorModel,
|
||||
Raster.createWritableRaster(sampleModel, null),
|
||||
|
||||
false, null);
|
||||
|
||||
Graphics2D g = image.createGraphics();
|
||||
g.setColor(Color.white);
|
||||
g.fillRect(0,0, SIZE, SIZE);
|
||||
g.setColor(Color.red);
|
||||
g.fillOval(10, 10, SIZE -20, SIZE-20);
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
private static BufferedImage createTestImage4(int nbits) {
|
||||
int SIZE = 10;
|
||||
|
||||
|
||||
BufferedImage image = null;
|
||||
|
||||
ColorSpace colorSpace =
|
||||
ColorSpace.getInstance(ColorSpace.CS_sRGB);
|
||||
ColorModel colorModel =
|
||||
new DirectColorModel(colorSpace,
|
||||
nbits, 0xff0000, 0x00ff00, 0x0000ff, 0x000000, false, DataBuffer.TYPE_INT);
|
||||
|
||||
SampleModel sampleModel =
|
||||
new SinglePixelPackedSampleModel(DataBuffer.TYPE_INT,
|
||||
SIZE,
|
||||
SIZE,
|
||||
new int[] { 0xff0000, 0x00ff00, 0x0000ff} );
|
||||
|
||||
|
||||
image =
|
||||
new BufferedImage(colorModel,
|
||||
Raster.createWritableRaster(sampleModel, null),
|
||||
|
||||
false, null);
|
||||
|
||||
Graphics2D g = image.createGraphics();
|
||||
g.setColor(Color.red);
|
||||
g.fillRect(0,0, SIZE, SIZE);
|
||||
g.setColor(Color.green);
|
||||
//g.fillOval(10, 10, SIZE -20, SIZE-20);
|
||||
g.drawLine(7, 0, 7, SIZE);
|
||||
g.setColor(Color.blue);
|
||||
g.drawLine(1, 0, 1, SIZE);
|
||||
g.setColor(Color.white);
|
||||
g.drawLine(3, 0, 3, SIZE);
|
||||
g.setColor(Color.yellow);
|
||||
g.drawLine(5, 0, 5, SIZE);
|
||||
return image;
|
||||
}
|
||||
|
||||
private static BufferedImage createTestImage(int type)
|
||||
throws IOException {
|
||||
|
||||
int w = 200;
|
||||
int h = 200;
|
||||
BufferedImage b = new BufferedImage(w, h, type);
|
||||
Graphics2D g = b.createGraphics();
|
||||
g.setColor(Color.white);
|
||||
g.fillRect(0,0, w, h);
|
||||
g.setColor(Color.black);
|
||||
g.fillOval(10, 10, w -20, h-20);
|
||||
|
||||
return b;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private static void showDiff(final BufferedImage in,
|
||||
final BufferedImage out) {
|
||||
final int width = in.getWidth();
|
||||
final int height = in.getHeight();
|
||||
|
||||
JFrame f = new JFrame("");
|
||||
f.getContentPane().add( new JComponent() {
|
||||
public Dimension getPreferredSize() {
|
||||
return new Dimension(2*width+2, height);
|
||||
}
|
||||
public void paintComponent(Graphics g) {
|
||||
g.setColor(Color.black);
|
||||
g.drawImage(in, 0,0, null);
|
||||
|
||||
g.drawImage(out, width+2, 0, null);
|
||||
}
|
||||
});
|
||||
f.pack();
|
||||
f.setVisible(true);
|
||||
}
|
||||
|
||||
}
|
241
jdk/test/javax/imageio/plugins/bmp/BMPPluginTest.java
Normal file
241
jdk/test/javax/imageio/plugins/bmp/BMPPluginTest.java
Normal file
@ -0,0 +1,241 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 2017, 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 4641872 4892194
|
||||
* @summary Tests writing and reading abilities of BMP plugin
|
||||
*/
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.image.ColorModel;
|
||||
import java.awt.image.Raster;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Iterator;
|
||||
|
||||
import javax.imageio.IIOException;
|
||||
import javax.imageio.IIOImage;
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.ImageReader;
|
||||
import javax.imageio.ImageTypeSpecifier;
|
||||
import javax.imageio.ImageWriteParam;
|
||||
import javax.imageio.ImageWriter;
|
||||
import javax.imageio.metadata.IIOMetadata;
|
||||
import javax.imageio.spi.ImageWriterSpi;
|
||||
|
||||
public class BMPPluginTest {
|
||||
|
||||
private static final int[] types = {
|
||||
BufferedImage.TYPE_INT_RGB, // = 1;
|
||||
BufferedImage.TYPE_INT_ARGB, // = 2;
|
||||
BufferedImage.TYPE_INT_ARGB_PRE, // = 3;
|
||||
BufferedImage.TYPE_INT_BGR, // = 4;
|
||||
BufferedImage.TYPE_3BYTE_BGR, // = 5;
|
||||
BufferedImage.TYPE_4BYTE_ABGR, // = 6;
|
||||
BufferedImage.TYPE_4BYTE_ABGR_PRE, // 7
|
||||
BufferedImage.TYPE_USHORT_565_RGB, // 8
|
||||
BufferedImage.TYPE_USHORT_555_RGB, // 9
|
||||
BufferedImage.TYPE_BYTE_GRAY, // 10
|
||||
BufferedImage.TYPE_USHORT_GRAY, //11
|
||||
BufferedImage.TYPE_BYTE_BINARY, //12
|
||||
BufferedImage.TYPE_BYTE_INDEXED //13
|
||||
};
|
||||
|
||||
private static String format = "BMP";
|
||||
|
||||
private static ImageReader ir = null;
|
||||
private static ImageWriter iw = null;
|
||||
private BufferedImage img;
|
||||
private ImageWriteParam param;
|
||||
private ByteArrayOutputStream baos;
|
||||
|
||||
private static void init() {
|
||||
|
||||
Iterator i = ImageIO.getImageWritersByFormatName(format);
|
||||
if (!i.hasNext()) {
|
||||
throw new RuntimeException("No available ImageWrites for "+format+" format!");
|
||||
}
|
||||
iw = (ImageWriter)i.next();
|
||||
|
||||
i = ImageIO.getImageReadersByFormatName(format);
|
||||
if (!i.hasNext()) {
|
||||
throw new RuntimeException("No available ImageReaders for " +format+" format!");
|
||||
}
|
||||
|
||||
ir = (ImageReader)i.next();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
if (args.length > 0) {
|
||||
format = args[0];
|
||||
System.out.println("Test format " + format);
|
||||
}
|
||||
|
||||
init();
|
||||
System.out.println("IR="+ir);
|
||||
System.out.println("IW="+iw);
|
||||
ImageIO.setUseCache(false);
|
||||
|
||||
for (int i=0; i<types.length; i++) {
|
||||
boolean bPassed = true;
|
||||
Object reason = null;
|
||||
|
||||
try {
|
||||
|
||||
BufferedImage image = createTestImage(types[i]);
|
||||
|
||||
ImageWriteParam param = iw.getDefaultWriteParam();
|
||||
|
||||
BMPPluginTest t = new BMPPluginTest(image, param);
|
||||
boolean res = false;
|
||||
res = t.test();
|
||||
if (!res) {
|
||||
bPassed = false;
|
||||
reason = new String("Null result");
|
||||
}
|
||||
} catch (IllegalArgumentException ex) {
|
||||
System.out.println("Expected exception type was caught: " + ex);
|
||||
|
||||
} catch (Throwable ex ) {
|
||||
System.out.println("FAILED");
|
||||
ex.printStackTrace();
|
||||
bPassed = false;
|
||||
reason = ex;
|
||||
throw new RuntimeException("Test for type " + types[i] + " FAILED due to exception");
|
||||
}
|
||||
/*
|
||||
System.out.println("Type " + types[i] + " result: " +
|
||||
(bPassed ? "PASSED" : "FAILED") +
|
||||
((reason != null) ? (" Reason: " + reason) : ""));
|
||||
*/
|
||||
System.out.println("Test for type " + types[i] + " PASSED");
|
||||
}
|
||||
|
||||
System.out.println("END OF TEST");
|
||||
}
|
||||
|
||||
public BMPPluginTest(BufferedImage img, ImageWriteParam param) {
|
||||
|
||||
this.img = img;
|
||||
this.param = param;
|
||||
baos = new ByteArrayOutputStream();
|
||||
}
|
||||
|
||||
public boolean test() throws IIOException, IOException {
|
||||
|
||||
ir.reset();
|
||||
iw.reset();
|
||||
|
||||
String[] suffixes = iw.getOriginatingProvider().getFileSuffixes();
|
||||
|
||||
IIOMetadata md = iw.getDefaultImageMetadata(new ImageTypeSpecifier(img), param);
|
||||
|
||||
System.out.println("Image type " + img.getType());
|
||||
|
||||
ImageWriterSpi spi = iw.getOriginatingProvider();
|
||||
boolean bCanEncode = spi.canEncodeImage(img);
|
||||
|
||||
System.out.println("Can encode image? " + (bCanEncode ? "YES" : "NO"));
|
||||
if (!bCanEncode) {
|
||||
return true;
|
||||
}
|
||||
IIOImage iio_img = new IIOImage(img, null, md);
|
||||
|
||||
String fname = "test"+img.getType()+"."+suffixes[0];
|
||||
|
||||
iw.setOutput(ImageIO.createImageOutputStream(new FileOutputStream(new File(fname))));
|
||||
System.out.print("write image ... ");
|
||||
iw.write(iio_img);
|
||||
System.out.println("OK");
|
||||
System.out.print("read image ... ");
|
||||
|
||||
byte[] ba_image = baos.toByteArray();
|
||||
|
||||
ByteArrayInputStream bais = new ByteArrayInputStream(ba_image);
|
||||
|
||||
ir.setInput(ImageIO.createImageInputStream(new FileInputStream(new File(fname))));
|
||||
|
||||
BufferedImage res = ir.read(0);
|
||||
System.out.println("OK");
|
||||
|
||||
System.out.print("compare images ... ");
|
||||
boolean r = compare(img,res);
|
||||
System.out.println(r?"OK":"FAILED");
|
||||
return r;
|
||||
}
|
||||
|
||||
private boolean compare(BufferedImage in, BufferedImage out) {
|
||||
int width = in.getWidth();
|
||||
int height = in.getHeight();
|
||||
if (out.getWidth() != width || out.getHeight() != height) {
|
||||
throw new RuntimeException("Dimensions changed!");
|
||||
}
|
||||
|
||||
Raster oldras = in.getRaster();
|
||||
ColorModel oldcm = in.getColorModel();
|
||||
Raster newras = out.getRaster();
|
||||
ColorModel newcm = out.getColorModel();
|
||||
|
||||
for (int j = 0; j < height; j++) {
|
||||
for (int i = 0; i < width; i++) {
|
||||
Object oldpixel = oldras.getDataElements(i, j, null);
|
||||
int oldrgb = oldcm.getRGB(oldpixel);
|
||||
int oldalpha = oldcm.getAlpha(oldpixel);
|
||||
|
||||
Object newpixel = newras.getDataElements(i, j, null);
|
||||
int newrgb = newcm.getRGB(newpixel);
|
||||
int newalpha = newcm.getAlpha(newpixel);
|
||||
|
||||
if (newrgb != oldrgb ||
|
||||
newalpha != oldalpha) {
|
||||
throw new RuntimeException("Pixels differ at " + i +
|
||||
", " + j);
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
private static BufferedImage createTestImage(int type) throws IOException {
|
||||
|
||||
int w = 200;
|
||||
int h = 200;
|
||||
BufferedImage b = new BufferedImage(w, h, type);
|
||||
Graphics2D g = b.createGraphics();
|
||||
g.setColor(Color.white);
|
||||
g.fillRect(0,0, w, h);
|
||||
g.setColor(Color.black);
|
||||
g.fillOval(10, 10, w -20, h-20);
|
||||
|
||||
return b;
|
||||
}
|
||||
|
||||
}
|
175
jdk/test/javax/imageio/plugins/bmp/BMPWriteParamTest.java
Normal file
175
jdk/test/javax/imageio/plugins/bmp/BMPWriteParamTest.java
Normal file
@ -0,0 +1,175 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 2017, 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 4641872
|
||||
* @summary Tests writing compression modes of BMP plugin
|
||||
*/
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.image.ColorModel;
|
||||
import java.awt.image.Raster;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Iterator;
|
||||
|
||||
import javax.imageio.IIOImage;
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.ImageReader;
|
||||
import javax.imageio.ImageTypeSpecifier;
|
||||
import javax.imageio.ImageWriteParam;
|
||||
import javax.imageio.ImageWriter;
|
||||
import javax.imageio.metadata.IIOMetadata;
|
||||
import javax.imageio.stream.ImageOutputStream;
|
||||
|
||||
public class BMPWriteParamTest {
|
||||
|
||||
static final String format = "BMP";
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
ImageWriter iw = null;
|
||||
Iterator writers = ImageIO.getImageWritersByFormatName(format);
|
||||
if (!writers.hasNext()) {
|
||||
throw new RuntimeException("No available Image writer for "+format);
|
||||
}
|
||||
iw = (ImageWriter)writers.next();
|
||||
|
||||
try {
|
||||
BufferedImage img = createTestImage();
|
||||
|
||||
BufferedImage bmp_res = getWriteResult(img, "BMP");
|
||||
BufferedImage png_res = getWriteResult(img, "PNG");
|
||||
|
||||
compare(bmp_res, png_res);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
throw new RuntimeException("Unexpected exception: " + ex);
|
||||
}
|
||||
}
|
||||
|
||||
private static BufferedImage getWriteResult(BufferedImage img,
|
||||
String format
|
||||
) throws IOException {
|
||||
ImageWriter iw = null;
|
||||
Iterator writers = ImageIO.getImageWritersByFormatName(format);
|
||||
while (writers.hasNext()) {
|
||||
iw = (ImageWriter)writers.next();
|
||||
System.out.println(format + " -> " + iw.toString());
|
||||
}
|
||||
if (iw==null) {
|
||||
throw new RuntimeException("No available Image writer for "+format);
|
||||
}
|
||||
ImageWriteParam param = iw.getDefaultWriteParam();
|
||||
|
||||
param.setSourceRegion(new Rectangle(10, 10, 31, 31));
|
||||
param.setSourceSubsampling(3, 3, 0, 0);
|
||||
|
||||
IIOMetadata meta = iw.getDefaultImageMetadata(new ImageTypeSpecifier(img), param);
|
||||
|
||||
IIOImage iio_img = new IIOImage(img, null, meta);
|
||||
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
|
||||
iw.setOutput(ios);
|
||||
iw.write(meta, iio_img, param);
|
||||
ios.flush();
|
||||
|
||||
byte[] ba_image = baos.toByteArray();
|
||||
|
||||
ByteArrayInputStream bais = new ByteArrayInputStream(ba_image);
|
||||
|
||||
ImageReader ir = null;
|
||||
|
||||
Iterator readers = ImageIO.getImageReadersByFormatName(format);
|
||||
while (readers.hasNext()) {
|
||||
ir = (ImageReader)readers.next();
|
||||
System.out.println(format + " -> " + ir.toString());
|
||||
}
|
||||
if (ir==null) {
|
||||
throw new RuntimeException("No available Image reader for "+format);
|
||||
}
|
||||
|
||||
ir.setInput(ImageIO.createImageInputStream(bais));
|
||||
|
||||
BufferedImage res = ir.read(0);
|
||||
return res;
|
||||
}
|
||||
|
||||
private static BufferedImage createTestImage()
|
||||
throws IOException {
|
||||
|
||||
int w = 50;
|
||||
int h = 50;
|
||||
BufferedImage b = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
|
||||
Graphics2D g = b.createGraphics();
|
||||
g.setColor(Color.red);
|
||||
g.fillRect(0,0, w, h);
|
||||
g.setColor(Color.white);
|
||||
for (int i=10; i<=10+30; i+= 3) {
|
||||
g.drawLine(i, 10, i, 40);
|
||||
g.drawLine(10, i, 40, i);
|
||||
}
|
||||
return b;
|
||||
}
|
||||
|
||||
private static boolean compare(final BufferedImage in,
|
||||
final BufferedImage out)
|
||||
{
|
||||
final int width = in.getWidth();
|
||||
int height = in.getHeight();
|
||||
if (out.getWidth() != width || out.getHeight() != height) {
|
||||
throw new RuntimeException("Dimensions changed!");
|
||||
}
|
||||
|
||||
Raster oldras = in.getRaster();
|
||||
ColorModel oldcm = in.getColorModel();
|
||||
Raster newras = out.getRaster();
|
||||
ColorModel newcm = out.getColorModel();
|
||||
|
||||
for (int j = 0; j < height; j++) {
|
||||
for (int i = 0; i < width; i++) {
|
||||
Object oldpixel = oldras.getDataElements(i, j, null);
|
||||
int oldrgb = oldcm.getRGB(oldpixel);
|
||||
int oldalpha = oldcm.getAlpha(oldpixel);
|
||||
|
||||
Object newpixel = newras.getDataElements(i, j, null);
|
||||
int newrgb = newcm.getRGB(newpixel);
|
||||
int newalpha = newcm.getAlpha(newpixel);
|
||||
|
||||
if (newrgb != oldrgb ||
|
||||
newalpha != oldalpha) {
|
||||
// showDiff(in, out);
|
||||
throw new RuntimeException("Pixels differ at " + i +
|
||||
", " + j + " new = " + Integer.toHexString(newrgb) + " old = " + Integer.toHexString(oldrgb));
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
106
jdk/test/javax/imageio/plugins/bmp/BmpBigDestinationTest.java
Normal file
106
jdk/test/javax/imageio/plugins/bmp/BmpBigDestinationTest.java
Normal file
@ -0,0 +1,106 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 2017, 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 4929367
|
||||
* @summary tests what BMP image was decoded correctly if destination buffered
|
||||
* image is bigger than source image
|
||||
*/
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Iterator;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.ImageReadParam;
|
||||
import javax.imageio.ImageReader;
|
||||
import javax.imageio.ImageTypeSpecifier;
|
||||
import javax.imageio.ImageWriter;
|
||||
|
||||
public class BmpBigDestinationTest {
|
||||
static String format = "BMP";
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
BufferedImage src = new BufferedImage(100, 100,
|
||||
BufferedImage.TYPE_INT_RGB);
|
||||
Graphics2D g = src.createGraphics();
|
||||
g.setColor(Color.red);
|
||||
g.fillRect(0,0,100, 100);
|
||||
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
|
||||
ImageWriter iw =
|
||||
(ImageWriter)ImageIO.getImageWritersByFormatName(format).next();
|
||||
if (iw == null) {
|
||||
throw new RuntimeException("No writer available. Test failed.");
|
||||
}
|
||||
|
||||
iw.setOutput(ImageIO.createImageOutputStream(baos));
|
||||
iw.write(src);
|
||||
|
||||
byte[] data = baos.toByteArray();
|
||||
|
||||
ImageReader ir =
|
||||
(ImageReader)ImageIO.getImageReadersByFormatName(format).next();
|
||||
ir.setInput(
|
||||
ImageIO.createImageInputStream(
|
||||
new ByteArrayInputStream(data)));
|
||||
|
||||
Iterator specifiers = ir.getImageTypes(0);
|
||||
ImageTypeSpecifier typeSpecifier = null;
|
||||
|
||||
if (specifiers.hasNext()) {
|
||||
typeSpecifier = (ImageTypeSpecifier) specifiers.next();
|
||||
}
|
||||
ImageReadParam param = new ImageReadParam();
|
||||
BufferedImage dst = typeSpecifier.createBufferedImage(200, 200);
|
||||
param.setDestination(dst);
|
||||
|
||||
ir.read(0, param);
|
||||
|
||||
checkResults(src,dst);
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException("Unexpected exception. Test failed.");
|
||||
}
|
||||
}
|
||||
|
||||
private static void checkResults(BufferedImage src, BufferedImage dst) {
|
||||
for(int x=0; x<src.getWidth(); x++) {
|
||||
for(int y=0; y<src.getHeight(); y++) {
|
||||
int srcRgb = src.getRGB(x,y);
|
||||
int dstRgb = dst.getRGB(x,y);
|
||||
if (srcRgb != dstRgb) {
|
||||
throw new RuntimeException("Images are different at point ["
|
||||
+ x + "," + y + "]");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,151 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 2017, 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 4895512
|
||||
* @summary Test that default image metadata for BMP image writer is not null
|
||||
*/
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.Iterator;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.ImageTypeSpecifier;
|
||||
import javax.imageio.ImageWriteParam;
|
||||
import javax.imageio.ImageWriter;
|
||||
import javax.imageio.metadata.IIOMetadata;
|
||||
|
||||
import org.w3c.dom.NamedNodeMap;
|
||||
import org.w3c.dom.Node;
|
||||
|
||||
public class BmpDefaultImageMetadataTest {
|
||||
ImageWriter writer = null;
|
||||
IIOMetadata imageData = null;
|
||||
ImageWriteParam writeParam = null;
|
||||
BufferedImage bimg = null;
|
||||
|
||||
public BmpDefaultImageMetadataTest(String format) {
|
||||
try {
|
||||
bimg = new BufferedImage(200, 200, bimg.TYPE_INT_RGB);
|
||||
Graphics gg = bimg.getGraphics();
|
||||
gg.setColor(Color.red);
|
||||
gg.fillRect(50, 50, 100, 100);
|
||||
|
||||
Iterator it = ImageIO.getImageWritersByFormatName(format);
|
||||
if (it.hasNext()) {
|
||||
writer = (ImageWriter) it.next();
|
||||
}
|
||||
if (writer == null) {
|
||||
throw new RuntimeException("No writer available for the given format."
|
||||
+ " Test failed.");
|
||||
}
|
||||
writeParam = writer.getDefaultWriteParam();
|
||||
|
||||
System.out.println("Testing Image Metadata for "+format+"\n");
|
||||
imageData = writer.getDefaultImageMetadata(new ImageTypeSpecifier(bimg), writeParam);
|
||||
if (imageData == null) {
|
||||
System.out.println("return value is null. No default image metadata is associated with "+format+" writer");
|
||||
throw new RuntimeException("Default image metadata is null."
|
||||
+ " Test failed.");
|
||||
}
|
||||
int j = 0;
|
||||
String imageDataNames[] = null;
|
||||
if(imageData != null) {
|
||||
System.out.println("Is standard metadata format supported (Image) ? "+
|
||||
imageData.isStandardMetadataFormatSupported() );
|
||||
imageDataNames = imageData.getMetadataFormatNames();
|
||||
System.out.println("\nAll supported Metadata Format Names\n");
|
||||
if(imageDataNames!=null){
|
||||
for(j=0; j<imageDataNames.length; j++) {
|
||||
System.out.println("FORMAT NAME: "+imageDataNames[j]);
|
||||
if (imageDataNames[j].equals(imageData.getNativeMetadataFormatName())) {
|
||||
System.out.println("This is a Native Metadata format\n");
|
||||
} else {
|
||||
System.out.println("\n");
|
||||
}
|
||||
System.out.println("");
|
||||
System.out.println("IIOImageMetadata DOM tree for "+imageDataNames[j]);
|
||||
System.out.println("");
|
||||
Node imageNode = imageData.getAsTree(imageDataNames[j]);
|
||||
displayMetadata(imageNode);
|
||||
System.out.println("\n\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
}catch(Exception e){
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException("Exception was thrown."
|
||||
+ " Test failed.");
|
||||
}
|
||||
}
|
||||
|
||||
public void displayMetadata(Node root) {
|
||||
displayMetadata(root, 0);
|
||||
}
|
||||
|
||||
void indent(int level) {
|
||||
for (int i = 0; i < level; i++) {
|
||||
System.out.print(" ");
|
||||
}
|
||||
}
|
||||
|
||||
void displayMetadata(Node node, int level) {
|
||||
indent(level); // emit open tag
|
||||
System.out.print("<" + node.getNodeName());
|
||||
NamedNodeMap map = node.getAttributes();
|
||||
if (map != null) { // print attribute values
|
||||
int length = map.getLength();
|
||||
for (int i = 0; i < length; i++) {
|
||||
Node attr = map.item(i);
|
||||
System.out.print(" " + attr.getNodeName() +
|
||||
"=\"" + attr.getNodeValue() + "\"");
|
||||
}
|
||||
}
|
||||
Node child = node.getFirstChild();
|
||||
|
||||
if (node.getNodeValue() != null && !node.getNodeValue().equals("") ) {
|
||||
System.out.println(">");
|
||||
indent(level);
|
||||
System.out.println(node.getNodeValue());
|
||||
indent(level); // emit close tag
|
||||
System.out.println("</" + node.getNodeName() + ">");
|
||||
} else if (child != null) {
|
||||
System.out.println(">"); // close current tag
|
||||
while (child != null) { // emit child tags recursively
|
||||
displayMetadata(child, level + 1);
|
||||
child = child.getNextSibling();
|
||||
}
|
||||
indent(level); // emit close tag
|
||||
System.out.println("</" + node.getNodeName() + ">");
|
||||
} else {
|
||||
System.out.println("/>");
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String args[]) {
|
||||
BmpDefaultImageMetadataTest test = new BmpDefaultImageMetadataTest("bmp");
|
||||
}
|
||||
}
|
96
jdk/test/javax/imageio/plugins/bmp/CompressionModeTest.java
Normal file
96
jdk/test/javax/imageio/plugins/bmp/CompressionModeTest.java
Normal file
@ -0,0 +1,96 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 2017, 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 4893464
|
||||
* @summary Tests bmp writer behavior with different compression modes
|
||||
*/
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
|
||||
import javax.imageio.IIOImage;
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.ImageTypeSpecifier;
|
||||
import javax.imageio.ImageWriteParam;
|
||||
import javax.imageio.ImageWriter;
|
||||
import javax.imageio.metadata.IIOMetadata;
|
||||
import javax.imageio.stream.ImageOutputStream;
|
||||
|
||||
public class CompressionModeTest {
|
||||
|
||||
public static void main(String args[]) {
|
||||
int[] iModes = { ImageWriteParam.MODE_DISABLED,
|
||||
ImageWriteParam.MODE_EXPLICIT,
|
||||
ImageWriteParam.MODE_COPY_FROM_METADATA,
|
||||
ImageWriteParam.MODE_DEFAULT };
|
||||
|
||||
String[] strModes = { "ImageWriteParam.MODE_DISABLED",
|
||||
"ImageWriteParam.MODE_EXPLICIT",
|
||||
"ImageWriteParam.MODE_COPY_FROM_METADATA",
|
||||
"ImageWriteParam.MODE_DEFAULT" };
|
||||
|
||||
for(int i=0; i<iModes.length; i++) {
|
||||
System.out.println("Test compression mode "+strModes[i]);
|
||||
doTest(iModes[i]);
|
||||
}
|
||||
}
|
||||
|
||||
private static void doTest(int mode) {
|
||||
String fileFormat = "bmp";
|
||||
try {
|
||||
ImageWriter iw = (ImageWriter)ImageIO.getImageWritersBySuffix(fileFormat).next();
|
||||
if(iw == null) {
|
||||
throw new RuntimeException("No available image writer for "
|
||||
+ fileFormat
|
||||
+ " Test failed.");
|
||||
}
|
||||
|
||||
File file = new File("image." + fileFormat);
|
||||
ImageOutputStream ios = ImageIO.createImageOutputStream(file);
|
||||
iw.setOutput(ios);
|
||||
|
||||
BufferedImage bimg = new BufferedImage(100,
|
||||
100, BufferedImage.TYPE_INT_RGB);
|
||||
Graphics g = bimg.getGraphics();
|
||||
g.setColor(Color.green);
|
||||
g.fillRect(0,0,100,100);
|
||||
|
||||
ImageWriteParam param = iw.getDefaultWriteParam();
|
||||
|
||||
param.setCompressionMode(mode);
|
||||
|
||||
IIOMetadata meta = iw.getDefaultImageMetadata(new ImageTypeSpecifier(bimg),
|
||||
param);
|
||||
|
||||
IIOImage iioImg = new IIOImage(bimg, null, meta);
|
||||
iw.write(null, iioImg, param);
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException("Test failed.");
|
||||
}
|
||||
}
|
||||
}
|
147
jdk/test/javax/imageio/plugins/bmp/EmbeddedFormatTest.java
Normal file
147
jdk/test/javax/imageio/plugins/bmp/EmbeddedFormatTest.java
Normal file
@ -0,0 +1,147 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2017, 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 6294920 6294926
|
||||
* @summary Test verifies that BMP images with compression types BI_JPEG and
|
||||
* BI_PNG are read correctly in case of 1, 8, 16, 24 and 32 bpp
|
||||
*/
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.imageio.IIOImage;
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.ImageReader;
|
||||
import javax.imageio.ImageWriteParam;
|
||||
import javax.imageio.ImageWriter;
|
||||
import javax.imageio.stream.ImageInputStream;
|
||||
import javax.imageio.stream.ImageOutputStream;
|
||||
|
||||
public class EmbeddedFormatTest {
|
||||
ImageWriter writer;
|
||||
ImageReader reader;
|
||||
|
||||
static int[] bi_types = {
|
||||
BufferedImage.TYPE_INT_RGB,
|
||||
BufferedImage.TYPE_3BYTE_BGR,
|
||||
BufferedImage.TYPE_USHORT_555_RGB,
|
||||
BufferedImage.TYPE_BYTE_GRAY,
|
||||
BufferedImage.TYPE_BYTE_BINARY
|
||||
};
|
||||
|
||||
public EmbeddedFormatTest() {
|
||||
writer = ImageIO.getImageWritersByFormatName("BMP").next();
|
||||
reader = ImageIO.getImageReadersByFormatName("BMP").next();
|
||||
}
|
||||
|
||||
public void doTest(String compression, int bi_type) throws IOException {
|
||||
System.out.println("Test " + compression + " on " + getImageTypeName(bi_type));
|
||||
BufferedImage src = createTestImage(bi_type);
|
||||
writer.reset();
|
||||
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
ImageOutputStream ios =
|
||||
ImageIO.createImageOutputStream(baos);
|
||||
writer.setOutput(ios);
|
||||
|
||||
ImageWriteParam wparam = prepareWriteParam(compression);
|
||||
writer.write(null, new IIOImage(src, null, null), wparam);
|
||||
ios.flush();
|
||||
ios.close();
|
||||
|
||||
// read result
|
||||
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
|
||||
ImageInputStream iis = ImageIO.createImageInputStream(bais);
|
||||
reader.reset();
|
||||
reader.setInput(iis);
|
||||
|
||||
BufferedImage dst = reader.read(0);
|
||||
|
||||
checkResult(dst);
|
||||
}
|
||||
|
||||
protected BufferedImage createTestImage(int type) {
|
||||
BufferedImage img = new BufferedImage(200, 200, type);
|
||||
Graphics g = img.createGraphics();
|
||||
g.setColor(Color.black);
|
||||
g.fillRect(0, 0, 200, 200);
|
||||
g.setColor(Color.white);
|
||||
g.fillRect(50, 50, 100, 100);
|
||||
|
||||
return img;
|
||||
}
|
||||
|
||||
protected void checkResult(BufferedImage img) {
|
||||
int imgBlack = img.getRGB(25, 25);
|
||||
if (imgBlack != 0xff000000) {
|
||||
throw new RuntimeException("Wrong black color: " +
|
||||
Integer.toHexString(imgBlack));
|
||||
}
|
||||
|
||||
int imgWhite = img.getRGB(100, 100);
|
||||
if (imgWhite != 0xffffffff) {
|
||||
throw new RuntimeException("Wrong white color: " +
|
||||
Integer.toHexString(imgWhite));
|
||||
}
|
||||
}
|
||||
|
||||
protected ImageWriteParam prepareWriteParam(String compression) {
|
||||
ImageWriteParam imageWriteParam = writer.getDefaultWriteParam();
|
||||
imageWriteParam.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
|
||||
imageWriteParam.setCompressionType(compression);
|
||||
return imageWriteParam;
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
EmbeddedFormatTest t = new EmbeddedFormatTest();
|
||||
|
||||
for (int i = 0; i < bi_types.length; i++) {
|
||||
t.doTest("BI_JPEG", bi_types[i]);
|
||||
t.doTest("BI_PNG", bi_types[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static String getImageTypeName(int type) {
|
||||
switch(type) {
|
||||
case BufferedImage.TYPE_INT_RGB:
|
||||
return "TYPE_INT_RGB";
|
||||
case BufferedImage.TYPE_3BYTE_BGR:
|
||||
return "TYPE_3BYTE_BGR";
|
||||
case BufferedImage.TYPE_USHORT_555_RGB:
|
||||
return "TYPE_USHORT_555_RGB";
|
||||
case BufferedImage.TYPE_BYTE_GRAY:
|
||||
return "TYPE_BYTE_GRAY";
|
||||
case BufferedImage.TYPE_BYTE_BINARY:
|
||||
return "TYPE_BYTE_BINARY";
|
||||
default:
|
||||
return "TBD";
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 2017, 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 4895483
|
||||
* @summary Test checks that the IllegalStateException was thrown if input was
|
||||
* not set to the BMPImageReader
|
||||
*/
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.ImageReader;
|
||||
import javax.imageio.metadata.IIOMetadata;
|
||||
|
||||
public class EmptyInputBmpMetadataTest {
|
||||
private static String fmt = "BMP";
|
||||
|
||||
public static void main(String[] args) {
|
||||
boolean isPassed = false;
|
||||
ImageReader ir = (ImageReader)ImageIO.getImageReadersByFormatName(fmt).next();
|
||||
|
||||
if (ir == null) {
|
||||
throw new RuntimeException("No available reader for " + fmt);
|
||||
}
|
||||
IIOMetadata meta = null;
|
||||
try {
|
||||
meta = ir.getImageMetadata(0);
|
||||
} catch (IllegalStateException e) {
|
||||
System.out.println("Correct exception was thrown. Test passed.");
|
||||
isPassed = true;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if (!isPassed) {
|
||||
throw new RuntimeException("The IllegalStateException was not thrown."
|
||||
+"Test failed.");
|
||||
}
|
||||
}
|
||||
}
|
301
jdk/test/javax/imageio/plugins/bmp/NoExtraBytesTest.java
Normal file
301
jdk/test/javax/imageio/plugins/bmp/NoExtraBytesTest.java
Normal file
@ -0,0 +1,301 @@
|
||||
/*
|
||||
* Copyright (c) 2006, 2017, 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 5076878
|
||||
* @summary Test verifies that ImageIO creates BMP images with correct bpp
|
||||
*/
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Transparency;
|
||||
import java.awt.color.ColorSpace;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.image.ColorModel;
|
||||
import java.awt.image.ComponentColorModel;
|
||||
import java.awt.image.DataBuffer;
|
||||
import java.awt.image.DirectColorModel;
|
||||
import java.awt.image.Raster;
|
||||
import java.awt.image.WritableRaster;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Hashtable;
|
||||
|
||||
import javax.imageio.IIOImage;
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.ImageReader;
|
||||
import javax.imageio.metadata.IIOMetadata;
|
||||
import javax.imageio.stream.ImageInputStream;
|
||||
|
||||
import org.w3c.dom.Node;
|
||||
|
||||
public class NoExtraBytesTest {
|
||||
|
||||
private static Hashtable<Integer, Integer> tests = null;
|
||||
private static Color[] usedColors = new Color[] { Color.red, Color.green, Color.blue, Color.yellow, Color.white, Color.black };
|
||||
|
||||
private static final int TYPE_INT_GRB = 0x100;
|
||||
private static final int TYPE_INT_GBR = 0x101;
|
||||
private static final int TYPE_INT_RBG = 0x102;
|
||||
private static final int TYPE_INT_BRG = 0x103;
|
||||
private static final int TYPE_INT_555_GRB = 0x104;
|
||||
private static final int TYPE_3BYTE_RGB = 0x105;
|
||||
private static final int TYPE_3BYTE_GRB = 0x106;
|
||||
|
||||
private static final int w = 300;
|
||||
private static final int h = 200;
|
||||
private static final int dx = w / usedColors.length;
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
initTests();
|
||||
|
||||
for (Integer type : tests.keySet()) {
|
||||
new NoExtraBytesTest(type.intValue(), tests.get(type).intValue()).doTest();
|
||||
}
|
||||
System.out.println("Test passed.");
|
||||
}
|
||||
|
||||
private static void initTests() {
|
||||
tests = new Hashtable<Integer, Integer>();
|
||||
|
||||
tests.put(new Integer(BufferedImage.TYPE_INT_RGB), new Integer(24));
|
||||
tests.put(new Integer(BufferedImage.TYPE_INT_BGR), new Integer(24));
|
||||
tests.put(new Integer(BufferedImage.TYPE_3BYTE_BGR), new Integer(24));
|
||||
tests.put(new Integer(TYPE_INT_GRB), new Integer(24));
|
||||
tests.put(new Integer(TYPE_INT_GBR), new Integer(24));
|
||||
tests.put(new Integer(TYPE_INT_RBG), new Integer(24));
|
||||
tests.put(new Integer(TYPE_INT_BRG), new Integer(24));
|
||||
tests.put(new Integer(BufferedImage.TYPE_USHORT_555_RGB), new Integer(16));
|
||||
tests.put(new Integer(BufferedImage.TYPE_USHORT_565_RGB), new Integer(16));
|
||||
tests.put(new Integer(TYPE_INT_555_GRB), new Integer(16));
|
||||
tests.put(new Integer(TYPE_3BYTE_RGB), new Integer(24));
|
||||
tests.put(new Integer(TYPE_3BYTE_GRB), new Integer(24));
|
||||
}
|
||||
|
||||
private static String getImageTypeName(int t) {
|
||||
switch(t) {
|
||||
case BufferedImage.TYPE_INT_RGB:
|
||||
return "TYPE_INT_RGB";
|
||||
case BufferedImage.TYPE_INT_BGR:
|
||||
return "TYPE_INT_BGR";
|
||||
case BufferedImage.TYPE_3BYTE_BGR:
|
||||
return "TYPE_3BYTE_BGR";
|
||||
case BufferedImage.TYPE_USHORT_555_RGB:
|
||||
return "TYPE_USHORT_555_RGB";
|
||||
case BufferedImage.TYPE_USHORT_565_RGB:
|
||||
return "TYPE_USHORT_565_RGB";
|
||||
case TYPE_INT_GRB:
|
||||
return "TYPE_INT_GRB";
|
||||
case TYPE_INT_GBR:
|
||||
return "TYPE_INT_GBR";
|
||||
case TYPE_INT_RBG:
|
||||
return "TYPE_INT_RBG";
|
||||
case TYPE_INT_BRG:
|
||||
return "TYPE_INT_BRG";
|
||||
case TYPE_INT_555_GRB:
|
||||
return "TYPE_INT_555_GRB";
|
||||
case TYPE_3BYTE_RGB:
|
||||
return "TYPE_3BYTE_RGB";
|
||||
case TYPE_3BYTE_GRB:
|
||||
return "TYPE_3BYTE_GRB";
|
||||
default:
|
||||
throw new IllegalArgumentException("Unknown image type: " + t);
|
||||
}
|
||||
}
|
||||
private static BufferedImage createTestImage(int type) {
|
||||
BufferedImage dst = null;
|
||||
ColorModel colorModel = null;
|
||||
WritableRaster raster = null;
|
||||
ColorSpace cs = null;
|
||||
System.out.println("Create image for " + getImageTypeName(type));
|
||||
switch(type) {
|
||||
case TYPE_INT_GRB:
|
||||
colorModel = new DirectColorModel(24,
|
||||
0x0000ff00,
|
||||
0x00ff0000,
|
||||
0x000000ff);
|
||||
break;
|
||||
case TYPE_INT_GBR:
|
||||
colorModel = new DirectColorModel(24,
|
||||
0x000000ff,
|
||||
0x00ff0000,
|
||||
0x0000ff00);
|
||||
break;
|
||||
case TYPE_INT_RBG:
|
||||
colorModel = new DirectColorModel(24,
|
||||
0x00ff0000,
|
||||
0x000000ff,
|
||||
0x0000ff00);
|
||||
break;
|
||||
case TYPE_INT_BRG:
|
||||
colorModel = new DirectColorModel(24,
|
||||
0x0000ff00,
|
||||
0x000000ff,
|
||||
0x00ff0000);
|
||||
break;
|
||||
case TYPE_INT_555_GRB:
|
||||
colorModel = new DirectColorModel(24,
|
||||
0x0000001F,
|
||||
0x000003e0,
|
||||
0x00007c00);
|
||||
break;
|
||||
case TYPE_3BYTE_RGB:
|
||||
cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
|
||||
int[] nBits = {8, 8, 8};
|
||||
int[] bOffs = {0, 1, 2};
|
||||
colorModel = new ComponentColorModel(cs, nBits, false, false,
|
||||
Transparency.OPAQUE,
|
||||
DataBuffer.TYPE_BYTE);
|
||||
raster = Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE,
|
||||
w, h,
|
||||
w*3, 3,
|
||||
bOffs, null);
|
||||
break;
|
||||
case TYPE_3BYTE_GRB:
|
||||
cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
|
||||
//nBits = {8, 8, 8};
|
||||
//bOffs = {0, 1, 2};
|
||||
colorModel = new ComponentColorModel(cs, new int[] { 8, 8, 8 }, false, false,
|
||||
Transparency.OPAQUE,
|
||||
DataBuffer.TYPE_BYTE);
|
||||
raster = Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE,
|
||||
w, h,
|
||||
w*3, 3,
|
||||
new int[] { 1, 0, 2}, null);
|
||||
break;
|
||||
default:
|
||||
dst = new BufferedImage(w, h, type);
|
||||
//colorModel = ImageTypeSpecifier.createFromBufferedImageType(type).getColorModel();
|
||||
}
|
||||
|
||||
if (dst == null) {
|
||||
if (raster == null) {
|
||||
raster = colorModel.createCompatibleWritableRaster(w, h);
|
||||
}
|
||||
|
||||
dst = new BufferedImage(colorModel, raster, false, null);
|
||||
}
|
||||
Graphics g = dst.createGraphics();
|
||||
for (int i = 0; i < usedColors.length; i ++) {
|
||||
g.setColor(usedColors[i]);
|
||||
g.fillRect(i * dx, 0, dx, h);
|
||||
}
|
||||
g.dispose();
|
||||
|
||||
return dst;
|
||||
}
|
||||
|
||||
private BufferedImage src;
|
||||
private int expectedColorDepth;
|
||||
private int type;
|
||||
|
||||
private IIOImage iio_dst;
|
||||
|
||||
public NoExtraBytesTest(int type, int expectedColorDepth) {
|
||||
this.type = type;
|
||||
this.src = createTestImage(type);
|
||||
this.expectedColorDepth = expectedColorDepth;
|
||||
}
|
||||
|
||||
public void doTest() throws IOException {
|
||||
// write src as BMP
|
||||
System.out.println("Test for image: " + getImageTypeName(type));
|
||||
System.out.println("image is " + src);
|
||||
|
||||
File f = File.createTempFile("sizeTest_", ".bmp", new File("."));
|
||||
System.out.println("Use file " + f.getCanonicalPath());
|
||||
ImageIO.write(src, "BMP", f);
|
||||
|
||||
//read it again
|
||||
read(f);
|
||||
|
||||
checkColorDepth();
|
||||
|
||||
checkImageContent();
|
||||
}
|
||||
|
||||
private void read(File f) throws IOException {
|
||||
ImageReader reader = ImageIO.getImageReadersByFormatName("BMP").next();
|
||||
|
||||
ImageInputStream iis =
|
||||
ImageIO.createImageInputStream(new FileInputStream(f));
|
||||
|
||||
reader.setInput(iis);
|
||||
|
||||
iio_dst = reader.readAll(0, reader.getDefaultReadParam());
|
||||
}
|
||||
|
||||
private void checkColorDepth() {
|
||||
IIOMetadata dst = iio_dst.getMetadata();
|
||||
|
||||
Node data = dst.getAsTree("javax_imageio_bmp_1.0");
|
||||
|
||||
Node n = data.getFirstChild();
|
||||
|
||||
while (n != null && !("BitsPerPixel".equals(n.getNodeName()))) {
|
||||
System.out.println("Node " + n.getNodeName());
|
||||
n = n.getNextSibling();
|
||||
}
|
||||
if (n == null) {
|
||||
throw new RuntimeException("No BitsPerSample node!");
|
||||
}
|
||||
|
||||
int bpp = 0;
|
||||
String value = n.getNodeValue();
|
||||
System.out.println("value = " + value);
|
||||
try {
|
||||
bpp = Integer.parseInt(value);
|
||||
} catch (NumberFormatException e) {
|
||||
throw new RuntimeException("Wrong bpp value: " + value, e);
|
||||
}
|
||||
|
||||
if (bpp != this.expectedColorDepth) {
|
||||
throw new RuntimeException("Wrong color depth: " + bpp +
|
||||
" (should be " + this.expectedColorDepth + ")");
|
||||
}
|
||||
}
|
||||
|
||||
private void checkImageContent() {
|
||||
BufferedImage dst =
|
||||
(BufferedImage)iio_dst.getRenderedImage();
|
||||
int y = h / 2;
|
||||
int x = dx / 2;
|
||||
|
||||
for (int i = 0; i < usedColors.length; i++, x += dx) {
|
||||
int srcRgb = src.getRGB(x, y);
|
||||
int dstRgb = dst.getRGB(x, y);
|
||||
int rgb = usedColors[i].getRGB();
|
||||
|
||||
if (dstRgb != srcRgb || dstRgb != rgb) {
|
||||
throw new RuntimeException("Wrong color at [" + x + ", " + y +
|
||||
"] " + Integer.toHexString(dstRgb) +
|
||||
" (srcRgb=" + Integer.toHexString(srcRgb) +
|
||||
", original color is " + Integer.toHexString(rgb) + ")");
|
||||
}
|
||||
|
||||
}
|
||||
System.out.println("Image colors are OK.");
|
||||
}
|
||||
}
|
159
jdk/test/javax/imageio/plugins/bmp/RLECompressionTest.java
Normal file
159
jdk/test/javax/imageio/plugins/bmp/RLECompressionTest.java
Normal file
@ -0,0 +1,159 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2017, 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 6332480
|
||||
* @summary Test verifies that images encoded as BMP with RLE4 or RLE8
|
||||
* compression type are read correctly
|
||||
*/
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.image.IndexColorModel;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.imageio.IIOImage;
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.ImageWriteParam;
|
||||
import javax.imageio.ImageWriter;
|
||||
import javax.imageio.stream.ImageOutputStream;
|
||||
|
||||
public class RLECompressionTest {
|
||||
public static final int TEST_RLE8 = 0x01;
|
||||
public static final int TEST_RLE4 = 0x02;
|
||||
|
||||
private static Color[] usedColors = new Color[] {
|
||||
Color.black, Color.white, Color.red,
|
||||
Color.green, Color.blue, Color.yellow };
|
||||
|
||||
int w = 100;
|
||||
// NB: problem occurs when image height > width
|
||||
// The problem manifestation is that only first w
|
||||
// lines of image are filled by decoded data,
|
||||
// rest of image (all lines below (w-1)-th line)
|
||||
// is leaved uninitialized (black).
|
||||
// In order to verify that this problem is solved,
|
||||
// we use image with height > width.
|
||||
int h = 2 * w;
|
||||
|
||||
private IndexColorModel getTestColorModel(int type) {
|
||||
IndexColorModel icm = null;
|
||||
int bpp = 8;
|
||||
int size = 256;
|
||||
|
||||
switch(type) {
|
||||
case TEST_RLE8:
|
||||
bpp = 8;
|
||||
size = 256;
|
||||
break;
|
||||
case TEST_RLE4:
|
||||
bpp = 4;
|
||||
size = 16;
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException("Wrong test type: " + type);
|
||||
}
|
||||
|
||||
byte[] palette = new byte[size * 3];
|
||||
for (int i = 0; i < usedColors.length; i++) {
|
||||
palette[3 * i] = (byte)(0xff & usedColors[i].getRed());
|
||||
palette[3 * i + 1] = (byte)(0xff & usedColors[i].getGreen());
|
||||
palette[3 * i + 2] = (byte)(0xff & usedColors[i].getBlue());
|
||||
}
|
||||
// rest of palette is black
|
||||
|
||||
icm = new IndexColorModel(bpp, size, palette, 0, false);
|
||||
return icm;
|
||||
}
|
||||
|
||||
private BufferedImage getTestImage(int type) {
|
||||
BufferedImage src = null;
|
||||
IndexColorModel icm = getTestColorModel(type);
|
||||
src = new BufferedImage(w, h, BufferedImage.TYPE_BYTE_INDEXED, icm);
|
||||
Graphics2D g = src.createGraphics();
|
||||
g.setColor(Color.white);
|
||||
g.fillRect(0, 0, w, h);
|
||||
g.dispose();
|
||||
|
||||
return src;
|
||||
}
|
||||
|
||||
public void doTest(int type) throws IOException {
|
||||
BufferedImage src = getTestImage(type);
|
||||
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
|
||||
|
||||
ImageWriter writer = ImageIO.getImageWritersByFormatName("BMP").next();
|
||||
writer.setOutput(ios);
|
||||
|
||||
ImageWriteParam wparam = writer.getDefaultWriteParam();
|
||||
wparam.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
|
||||
switch(type) {
|
||||
case TEST_RLE8:
|
||||
wparam.setCompressionType("BI_RLE8");
|
||||
break;
|
||||
case TEST_RLE4:
|
||||
wparam.setCompressionType("BI_RLE4");
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException("Wrong test type: " + type);
|
||||
}
|
||||
|
||||
writer.write(null, new IIOImage(src, null, null), wparam);
|
||||
|
||||
ios.close();
|
||||
baos.close();
|
||||
|
||||
// read result
|
||||
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
|
||||
|
||||
BufferedImage dst = ImageIO.read(bais);
|
||||
|
||||
checkResult(src, dst);
|
||||
}
|
||||
|
||||
private void checkResult(BufferedImage src, BufferedImage dst) {
|
||||
int x = w / 2;
|
||||
for (int y = 0; y < h; y++) {
|
||||
int srcRgb = src.getRGB(x, y);
|
||||
int dstRgb = dst.getRGB(x, y);
|
||||
|
||||
if (srcRgb != dstRgb) {
|
||||
throw new RuntimeException("Test failed due to color difference: " +
|
||||
Integer.toHexString(dstRgb) + " instead of " + Integer.toHexString(srcRgb) +
|
||||
" at [" + x + ", " + y + "]");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
RLECompressionTest test = new RLECompressionTest();
|
||||
test.doTest(TEST_RLE8);
|
||||
test.doTest(TEST_RLE4);
|
||||
}
|
||||
}
|
257
jdk/test/javax/imageio/plugins/bmp/ReaderListenersTest.java
Normal file
257
jdk/test/javax/imageio/plugins/bmp/ReaderListenersTest.java
Normal file
@ -0,0 +1,257 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 2017, 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 4924507
|
||||
* @summary Test that listeners of bmp reader receive correct events in case of
|
||||
* BI_JPEG and BI_PNG compression types
|
||||
*/
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import javax.imageio.IIOImage;
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.ImageReader;
|
||||
import javax.imageio.ImageWriteParam;
|
||||
import javax.imageio.ImageWriter;
|
||||
import javax.imageio.event.IIOReadProgressListener;
|
||||
import javax.imageio.event.IIOReadUpdateListener;
|
||||
|
||||
public class ReaderListenersTest {
|
||||
public static final String[] compTypes = { "BI_JPEG", "BI_PNG" };
|
||||
|
||||
public static void main(String[] args) {
|
||||
for (int i=0; i< compTypes.length; i++) {
|
||||
doTest(compTypes[i]);
|
||||
}
|
||||
}
|
||||
|
||||
private static void doTest(String compression) {
|
||||
try {
|
||||
BufferedImage img = createTestImage();
|
||||
|
||||
ImageWriter iw = (ImageWriter)
|
||||
ImageIO.getImageWritersByFormatName("bmp").next();
|
||||
if (iw == null) {
|
||||
throw new RuntimeException("No writers for bmp format."
|
||||
+ " Test failed.");
|
||||
}
|
||||
|
||||
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
iw.setOutput(ImageIO.createImageOutputStream(baos));
|
||||
ImageWriteParam param = iw.getDefaultWriteParam();
|
||||
param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
|
||||
param.setCompressionType(compression);
|
||||
|
||||
iw.write(null, new IIOImage(img, null, null), param);
|
||||
baos.close();
|
||||
|
||||
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
|
||||
|
||||
ImageReader ir = (ImageReader)
|
||||
ImageIO.getImageReadersByFormatName("bmp").next();
|
||||
if (ir == null) {
|
||||
throw new RuntimeException("No readers for bmp format."
|
||||
+ " Test failed.");
|
||||
}
|
||||
|
||||
IIOReadUpdateAdapter updateAdapter = new IIOReadUpdateAdapter();
|
||||
IIOReadProgressAdapter progressAdapter = new IIOReadProgressAdapter();
|
||||
ir.addIIOReadProgressListener(progressAdapter);
|
||||
ir.addIIOReadUpdateListener(updateAdapter);
|
||||
ir.setInput(ImageIO.createImageInputStream(bais));
|
||||
BufferedImage dst = ir.read(0);
|
||||
|
||||
progressAdapter.checkResults();
|
||||
|
||||
if (!updateAdapter.isImageUpdateUsed) {
|
||||
throw new RuntimeException("imageUpdate was not used."
|
||||
+ " Test failed.");
|
||||
}
|
||||
} catch(IOException e) {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException("Test failed");
|
||||
}
|
||||
}
|
||||
|
||||
protected static BufferedImage createTestImage() {
|
||||
BufferedImage res = new BufferedImage(100, 100,
|
||||
BufferedImage.TYPE_INT_RGB);
|
||||
Graphics2D g = res.createGraphics();
|
||||
g.setColor(Color.red);
|
||||
g.fillRect(0,0, 100,100);
|
||||
return res;
|
||||
}
|
||||
|
||||
static class IIOReadProgressAdapter implements IIOReadProgressListener {
|
||||
List progress = new ArrayList();
|
||||
public boolean isTestPassed = false;
|
||||
private boolean isImageStarted = false;
|
||||
private boolean isImageComplete = false;
|
||||
private boolean isSequenceComplete = false;
|
||||
private boolean isSequenceStarted = false;
|
||||
|
||||
public void imageComplete(ImageReader source) {
|
||||
System.out.println("Image completed");
|
||||
if (!isImageComplete) {
|
||||
isImageComplete = true;
|
||||
} else {
|
||||
throw new RuntimeException("The imageComplete() is called twice."
|
||||
+ " Test failed.");
|
||||
}
|
||||
checkProgress();
|
||||
}
|
||||
|
||||
public void imageProgress(ImageReader source, float percentageDone) {
|
||||
System.out.println("Image Progress "+percentageDone);
|
||||
progress.add(new Float(percentageDone));
|
||||
}
|
||||
|
||||
public void imageStarted(ImageReader source, int imageIndex) {
|
||||
System.out.println("Image Started "+imageIndex);
|
||||
if (!isImageStarted) {
|
||||
isImageStarted = true;
|
||||
} else {
|
||||
throw new RuntimeException("The imageStarted() was called twice. "
|
||||
+ " Test failed.");
|
||||
}
|
||||
progress.clear();
|
||||
}
|
||||
|
||||
public void thumbnailComplete(ImageReader source) {
|
||||
System.out.println("Thubnail completed");
|
||||
}
|
||||
|
||||
public void thumbnailProgress(ImageReader source,
|
||||
float percentageDone)
|
||||
{
|
||||
System.out.println("Thubnail Progress " + percentageDone);
|
||||
}
|
||||
|
||||
public void thumbnailStarted(ImageReader source,
|
||||
int imageIndex, int thumbnailIndex)
|
||||
{
|
||||
System.out.println("Thubnail started " + imageIndex);
|
||||
}
|
||||
|
||||
public void sequenceComplete(ImageReader source) {
|
||||
if (!isSequenceComplete) {
|
||||
isSequenceComplete = true;
|
||||
} else {
|
||||
throw new RuntimeException("The imageComplete() is called twice."
|
||||
+ " Test failed.");
|
||||
}
|
||||
}
|
||||
|
||||
public void sequenceStarted(ImageReader source, int minIndex) {
|
||||
if (!isSequenceStarted) {
|
||||
isSequenceStarted = true;
|
||||
} else {
|
||||
throw new RuntimeException("The imageComplete() is called twice."
|
||||
+ " Test failed.");
|
||||
}
|
||||
}
|
||||
|
||||
public void readAborted(ImageReader source) {
|
||||
System.out.println("read Aborted");
|
||||
checkProgress();
|
||||
}
|
||||
|
||||
private void checkProgress() {
|
||||
Iterator i = progress.iterator();
|
||||
if (!i.hasNext()) {
|
||||
throw new RuntimeException("progress values list is empty!");
|
||||
}
|
||||
float val = ((Float)i.next()).floatValue();
|
||||
while(i.hasNext()) {
|
||||
float next = ((Float)i.next()).floatValue();
|
||||
if (val >= next) {
|
||||
throw new RuntimeException("progress values do not increase!");
|
||||
}
|
||||
val = next;
|
||||
}
|
||||
isTestPassed = true;
|
||||
System.out.println("Test passed.");
|
||||
}
|
||||
|
||||
public void checkResults() {
|
||||
if (isImageStarted && !isImageComplete) {
|
||||
throw new RuntimeException("The imageCompleted was not called."
|
||||
+ " Test failed.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static class IIOReadUpdateAdapter implements IIOReadUpdateListener {
|
||||
boolean isImageUpdateUsed = false;
|
||||
public void imageUpdate(ImageReader source, BufferedImage theImage,
|
||||
int minX, int minY, int width, int height,
|
||||
int periodX, int periodY, int[] bands)
|
||||
{
|
||||
System.out.println("imageUpdate");
|
||||
isImageUpdateUsed = true;
|
||||
}
|
||||
public void passComplete(ImageReader source, BufferedImage theImage) {
|
||||
System.out.println("passComplete");
|
||||
}
|
||||
public void passStarted(ImageReader source, BufferedImage theImage,
|
||||
int pass, int minPass, int maxPass,
|
||||
int minX, int minY, int periodX, int periodY,
|
||||
int[] bands)
|
||||
{
|
||||
System.out.println("passStarted");
|
||||
}
|
||||
public void thumbnailPassComplete(ImageReader source,
|
||||
BufferedImage theThumbnail)
|
||||
{
|
||||
System.out.println("thumbnailPassComplete");
|
||||
}
|
||||
public void thumbnailPassStarted(ImageReader source,
|
||||
BufferedImage theThumbnail,
|
||||
int pass, int minPass, int maxPass,
|
||||
int minX, int minY,
|
||||
int periodX, int periodY,
|
||||
int[] bands)
|
||||
{
|
||||
System.out.println("thumbnailPassStarted");
|
||||
}
|
||||
public void thumbnailUpdate(ImageReader source,
|
||||
BufferedImage theThumbnail,
|
||||
int minX, int minY,
|
||||
int width, int height,
|
||||
int periodX, int periodY, int[] bands)
|
||||
{
|
||||
System.out.println("thumbnailUpdate");
|
||||
}
|
||||
}
|
||||
}
|
223
jdk/test/javax/imageio/plugins/bmp/RleEncodingTest.java
Normal file
223
jdk/test/javax/imageio/plugins/bmp/RleEncodingTest.java
Normal file
@ -0,0 +1,223 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 2017, 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 4893446
|
||||
* @summary Tests that we get IOException if we try to encode the incompatible
|
||||
* image with RLE compression
|
||||
*/
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.image.IndexColorModel;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.imageio.IIOImage;
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.ImageWriteParam;
|
||||
import javax.imageio.ImageWriter;
|
||||
import javax.imageio.stream.ImageInputStream;
|
||||
import javax.imageio.stream.ImageOutputStream;
|
||||
|
||||
public class RleEncodingTest {
|
||||
|
||||
private static int testIdx = 1;
|
||||
|
||||
public static void main(String args[]) throws Exception {
|
||||
try {
|
||||
int mode = ImageWriteParam.MODE_EXPLICIT;
|
||||
String type = "BI_RLE4";
|
||||
doTest(type, mode);
|
||||
|
||||
type = "BI_RLE8";
|
||||
doTest(type, mode);
|
||||
|
||||
mode = ImageWriteParam.MODE_DEFAULT;
|
||||
type = "BI_RLE4";
|
||||
doTest(type, mode);
|
||||
|
||||
type = "BI_RLE8";
|
||||
doTest(type, mode);
|
||||
|
||||
System.out.println("Test 4bpp image.");
|
||||
encodeRLE4Test();
|
||||
|
||||
System.out.println("Test 8bpp image.");
|
||||
encodeRLE8Test();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException("Unexpected exception. Test failed");
|
||||
}
|
||||
}
|
||||
|
||||
private static void doTest(String compressionType,
|
||||
int compressionMode) throws IOException
|
||||
{
|
||||
BufferedImage bimg = new BufferedImage(100, 100,
|
||||
BufferedImage.TYPE_INT_RGB);
|
||||
Graphics g = bimg.getGraphics();
|
||||
g.setColor(Color.green);
|
||||
g.fillRect(0, 0, 100, 100);
|
||||
|
||||
doTest(bimg, compressionType, compressionMode);
|
||||
}
|
||||
|
||||
private static void encodeRLE4Test() throws IOException {
|
||||
// create 4bpp image
|
||||
byte[] r = new byte[16];
|
||||
r[0] = (byte)0xff;
|
||||
byte[] g = new byte[16];
|
||||
g[1] = (byte)0xff;
|
||||
byte[] b = new byte[16];
|
||||
b[2] = (byte)0xff;
|
||||
IndexColorModel icm = new IndexColorModel(4, 16, r, g, b);
|
||||
|
||||
BufferedImage bimg = new BufferedImage(100, 100,
|
||||
BufferedImage.TYPE_BYTE_BINARY,
|
||||
icm);
|
||||
|
||||
Graphics gr = bimg.getGraphics();
|
||||
gr.setColor(Color.green);
|
||||
gr.fillRect(0, 0, 100, 100);
|
||||
|
||||
doTest(bimg, "BI_RLE4", ImageWriteParam.MODE_EXPLICIT);
|
||||
}
|
||||
|
||||
private static void encodeRLE8Test() throws IOException {
|
||||
// create 8bpp image
|
||||
byte[] r = new byte[256];
|
||||
r[0] = (byte)0xff;
|
||||
byte[] g = new byte[256];
|
||||
g[1] = (byte)0xff;
|
||||
byte[] b = new byte[256];
|
||||
b[2] = (byte)0xff;
|
||||
IndexColorModel icm = new IndexColorModel(8, 256, r, g, b);
|
||||
|
||||
BufferedImage bimg = new BufferedImage(100, 100,
|
||||
BufferedImage.TYPE_BYTE_INDEXED,
|
||||
icm);
|
||||
Graphics gr = bimg.getGraphics();
|
||||
gr.setColor(Color.green);
|
||||
gr.fillRect(0, 0, 100, 100);
|
||||
|
||||
doTest(bimg, "BI_RLE8", ImageWriteParam.MODE_EXPLICIT);
|
||||
}
|
||||
|
||||
private static void doTest(BufferedImage src,
|
||||
String compressionType,
|
||||
int compressionMode) throws IOException
|
||||
{
|
||||
|
||||
ImageWriter iw = (ImageWriter)ImageIO.getImageWritersBySuffix("bmp").next();
|
||||
if (iw == null) {
|
||||
throw new RuntimeException("No available writer. Test failed.");
|
||||
}
|
||||
|
||||
IIOImage iioImg = new IIOImage(src, null, null);
|
||||
ImageWriteParam param = iw.getDefaultWriteParam();
|
||||
|
||||
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
|
||||
iw.setOutput(ios);
|
||||
|
||||
System.out.println("Compression Type is " + compressionType);
|
||||
System.out.println("Compression Mode is " + compressionMode);
|
||||
|
||||
param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
|
||||
param.setCompressionType(compressionType);
|
||||
if (compressionMode != ImageWriteParam.MODE_EXPLICIT) {
|
||||
param.setCompressionMode(compressionMode);
|
||||
}
|
||||
try {
|
||||
iw.write(null, iioImg, param);
|
||||
} catch (IOException e) {
|
||||
int bpp = src.getColorModel().getPixelSize();
|
||||
if (compressionMode == ImageWriteParam.MODE_EXPLICIT) {
|
||||
if ((compressionType.equals("BI_RLE4") && bpp != 4)
|
||||
|| (compressionType.equals("BI_RLE8") && bpp != 8))
|
||||
{
|
||||
System.out.println("Can not encode "+ bpp+ "bpp image as"
|
||||
+ compressionType);
|
||||
return;
|
||||
} else {
|
||||
throw new RuntimeException("Unable to encode "
|
||||
+ bpp + "bpp image as "
|
||||
+ compressionType
|
||||
+ ". Test failed");
|
||||
}
|
||||
}
|
||||
}
|
||||
baos.close();
|
||||
|
||||
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
|
||||
ImageInputStream iis = ImageIO.createImageInputStream(bais);
|
||||
|
||||
BufferedImage dst = ImageIO.read(iis);
|
||||
|
||||
int w = src.getWidth();
|
||||
int h = src.getHeight();
|
||||
|
||||
Object dstPixel = dst.getRaster().getDataElements(w/2, h/2, null);
|
||||
Object srcPixel = src.getRaster().getDataElements(w/2, h/2, null);
|
||||
|
||||
if ( (src.getColorModel().getRed(srcPixel)
|
||||
!= dst.getColorModel().getRed(dstPixel))
|
||||
|| (src.getColorModel().getGreen(srcPixel)
|
||||
!= dst.getColorModel().getGreen(dstPixel))
|
||||
|| (src.getColorModel().getBlue(srcPixel)
|
||||
!= dst.getColorModel().getBlue(dstPixel))
|
||||
|| (src.getColorModel().getAlpha(srcPixel)
|
||||
!= dst.getColorModel().getAlpha(dstPixel)) ) {
|
||||
|
||||
showPixel(src, w/2, h/2);
|
||||
showPixel(dst, w/2, h/2);
|
||||
|
||||
throw new RuntimeException(
|
||||
"Colors are different: " +
|
||||
Integer.toHexString(src.getColorModel().getRGB(srcPixel))
|
||||
+ " and " +
|
||||
Integer.toHexString(dst.getColorModel().getRGB(dstPixel)));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static void showPixel(BufferedImage src, int x, int y) {
|
||||
System.out.println("Img is " + src);
|
||||
Object p = src.getRaster().getDataElements(x, y, null);
|
||||
System.out.println("RGB: " +
|
||||
Integer.toHexString(src.getColorModel().getRGB(p)));
|
||||
System.out.println("Red: " +
|
||||
Integer.toHexString(src.getColorModel().getRed(p)));
|
||||
System.out.println("Green: " +
|
||||
Integer.toHexString(src.getColorModel().getGreen(p)));
|
||||
System.out.println("Blue: " +
|
||||
Integer.toHexString(src.getColorModel().getBlue(p)));
|
||||
System.out.println("Alpha: " +
|
||||
Integer.toHexString(src.getColorModel().getAlpha(p)));
|
||||
}
|
||||
}
|
@ -0,0 +1,181 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2017, 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 6297016 6294960 6294965 6294984
|
||||
* @summary Test verifies that buffered images are written correctly if
|
||||
* compression BI_BITFIELDS is used
|
||||
*/
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.color.ColorSpace;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.imageio.IIOImage;
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.ImageReader;
|
||||
import javax.imageio.ImageWriteParam;
|
||||
import javax.imageio.ImageWriter;
|
||||
|
||||
public class TestCompressionBI_BITFIELDS {
|
||||
|
||||
protected String format = "BMP";
|
||||
|
||||
protected ImageReader reader;
|
||||
|
||||
protected ImageWriter writer;
|
||||
|
||||
protected boolean doSave = true;
|
||||
|
||||
Color[] colors = {
|
||||
Color.red, Color.green, Color.blue,
|
||||
Color.yellow, Color.white, Color.black};
|
||||
|
||||
int dx = 50;
|
||||
int h = 200;
|
||||
|
||||
public TestCompressionBI_BITFIELDS() {
|
||||
this("BMP");
|
||||
}
|
||||
|
||||
public TestCompressionBI_BITFIELDS(String format) {
|
||||
this.format = format;
|
||||
reader = ImageIO.getImageReadersByFormatName(format).next();
|
||||
writer = ImageIO.getImageWritersByFormatName(format).next();
|
||||
}
|
||||
|
||||
protected ImageWriteParam prepareWriteParam(BufferedImage src) {
|
||||
ImageWriteParam wparam = writer.getDefaultWriteParam();
|
||||
wparam.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
|
||||
wparam.setCompressionType("BI_BITFIELDS");
|
||||
|
||||
return wparam;
|
||||
}
|
||||
|
||||
public BufferedImage writeAndRead(BufferedImage src) throws IOException {
|
||||
writer.reset();
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
writer.setOutput(ImageIO.createImageOutputStream(baos));
|
||||
|
||||
ImageWriteParam wparam = prepareWriteParam(src);
|
||||
|
||||
IIOImage img = new IIOImage(src, null, null);
|
||||
|
||||
writer.write(null, img, wparam);
|
||||
|
||||
if (doSave) {
|
||||
// save images to file in order to be able to check
|
||||
// that image is well-formed using standard windows tools.
|
||||
File f = File.createTempFile("wr_test_", "." + format, new File("."));
|
||||
System.out.println("Save to file: " + f.getCanonicalPath());
|
||||
FileOutputStream fos = new FileOutputStream(f);
|
||||
fos.write(baos.toByteArray());
|
||||
fos.flush();
|
||||
fos.close();
|
||||
}
|
||||
|
||||
// read result
|
||||
reader.reset();
|
||||
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
|
||||
reader.setInput(ImageIO.createImageInputStream(bais));
|
||||
|
||||
return reader.read(0);
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
// buffered image types listed below can be saved as BI_BITFIELDS BMP
|
||||
int[] types = {BufferedImage.TYPE_3BYTE_BGR,
|
||||
BufferedImage.TYPE_USHORT_555_RGB,
|
||||
BufferedImage.TYPE_USHORT_565_RGB,
|
||||
BufferedImage.TYPE_BYTE_GRAY,
|
||||
BufferedImage.TYPE_BYTE_BINARY,
|
||||
BufferedImage.TYPE_BYTE_INDEXED,
|
||||
BufferedImage.TYPE_INT_BGR,
|
||||
BufferedImage.TYPE_INT_RGB};
|
||||
|
||||
for (int i = 0; i < types.length; i++) {
|
||||
System.out.println("Test image " + types[i]);
|
||||
TestCompressionBI_BITFIELDS t = new TestCompressionBI_BITFIELDS();
|
||||
|
||||
BufferedImage src =
|
||||
t.createTestImage(types[i]);
|
||||
System.out.println("Image for test: " + src);
|
||||
System.out.println("SampleModel: " + src.getSampleModel());
|
||||
|
||||
BufferedImage dst = null;
|
||||
try {
|
||||
dst = t.writeAndRead(src);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace(System.out);
|
||||
}
|
||||
|
||||
|
||||
t.compareImages(src, dst);
|
||||
}
|
||||
}
|
||||
|
||||
protected BufferedImage createTestImage(int type) {
|
||||
BufferedImage bimg = new BufferedImage(dx * colors.length, h, type);
|
||||
Graphics2D g = bimg.createGraphics();
|
||||
|
||||
for (int i = 0; i < colors.length; i++) {
|
||||
g.setColor(colors[i]);
|
||||
g.fillRect(dx * i, 0, dx, h);
|
||||
}
|
||||
return bimg;
|
||||
}
|
||||
|
||||
protected void compareImages(BufferedImage src, BufferedImage dst) {
|
||||
ColorSpace srcCS = src.getColorModel().getColorSpace();
|
||||
ColorSpace dstCS = dst.getColorModel().getColorSpace();
|
||||
if (!srcCS.equals(dstCS) && srcCS.getType() == ColorSpace.TYPE_GRAY) {
|
||||
System.out.println("Workaround color difference with GRAY.");
|
||||
BufferedImage tmp =
|
||||
new BufferedImage(src.getWidth(), src.getHeight(),
|
||||
BufferedImage.TYPE_INT_RGB);
|
||||
Graphics g = tmp.createGraphics();
|
||||
g.drawImage(src, 0, 0, null);
|
||||
src = tmp;
|
||||
}
|
||||
int y = h / 2;
|
||||
for (int i = 0; i < colors.length; i++) {
|
||||
int x = dx * i + dx / 2;
|
||||
int srcRgb = src.getRGB(x, y);
|
||||
int dstRgb = dst.getRGB(x, y);
|
||||
|
||||
if (srcRgb != dstRgb) {
|
||||
throw new RuntimeException("Test failed due to color difference: " +
|
||||
"src_pixel=" + Integer.toHexString(srcRgb) +
|
||||
"dst_pixel=" + Integer.toHexString(dstRgb));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
228
jdk/test/javax/imageio/plugins/bmp/Write3ByteBgrTest.java
Normal file
228
jdk/test/javax/imageio/plugins/bmp/Write3ByteBgrTest.java
Normal file
@ -0,0 +1,228 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 2017, 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 4892194 8014427
|
||||
* @summary Test checks that we able to encode TYPE_3BYTE_BGR images to bmp
|
||||
* format. Test failed if ArrayIndexOutOfBoundsException will be thrown
|
||||
* or pixel colors will be changed by the writing/reading.
|
||||
*/
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.color.ColorSpace;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.image.ColorModel;
|
||||
import java.awt.image.ComponentColorModel;
|
||||
import java.awt.image.DataBuffer;
|
||||
import java.awt.image.Raster;
|
||||
import java.awt.image.WritableRaster;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.imageio.IIOImage;
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.ImageWriter;
|
||||
import javax.imageio.stream.ImageOutputStream;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JFrame;
|
||||
|
||||
public class Write3ByteBgrTest {
|
||||
private static int width = 100;
|
||||
private static int height = 100;
|
||||
private static Color color = new Color(0x10, 0x20, 0x30);
|
||||
|
||||
static int bufferedImageType[] = {
|
||||
BufferedImage.TYPE_CUSTOM,
|
||||
BufferedImage.TYPE_BYTE_BINARY,
|
||||
BufferedImage.TYPE_3BYTE_BGR
|
||||
};
|
||||
|
||||
static String bufferedImageStringType[] = {
|
||||
"BufferedImage.TYPE_CUSTOM: test for BandedSampleModel",
|
||||
"BufferedImage.TYPE_BYTE_BINARY",
|
||||
"BufferedImage.TYPE_3BYTE_BGR"
|
||||
};
|
||||
|
||||
private static String writingFormat = "BMP";
|
||||
private static ImageWriter writer = (ImageWriter)ImageIO.getImageWritersByFormatName(writingFormat).next();
|
||||
private int type;
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
//int i = 0;
|
||||
for(int i=0; i<bufferedImageType.length; i++) {
|
||||
Write3ByteBgrTest t1 = new Write3ByteBgrTest(bufferedImageType[i]);
|
||||
|
||||
System.out.println("\n\nImage test for type " + bufferedImageStringType[i]);
|
||||
t1.doImageTest();
|
||||
}
|
||||
}
|
||||
|
||||
private Write3ByteBgrTest(int type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
private void doImageTest() {
|
||||
try {
|
||||
BufferedImage src = createTestImage(type);
|
||||
BufferedImage dst = writeImage(src);
|
||||
|
||||
compareImages(src, dst);
|
||||
} catch (ArrayIndexOutOfBoundsException e) {
|
||||
throw new RuntimeException("Test failed: index out of array bounds!");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void compareImages(BufferedImage src, BufferedImage dst) {
|
||||
Object dstPixel = dst.getRaster().getDataElements(width/2, height/2, null);
|
||||
Object srcPixel = src.getRaster().getDataElements(width/2, height/2, null);
|
||||
|
||||
if ( (src.getColorModel().getRed(srcPixel) != dst.getColorModel().getRed(dstPixel)) ||
|
||||
(src.getColorModel().getGreen(srcPixel) != dst.getColorModel().getGreen(dstPixel)) ||
|
||||
(src.getColorModel().getBlue(srcPixel) != dst.getColorModel().getBlue(dstPixel)) ||
|
||||
(src.getColorModel().getAlpha(srcPixel) != dst.getColorModel().getAlpha(dstPixel)) ) {
|
||||
|
||||
showPixel(src, width/2, height/2);
|
||||
showPixel(dst, width/2, height/2);
|
||||
|
||||
showRes(dst, src);
|
||||
throw new RuntimeException(
|
||||
"Colors are different: " +
|
||||
Integer.toHexString(src.getColorModel().getRGB(srcPixel)) + " and " +
|
||||
Integer.toHexString(dst.getColorModel().getRGB(dstPixel)));
|
||||
}
|
||||
}
|
||||
|
||||
private BufferedImage writeImage(BufferedImage src) {
|
||||
try {
|
||||
BufferedImage dst = null;
|
||||
if (!writer.getOriginatingProvider().canEncodeImage(src)) {
|
||||
throw new RuntimeException(writingFormat+" writer does not support the image type "+type);
|
||||
}
|
||||
System.out.println(writingFormat+" writer claims it can encode the image "+type);
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
|
||||
writer.setOutput(ios);
|
||||
IIOImage img = new IIOImage(src.getRaster(), null, null);
|
||||
writer.write(img);
|
||||
ios.close();
|
||||
baos.close();
|
||||
|
||||
// save to file
|
||||
File f = new File("test"+src.getType()+".bmp");
|
||||
FileOutputStream fos = new FileOutputStream(f);
|
||||
fos.write(baos.toByteArray());
|
||||
fos.close();
|
||||
|
||||
|
||||
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
|
||||
dst = ImageIO.read(bais);
|
||||
return dst;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private static void showPixel(BufferedImage src, int x, int y) {
|
||||
System.out.println("Img is " + src);
|
||||
Object p = src.getRaster().getDataElements(x, y, null);
|
||||
System.out.println("RGB: " +
|
||||
Integer.toHexString(src.getColorModel().getRGB(p)));
|
||||
System.out.println("Red: " +
|
||||
Integer.toHexString(src.getColorModel().getRed(p)));
|
||||
System.out.println("Green: " +
|
||||
Integer.toHexString(src.getColorModel().getGreen(p)));
|
||||
System.out.println("Blue: " +
|
||||
Integer.toHexString(src.getColorModel().getBlue(p)));
|
||||
System.out.println("Alpha: " +
|
||||
Integer.toHexString(src.getColorModel().getAlpha(p)));
|
||||
}
|
||||
|
||||
private static BufferedImage createTestImage(int type) {
|
||||
return createTestImage(type, color);
|
||||
}
|
||||
|
||||
private static BufferedImage createTestImage(int type, Color c) {
|
||||
BufferedImage i = null;
|
||||
if (type == BufferedImage.TYPE_CUSTOM) {
|
||||
WritableRaster wr = Raster.createBandedRaster(
|
||||
DataBuffer.TYPE_BYTE,
|
||||
width, height,
|
||||
width, // scanlineStride
|
||||
new int[] { 0, 1, 2},// bankIndices[],
|
||||
new int[] { 1, 2, 0},// bankOffsets[],
|
||||
null);
|
||||
|
||||
ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
|
||||
|
||||
ColorModel cm = new ComponentColorModel(cs,
|
||||
new int[] { 8, 8, 8},
|
||||
false,
|
||||
false,
|
||||
ColorModel.OPAQUE,
|
||||
DataBuffer.TYPE_BYTE);
|
||||
i = new BufferedImage(cm, wr, false, null);
|
||||
} else {
|
||||
i = new BufferedImage(width, height, type);
|
||||
}
|
||||
|
||||
Graphics2D g = i.createGraphics();
|
||||
|
||||
g.setColor(c);
|
||||
g.fillRect(0, 0, width, height);
|
||||
g.setColor(Color.white);
|
||||
g.drawRect(10,10, width-20, height-20);
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
private static void showRes(final BufferedImage src,
|
||||
final BufferedImage dst)
|
||||
{
|
||||
final int w = src.getWidth()+ dst.getWidth();
|
||||
final int h = Math.max(src.getHeight(), dst.getHeight());
|
||||
|
||||
JFrame f = new JFrame("Test results");
|
||||
f.getContentPane().add( new JComponent() {
|
||||
public Dimension getPreferredSize() {
|
||||
return new Dimension(w,h);
|
||||
}
|
||||
|
||||
public void paintComponent(Graphics g) {
|
||||
g.drawImage(src,0,0, null);
|
||||
g.drawImage(dst, src.getWidth(),0, null);
|
||||
}
|
||||
});
|
||||
f.pack();
|
||||
f.setVisible(true);
|
||||
}
|
||||
}
|
@ -0,0 +1,176 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 2017, 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 4897067 4920152
|
||||
* @summary Tests that IIOWriteProgressListener receives correct progress
|
||||
* percentage. Also it tests problem described in 4920152: test fails
|
||||
* if imageComplete() or imageStarted() was called twice.
|
||||
*/
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import javax.imageio.IIOImage;
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.ImageWriteParam;
|
||||
import javax.imageio.ImageWriter;
|
||||
import javax.imageio.event.IIOWriteProgressListener;
|
||||
import javax.imageio.stream.ImageOutputStream;
|
||||
|
||||
public class WriteProgressListenerTest {
|
||||
|
||||
|
||||
protected static String format = "BMP";
|
||||
|
||||
protected String compression_type;
|
||||
protected WriteProgressListener listener;
|
||||
|
||||
public WriteProgressListenerTest(String compression_type) {
|
||||
this.compression_type = compression_type;
|
||||
listener = new WriteProgressListener();
|
||||
}
|
||||
|
||||
public void doTest() {
|
||||
try {
|
||||
System.out.println("Progress test for " + compression_type);
|
||||
BufferedImage bi = new BufferedImage(20, 300, BufferedImage.TYPE_INT_RGB);
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
|
||||
|
||||
Iterator iter = ImageIO.getImageWritersByFormatName(format);
|
||||
if (!iter.hasNext()) {
|
||||
throw new RuntimeException("No available writer for " + format);
|
||||
}
|
||||
ImageWriter writer = (ImageWriter)iter.next();
|
||||
|
||||
writer.setOutput(ios);
|
||||
writer.addIIOWriteProgressListener(listener);
|
||||
|
||||
IIOImage iio_img = new IIOImage(bi, null, null);
|
||||
|
||||
ImageWriteParam param = writer.getDefaultWriteParam();
|
||||
|
||||
param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
|
||||
param.setCompressionType(compression_type);
|
||||
|
||||
|
||||
writer.write(null, iio_img, param);
|
||||
|
||||
if (!listener.isTestPassed) {
|
||||
throw new RuntimeException("Test for " + compression_type + " does not finish correctly!");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String args[]) {
|
||||
String[] compression_types = new String[] { "BI_RGB",
|
||||
"BI_JPEG",
|
||||
"BI_PNG"};
|
||||
|
||||
for(int i=0; i<compression_types.length; i++) {
|
||||
WriteProgressListenerTest test = new
|
||||
WriteProgressListenerTest(compression_types[i]);
|
||||
test.doTest();
|
||||
}
|
||||
}
|
||||
|
||||
static class WriteProgressListener implements IIOWriteProgressListener {
|
||||
List progress;
|
||||
public boolean isTestPassed = false;
|
||||
private boolean isImageStarted = false;
|
||||
private boolean isImageComplete = false;
|
||||
|
||||
public WriteProgressListener() {
|
||||
progress = new ArrayList();
|
||||
}
|
||||
|
||||
public void imageComplete(ImageWriter source) {
|
||||
System.out.println("Image Completed");
|
||||
if (!isImageComplete) {
|
||||
isImageComplete = true;
|
||||
} else {
|
||||
throw new RuntimeException("The imageComplete() was called twice."
|
||||
+ " Test failed.");
|
||||
}
|
||||
|
||||
checkProgress();
|
||||
}
|
||||
public void imageProgress(ImageWriter source, float percentageDone) {
|
||||
System.out.println("Image Progress "+percentageDone);
|
||||
progress.add(new Float(percentageDone));
|
||||
}
|
||||
|
||||
public void imageStarted(ImageWriter source, int imageIndex) {
|
||||
System.out.println("Image Started "+imageIndex);
|
||||
if (!isImageStarted) {
|
||||
isImageStarted = true;
|
||||
} else {
|
||||
throw new RuntimeException("The imageStarted() was called twice. "
|
||||
+ " Test failed.");
|
||||
}
|
||||
progress.clear();
|
||||
}
|
||||
|
||||
public void thumbnailComplete(ImageWriter source) {
|
||||
System.out.println("Thubnail completed");
|
||||
}
|
||||
|
||||
public void thumbnailProgress(ImageWriter source, float percentageDone) {
|
||||
System.out.println("Thubnail Progress " + percentageDone);
|
||||
}
|
||||
|
||||
public void thumbnailStarted(ImageWriter source, int imageIndex, int thumbnailIndex) {
|
||||
System.out.println("Thubnail started " + imageIndex);
|
||||
}
|
||||
|
||||
public void writeAborted(ImageWriter source) {
|
||||
System.out.println("Writing Aborted");
|
||||
checkProgress();
|
||||
}
|
||||
|
||||
private void checkProgress() {
|
||||
Iterator i = progress.iterator();
|
||||
if (!i.hasNext()) {
|
||||
throw new RuntimeException("progress values list is empty!");
|
||||
}
|
||||
float val = ((Float)i.next()).floatValue();
|
||||
while(i.hasNext()) {
|
||||
float next = ((Float)i.next()).floatValue();
|
||||
if (val >= next) {
|
||||
throw new RuntimeException("progress values do not increase!");
|
||||
}
|
||||
val = next;
|
||||
}
|
||||
isTestPassed = true;
|
||||
System.out.println("Test passed.");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
194
jdk/test/javax/imageio/plugins/bmp/WritingColorChangeTest.java
Normal file
194
jdk/test/javax/imageio/plugins/bmp/WritingColorChangeTest.java
Normal file
@ -0,0 +1,194 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 2017, 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 4892214
|
||||
* @summary Test checks that colors are not changed by the writing/reading in
|
||||
* the BMP format for TYPE_INT_BGR and TYPE_USHORT_555_RGB buffered
|
||||
* images
|
||||
*/
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.ImageWriter;
|
||||
import javax.imageio.stream.ImageOutputStream;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JFrame;
|
||||
|
||||
public class WritingColorChangeTest {
|
||||
private static int width = 100;
|
||||
private static int height = 100;
|
||||
private static Color color = new Color(0x10, 0x20, 0x30);
|
||||
|
||||
static int bufferedImageType[] = {
|
||||
BufferedImage.TYPE_USHORT_565_RGB,
|
||||
BufferedImage.TYPE_INT_BGR,
|
||||
BufferedImage.TYPE_INT_RGB,
|
||||
BufferedImage.TYPE_USHORT_555_RGB,
|
||||
};
|
||||
|
||||
static String bufferedImageStringType[] = {
|
||||
"BufferedImage.TYPE_USHORT_565_RGB",
|
||||
"BufferedImage.TYPE_INT_BGR",
|
||||
"BufferedImage.TYPE_INT_RGB",
|
||||
"BufferedImage.TYPE_USHORT_555_RGB",
|
||||
};
|
||||
private static String writingFormat = "BMP";
|
||||
private static ImageWriter writer = (ImageWriter)ImageIO.getImageWritersByFormatName(writingFormat).next();
|
||||
private int type;
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
//int i = 7; //3; //7;
|
||||
for(int i=0; i<bufferedImageType.length; i++) {
|
||||
System.out.println("\n\nTest for type " + bufferedImageStringType[i]);
|
||||
|
||||
WritingColorChangeTest t1 = new WritingColorChangeTest(bufferedImageType[i]);
|
||||
t1.doTest();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private WritingColorChangeTest(int type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
private void doTest() {
|
||||
BufferedImage src = createTestImage(type);
|
||||
System.out.println("Sample model is " + src.getSampleModel());
|
||||
|
||||
BufferedImage dst = doModification(src);
|
||||
|
||||
Object dstPixel = dst.getRaster().getDataElements(width/2, height/2, null);
|
||||
Object srcPixel = src.getRaster().getDataElements(width/2, height/2, null);
|
||||
|
||||
if (src.getType() == BufferedImage.TYPE_USHORT_555_RGB ||
|
||||
src.getType() == BufferedImage.TYPE_USHORT_565_RGB ) {
|
||||
|
||||
Color cmpColor = new Color(dst.getColorModel().getRed(dstPixel),
|
||||
dst.getColorModel().getGreen(dstPixel),
|
||||
dst.getColorModel().getBlue(dstPixel));
|
||||
BufferedImage cmp = createTestImage(src.getType(), cmpColor);
|
||||
|
||||
Object cmpPixel = cmp.getRaster().getDataElements(width/2, height/2, null);
|
||||
|
||||
dst = cmp;
|
||||
dstPixel = cmpPixel;
|
||||
}
|
||||
|
||||
if ( (src.getColorModel().getRed(srcPixel) != dst.getColorModel().getRed(dstPixel)) ||
|
||||
(src.getColorModel().getGreen(srcPixel) != dst.getColorModel().getGreen(dstPixel)) ||
|
||||
(src.getColorModel().getBlue(srcPixel) != dst.getColorModel().getBlue(dstPixel)) ||
|
||||
(src.getColorModel().getAlpha(srcPixel) != dst.getColorModel().getAlpha(dstPixel)) ) {
|
||||
|
||||
showPixel(src, width/2, height/2);
|
||||
showPixel(dst, width/2, height/2);
|
||||
|
||||
showRes(dst, src);
|
||||
throw new RuntimeException(
|
||||
"Colors are different: " +
|
||||
Integer.toHexString(src.getColorModel().getRGB(srcPixel)) + " and " +
|
||||
Integer.toHexString(dst.getColorModel().getRGB(dstPixel)));
|
||||
}
|
||||
}
|
||||
|
||||
private BufferedImage doModification(BufferedImage src) {
|
||||
try {
|
||||
BufferedImage dst = null;
|
||||
if (!writer.getOriginatingProvider().canEncodeImage(src)) {
|
||||
throw new RuntimeException(writingFormat+" writer does not support the image type "+type);
|
||||
}
|
||||
System.out.println(writingFormat+" writer claims it can encode the image "+type);
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
|
||||
writer.setOutput(ios);
|
||||
writer.write(src);
|
||||
ios.close();
|
||||
baos.close();
|
||||
|
||||
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
|
||||
dst = ImageIO.read(bais);
|
||||
return dst;
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private static void showPixel(BufferedImage src, int x, int y) {
|
||||
System.out.println("Img is " + src);
|
||||
Object p = src.getRaster().getDataElements(x, y, null);
|
||||
System.out.println("RGB: " +
|
||||
Integer.toHexString(src.getColorModel().getRGB(p)));
|
||||
System.out.println("Red: " +
|
||||
Integer.toHexString(src.getColorModel().getRed(p)));
|
||||
System.out.println("Green: " +
|
||||
Integer.toHexString(src.getColorModel().getGreen(p)));
|
||||
System.out.println("Blue: " +
|
||||
Integer.toHexString(src.getColorModel().getBlue(p)));
|
||||
System.out.println("Alpha: " +
|
||||
Integer.toHexString(src.getColorModel().getAlpha(p)));
|
||||
}
|
||||
|
||||
private static BufferedImage createTestImage(int type) {
|
||||
return createTestImage(type, color);
|
||||
}
|
||||
|
||||
private static BufferedImage createTestImage(int type, Color c) {
|
||||
BufferedImage i = new BufferedImage(width, height,
|
||||
type);
|
||||
Graphics2D g = i.createGraphics();
|
||||
|
||||
g.setColor(c);
|
||||
g.fillRect(0, 0, width, height);
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
private static void showRes(final BufferedImage src, final BufferedImage dst) {
|
||||
final int w = src.getWidth()+ dst.getWidth();
|
||||
final int h = Math.max(src.getHeight(), dst.getHeight());
|
||||
|
||||
JFrame f = new JFrame("Test results");
|
||||
f.getContentPane().add( new JComponent() {
|
||||
public Dimension getPreferredSize() {
|
||||
return new Dimension(w,h);
|
||||
}
|
||||
|
||||
public void paintComponent(Graphics g) {
|
||||
g.drawImage(src,0,0, null);
|
||||
g.drawImage(dst, src.getWidth(),0, null);
|
||||
}
|
||||
});
|
||||
f.pack();
|
||||
f.setVisible(true);
|
||||
}
|
||||
}
|
168
jdk/test/javax/imageio/plugins/gif/AnimationTest.java
Normal file
168
jdk/test/javax/imageio/plugins/gif/AnimationTest.java
Normal file
@ -0,0 +1,168 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2017, 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 4339415
|
||||
* @summary Tests that GIF writer plugin writes image sequences correctly
|
||||
*/
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.image.IndexColorModel;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.imageio.IIOImage;
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.ImageReader;
|
||||
import javax.imageio.ImageTypeSpecifier;
|
||||
import javax.imageio.ImageWriteParam;
|
||||
import javax.imageio.ImageWriter;
|
||||
import javax.imageio.metadata.IIOMetadata;
|
||||
import javax.imageio.stream.ImageOutputStream;
|
||||
|
||||
public class AnimationTest {
|
||||
|
||||
BufferedImage img = null;
|
||||
int x, y;
|
||||
int w, h;
|
||||
|
||||
protected static String fname = "animtest.gif";
|
||||
|
||||
public AnimationTest() {
|
||||
w = h = 100;
|
||||
}
|
||||
|
||||
private void initFrame() {
|
||||
if (img != null) {
|
||||
return;
|
||||
}
|
||||
byte r[] = new byte[256];
|
||||
byte g[] = new byte[256];
|
||||
byte b[] = new byte[256];
|
||||
|
||||
for (int i = 0; i < 256; i++) {
|
||||
r[i] = g[i] = b[i] = (byte)0x00;
|
||||
}
|
||||
r[0] = (byte)0x00; g[0] = (byte)0x00; b[0] = (byte)0x00;
|
||||
r[1] = (byte)0xFF; g[1] = (byte)0xFF; b[1] = (byte)0xFF;
|
||||
r[2] = (byte)0xFF; g[3] = (byte)0xFF; b[4] = (byte)0xFF;
|
||||
|
||||
IndexColorModel icm = new IndexColorModel(8, 256,
|
||||
r, g, b);
|
||||
|
||||
img = new BufferedImage(w, h,
|
||||
BufferedImage.TYPE_BYTE_INDEXED,
|
||||
icm);
|
||||
}
|
||||
|
||||
private BufferedImage createNextFrame() {
|
||||
Graphics g = img.createGraphics();
|
||||
g.setColor(Color.white);
|
||||
g.fillRect(0, 0, w, h);
|
||||
|
||||
g.setColor(Color.red);
|
||||
g.drawLine(x, 0, x, h);
|
||||
|
||||
g.setColor(Color.blue);
|
||||
g.drawLine(0, y, w, y);
|
||||
|
||||
x += 2;
|
||||
y += 2;
|
||||
|
||||
x %= w;
|
||||
y %= h;
|
||||
|
||||
return img;
|
||||
}
|
||||
|
||||
ImageWriter writer = null;
|
||||
|
||||
private ImageWriter initWriter() throws IOException {
|
||||
ImageOutputStream ios =
|
||||
ImageIO.createImageOutputStream(new File(fname));
|
||||
writer = ImageIO.getImageWritersByFormatName("GIF").next();
|
||||
|
||||
writer.setOutput(ios);
|
||||
|
||||
return writer;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
AnimationTest t = new AnimationTest();
|
||||
t.initFrame();
|
||||
|
||||
ImageWriter w = t.initWriter();
|
||||
|
||||
ImageWriteParam p = w.getDefaultWriteParam();
|
||||
|
||||
IIOMetadata streamMetadata = w.getDefaultStreamMetadata(p);
|
||||
|
||||
w.prepareWriteSequence(streamMetadata);
|
||||
|
||||
for (int i = 0; i < 50; i++) {
|
||||
BufferedImage f = t.createNextFrame();
|
||||
|
||||
ImageTypeSpecifier type = new ImageTypeSpecifier(f);
|
||||
|
||||
IIOMetadata m = w.getDefaultImageMetadata(type, p);
|
||||
|
||||
w.writeToSequence(new IIOImage(f, null, m), p);
|
||||
}
|
||||
w.endWriteSequence();
|
||||
|
||||
t.checkAnimation();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Test failed.", e);
|
||||
}
|
||||
}
|
||||
|
||||
protected void checkAnimation() throws IOException {
|
||||
ImageReader r = ImageIO.getImageReadersByFormatName("GIF").next();
|
||||
r.setInput(ImageIO.createImageInputStream(new File(fname)));
|
||||
|
||||
int n = r.getNumImages(true);
|
||||
for (int i = 0; i < n; i++) {
|
||||
BufferedImage f = r.read(i);
|
||||
checkFrame(i, f);
|
||||
}
|
||||
System.out.println("Test passed.");
|
||||
}
|
||||
|
||||
protected void checkFrame(int i, BufferedImage f) {
|
||||
int x = 2 * i + 1;
|
||||
for (int y = 0; y < h; y++) {
|
||||
int argb = f.getRGB(x, y);
|
||||
if (argb != 0xffffffff && !(argb == 0xff0000ff && y == 2 * i)) {
|
||||
throw new RuntimeException("Test failed - bad frame");
|
||||
}
|
||||
argb = f.getRGB(y, x);
|
||||
if (argb != 0xffffffff && !(argb == 0xffff0000 && y == 2 * i)) {
|
||||
throw new RuntimeException("Test failed - bad frame");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
100
jdk/test/javax/imageio/plugins/gif/DisableCompressionTest.java
Normal file
100
jdk/test/javax/imageio/plugins/gif/DisableCompressionTest.java
Normal file
@ -0,0 +1,100 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2017, 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 6294683
|
||||
* @summary Test verifies that GIF ImageWriteParam behaves according to spec
|
||||
*/
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.ImageWriteParam;
|
||||
import javax.imageio.ImageWriter;
|
||||
|
||||
public class DisableCompressionTest {
|
||||
|
||||
public static void main(String[] args) {
|
||||
testFormat("GIF");
|
||||
}
|
||||
|
||||
protected static void testFormat(String format) {
|
||||
ImageWriter writer = ImageIO.getImageWritersByFormatName(format).next();
|
||||
if (writer == null) {
|
||||
throw new RuntimeException("No writer for " + format);
|
||||
}
|
||||
|
||||
ImageWriteParam param = writer.getDefaultWriteParam();
|
||||
int[] supported_modes = new int[] {
|
||||
ImageWriteParam.MODE_COPY_FROM_METADATA,
|
||||
ImageWriteParam.MODE_DEFAULT,
|
||||
ImageWriteParam.MODE_EXPLICIT };
|
||||
|
||||
for (int mode : supported_modes) {
|
||||
String mode_name = getModeName(mode);
|
||||
System.out.println("Test mode " + mode_name + "...");
|
||||
// we know that GIF image writer supports compression
|
||||
// and supports any compression mode form supportd_modes
|
||||
// If exception would be thrown here then test failed.
|
||||
param.setCompressionMode(mode);
|
||||
|
||||
// now we are trying to disable compression.
|
||||
// This operation is not supported because GIF image writer
|
||||
// does not provide uncompressed output.
|
||||
// The expected behaviour is that UnsupportedOperationException
|
||||
// will be thrown here and current compression mode will not be
|
||||
// changed.
|
||||
boolean gotException = false;
|
||||
try {
|
||||
param.setCompressionMode(ImageWriteParam.MODE_DISABLED);
|
||||
} catch (UnsupportedOperationException e) {
|
||||
gotException = true;
|
||||
} catch (Throwable e) {
|
||||
throw new RuntimeException("Test failed due to unexpected exception", e);
|
||||
}
|
||||
|
||||
if (!gotException) {
|
||||
throw new RuntimeException("Test failed.");
|
||||
}
|
||||
|
||||
if (param.getCompressionMode() != mode) {
|
||||
throw new RuntimeException("Param state was changed.");
|
||||
}
|
||||
System.out.println("Test passed.");
|
||||
}
|
||||
}
|
||||
|
||||
private static String getModeName(int mode) {
|
||||
switch(mode) {
|
||||
case ImageWriteParam.MODE_COPY_FROM_METADATA:
|
||||
return "MODE_COPY_FROM_METADATA";
|
||||
case ImageWriteParam.MODE_DEFAULT:
|
||||
return "MODE_DEFAULT";
|
||||
case ImageWriteParam.MODE_DISABLED:
|
||||
return "MODE_DISABLED";
|
||||
case ImageWriteParam.MODE_EXPLICIT:
|
||||
return "MODE_EXPLICIT";
|
||||
default:
|
||||
throw new IllegalArgumentException("Unknown mode: " + mode);
|
||||
}
|
||||
}
|
||||
}
|
90
jdk/test/javax/imageio/plugins/gif/EndWriteSequenceTest.java
Normal file
90
jdk/test/javax/imageio/plugins/gif/EndWriteSequenceTest.java
Normal file
@ -0,0 +1,90 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2017, 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 6275366 6275369
|
||||
* @summary Verifies that behaviour of GIFImageWriter.endWriteSequence() is
|
||||
* consistent with specification
|
||||
*/
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.ImageWriter;
|
||||
import javax.imageio.stream.ImageOutputStream;
|
||||
|
||||
public class EndWriteSequenceTest {
|
||||
public static void main(String[] args) throws IOException {
|
||||
ImageWriter w =
|
||||
ImageIO.getImageWritersByFormatName("GIF").next();
|
||||
|
||||
boolean gotCorrectException = false;
|
||||
|
||||
/**
|
||||
* check statement: "Throws: IllegalStateException -
|
||||
* if the output has not been set ...."
|
||||
*/
|
||||
try {
|
||||
w.reset(); // to be shure that output is null
|
||||
w.endWriteSequence();
|
||||
} catch (IllegalStateException e) {
|
||||
gotCorrectException = true;
|
||||
} catch (Throwable e) {
|
||||
throw new RuntimeException("Test failed.", e);
|
||||
}
|
||||
if (!gotCorrectException) {
|
||||
throw new RuntimeException("Test failed.");
|
||||
}
|
||||
|
||||
/**
|
||||
* set up output stream
|
||||
*/
|
||||
ByteArrayOutputStream baos =
|
||||
new ByteArrayOutputStream();
|
||||
|
||||
ImageOutputStream ios =
|
||||
ImageIO.createImageOutputStream(baos);
|
||||
|
||||
w.setOutput(ios);
|
||||
|
||||
/**
|
||||
* check statement: "Throws: IllegalStateException -
|
||||
* if .... prepareWriteSequence has not been called.
|
||||
*/
|
||||
gotCorrectException = false;
|
||||
try {
|
||||
w.endWriteSequence();
|
||||
} catch (IllegalStateException e) {
|
||||
gotCorrectException = true;
|
||||
} catch (Throwable e) {
|
||||
throw new RuntimeException("Test failed.", e);
|
||||
}
|
||||
if (!gotCorrectException) {
|
||||
throw new RuntimeException("Test failed.");
|
||||
}
|
||||
|
||||
System.out.println("Test passed.");
|
||||
}
|
||||
}
|
134
jdk/test/javax/imageio/plugins/gif/IndexingTest.java
Normal file
134
jdk/test/javax/imageio/plugins/gif/IndexingTest.java
Normal file
@ -0,0 +1,134 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2017, 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 4339415
|
||||
* @summary Tests that GIF writer plugin is able to write non-index images
|
||||
*/
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Transparency;
|
||||
import java.awt.color.ColorSpace;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.image.ComponentColorModel;
|
||||
import java.awt.image.DataBuffer;
|
||||
import java.awt.image.WritableRaster;
|
||||
import java.io.File;
|
||||
import java.util.Random;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.ImageWriter;
|
||||
|
||||
public class IndexingTest {
|
||||
|
||||
protected static final String fname = "itest.gif";
|
||||
|
||||
int w;
|
||||
int h;
|
||||
|
||||
Random rnd;
|
||||
|
||||
public IndexingTest() {
|
||||
w = h = 200;
|
||||
rnd = new Random();
|
||||
}
|
||||
|
||||
public void doTest() {
|
||||
ComponentColorModel ccm = createBitmaskColorModel();
|
||||
BufferedImage img = createComponentImage(w, h, ccm);
|
||||
|
||||
try {
|
||||
ImageWriter w = ImageIO.getImageWritersByFormatName("GIF").next();
|
||||
w.setOutput(ImageIO.createImageOutputStream(new File(fname)));
|
||||
w.write(img);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Test failed.", e);
|
||||
}
|
||||
|
||||
BufferedImage dst = null;
|
||||
try {
|
||||
dst = ImageIO.read(new File(fname));
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Test failed.", e);
|
||||
}
|
||||
|
||||
compareImages(img, dst);
|
||||
|
||||
System.out.println("Test passed.");
|
||||
}
|
||||
|
||||
protected static ComponentColorModel createBitmaskColorModel() {
|
||||
ComponentColorModel cm =
|
||||
new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB),
|
||||
true, false, Transparency.BITMASK,
|
||||
DataBuffer.TYPE_BYTE);
|
||||
return cm;
|
||||
}
|
||||
|
||||
protected static BufferedImage createComponentImage(int w, int h,
|
||||
ComponentColorModel cm)
|
||||
{
|
||||
WritableRaster wr = cm.createCompatibleWritableRaster(w, h);
|
||||
|
||||
BufferedImage img = new BufferedImage(cm, wr, false, null);
|
||||
Graphics2D g = img.createGraphics();
|
||||
int width = w / 8;
|
||||
Color[] colors = new Color[8];
|
||||
colors[0] = Color.red;
|
||||
colors[1] = Color.green;
|
||||
colors[2] = Color.blue;
|
||||
colors[3] = Color.white;
|
||||
colors[4] = Color.black;
|
||||
colors[5] = new Color(0x80, 0x80, 0x80, 0x00);
|
||||
colors[6] = Color.yellow;
|
||||
colors[7] = Color.cyan;
|
||||
|
||||
for (int i = 0; i < 8; i++) {
|
||||
g.setColor(colors[i]);
|
||||
g.fillRect(i * width, 0, width, h);
|
||||
}
|
||||
return img;
|
||||
}
|
||||
|
||||
protected void compareImages(BufferedImage src, BufferedImage dst) {
|
||||
int n = 10;
|
||||
while (n-- > 0) {
|
||||
int x = rnd.nextInt(w);
|
||||
int y = rnd.nextInt(h);
|
||||
|
||||
int pSrc = src.getRGB(x, y);
|
||||
int pDst = src.getRGB(x, y);
|
||||
|
||||
if (pSrc != pDst) {
|
||||
throw new RuntimeException("Images are different");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
IndexingTest t = new IndexingTest();
|
||||
t.doTest();
|
||||
}
|
||||
}
|
@ -0,0 +1,108 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2017, 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 6307618
|
||||
* @summary Test verifies that GIF image writer updates the dimension of the
|
||||
* logical screen according to image dimension
|
||||
* @modules java.desktop/com.sun.imageio.plugins.gif
|
||||
*/
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.imageio.IIOImage;
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.ImageReader;
|
||||
import javax.imageio.ImageTypeSpecifier;
|
||||
import javax.imageio.ImageWriteParam;
|
||||
import javax.imageio.ImageWriter;
|
||||
import javax.imageio.metadata.IIOMetadata;
|
||||
import javax.imageio.stream.ImageInputStream;
|
||||
import javax.imageio.stream.ImageOutputStream;
|
||||
|
||||
import com.sun.imageio.plugins.gif.GIFStreamMetadata;
|
||||
|
||||
public class LogicalScreenDimensionTest {
|
||||
public static void main(String[] args) throws IOException {
|
||||
String format = "GIF";
|
||||
ImageWriter writer =
|
||||
ImageIO.getImageWritersByFormatName(format).next();
|
||||
if (writer == null) {
|
||||
throw new RuntimeException("No available writers for " + format);
|
||||
}
|
||||
|
||||
BufferedImage img = createTestImage(100, 100, BufferedImage.TYPE_BYTE_GRAY);
|
||||
|
||||
ImageWriteParam p = writer.getDefaultWriteParam();
|
||||
ImageTypeSpecifier type =
|
||||
ImageTypeSpecifier.createFromRenderedImage(img);
|
||||
IIOMetadata inImageMetadata =
|
||||
writer.getDefaultImageMetadata(type, p);
|
||||
|
||||
IIOMetadata inStreamMetadata = writer.getDefaultStreamMetadata(p);
|
||||
|
||||
// write and read image
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
|
||||
ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
|
||||
writer.setOutput(ios);
|
||||
|
||||
writer.write(inStreamMetadata, new IIOImage(img, null, inImageMetadata), p);
|
||||
|
||||
ios.flush();
|
||||
ios.close();
|
||||
|
||||
// read result
|
||||
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
|
||||
ImageInputStream iis = ImageIO.createImageInputStream(bais);
|
||||
ImageReader reader = ImageIO.getImageReader(writer);
|
||||
reader.setInput(iis);
|
||||
|
||||
IIOMetadata outStreamMetadata = reader.getStreamMetadata();
|
||||
|
||||
GIFStreamMetadata gifStreamMetadata = (GIFStreamMetadata)outStreamMetadata;
|
||||
|
||||
if (gifStreamMetadata.logicalScreenWidth != img.getWidth() ||
|
||||
gifStreamMetadata.logicalScreenHeight != img.getHeight()) {
|
||||
throw new RuntimeException("Test failed due to wrong logical screen dimension.");
|
||||
}
|
||||
}
|
||||
|
||||
private static BufferedImage createTestImage(int w, int h, int type) {
|
||||
BufferedImage res = new BufferedImage(w, h, type);
|
||||
Graphics2D g = res.createGraphics();
|
||||
g.setColor(Color.white);
|
||||
g.fillRect(0, 0, w, h);
|
||||
g.setColor(Color.black);
|
||||
g.fillRect(w/4, h/4, w/2, h/2);
|
||||
|
||||
|
||||
return res;
|
||||
}
|
||||
}
|
123
jdk/test/javax/imageio/plugins/gif/OddPaletteTest.java
Normal file
123
jdk/test/javax/imageio/plugins/gif/OddPaletteTest.java
Normal file
@ -0,0 +1,123 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2017, 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 6275211 6276621
|
||||
* @summary Tests that GIF writer plugin is able to write indexed images if
|
||||
* palette size is not a power of two
|
||||
*/
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.image.IndexColorModel;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.ImageWriter;
|
||||
import javax.imageio.stream.ImageOutputStream;
|
||||
|
||||
public class OddPaletteTest {
|
||||
|
||||
private static int w = 100;
|
||||
private static int h = 100;
|
||||
|
||||
public static void main(String[] args) {
|
||||
BufferedImage[] srcs = new BufferedImage[2];
|
||||
srcs[0] = createTestImage(7); // bug 6275211
|
||||
srcs[1] = createTestImage(1); // bug 6276621
|
||||
|
||||
for (int i = 0; i < srcs.length; i++) {
|
||||
doTest(srcs[i]);
|
||||
}
|
||||
}
|
||||
|
||||
private static void doTest(BufferedImage src) {
|
||||
ImageWriter w = ImageIO.getImageWritersByFormatName("GIF").next();
|
||||
if (w == null) {
|
||||
throw new RuntimeException("No writer available!");
|
||||
}
|
||||
|
||||
try {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
|
||||
w.setOutput(ios);
|
||||
w.write(src);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Test failed.", e);
|
||||
} catch (IllegalArgumentException e) {
|
||||
throw new RuntimeException("Test failed.", e);
|
||||
}
|
||||
}
|
||||
|
||||
private static BufferedImage createTestImage(int paletteSize) {
|
||||
byte[] r = new byte[paletteSize];
|
||||
byte[] g = new byte[paletteSize];
|
||||
byte[] b = new byte[paletteSize];
|
||||
|
||||
int shift = 256 / paletteSize;
|
||||
for (int i = 0; i < paletteSize; i++) {
|
||||
r[i] = g[i] = b[i] = (byte)(shift * i);
|
||||
}
|
||||
|
||||
int numBits = getNumBits(paletteSize);
|
||||
|
||||
System.out.println("num of bits " + numBits);
|
||||
|
||||
IndexColorModel icm =
|
||||
new IndexColorModel(numBits, paletteSize, r, g, b);
|
||||
|
||||
BufferedImage img = new BufferedImage(w, h,
|
||||
BufferedImage.TYPE_BYTE_INDEXED,
|
||||
icm);
|
||||
Graphics2D g2d = img.createGraphics();
|
||||
g2d.setColor(Color.white);
|
||||
g2d.fillRect(0, 0, w, h);
|
||||
g2d.setColor(Color.black);
|
||||
g2d.drawLine(0, 0, w, h);
|
||||
g2d.drawLine(0, h, w, 0);
|
||||
|
||||
return img;
|
||||
}
|
||||
|
||||
private static int getNumBits(int paletteSize) {
|
||||
if (paletteSize < 0) {
|
||||
throw new IllegalArgumentException("negative palette size: " +
|
||||
paletteSize);
|
||||
}
|
||||
if (paletteSize < 2) {
|
||||
return 1;
|
||||
}
|
||||
int numBits = 0;
|
||||
|
||||
paletteSize--;
|
||||
|
||||
while (paletteSize > 0) {
|
||||
numBits++;
|
||||
paletteSize = paletteSize >> 1;
|
||||
}
|
||||
return numBits;
|
||||
}
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2017, 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 6284538
|
||||
* @summary Test verifies whether IllegalStateException is thrown if the output
|
||||
* stream have not set to the GIF image writer instance
|
||||
*/
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.ImageWriteParam;
|
||||
import javax.imageio.ImageWriter;
|
||||
import javax.imageio.metadata.IIOMetadata;
|
||||
|
||||
public class PrepareWriteSequenceTest {
|
||||
public static void main(String[] args) throws IOException {
|
||||
String format = "GIF";
|
||||
ImageWriter writer = ImageIO.getImageWritersByFormatName(format).next();
|
||||
|
||||
ImageWriteParam param = writer.getDefaultWriteParam();
|
||||
|
||||
IIOMetadata streamMetadata = writer.getDefaultStreamMetadata(param);
|
||||
|
||||
boolean gotException = false;
|
||||
try {
|
||||
writer.prepareWriteSequence(streamMetadata);
|
||||
} catch (IllegalStateException e) {
|
||||
gotException = true;
|
||||
System.out.println("Test passed.");
|
||||
e.printStackTrace(System.out);
|
||||
}
|
||||
|
||||
if (!gotException) {
|
||||
throw new RuntimeException("Test failed.");
|
||||
}
|
||||
}
|
||||
}
|
200
jdk/test/javax/imageio/plugins/gif/RGBAnimationTest.java
Normal file
200
jdk/test/javax/imageio/plugins/gif/RGBAnimationTest.java
Normal file
@ -0,0 +1,200 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2017, 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 6324581
|
||||
* @summary Test verifies that RGB images are written to animated GIF image use
|
||||
* local color table if image palette is not equals to the global color
|
||||
* table
|
||||
* @modules java.desktop/com.sun.imageio.plugins.gif
|
||||
*/
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.imageio.IIOImage;
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.ImageReader;
|
||||
import javax.imageio.ImageTypeSpecifier;
|
||||
import javax.imageio.ImageWriteParam;
|
||||
import javax.imageio.ImageWriter;
|
||||
import javax.imageio.metadata.IIOMetadata;
|
||||
import javax.imageio.stream.ImageOutputStream;
|
||||
|
||||
import com.sun.imageio.plugins.gif.GIFImageMetadata;
|
||||
|
||||
public class RGBAnimationTest {
|
||||
protected static String format = "GIF";
|
||||
protected static boolean doSave = true;
|
||||
|
||||
Frame[] frames;
|
||||
ImageWriter writer;
|
||||
ImageReader reader;
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
RGBAnimationTest test = new RGBAnimationTest();
|
||||
test.doTest();
|
||||
}
|
||||
/** Creates a new instance of RGBAnimationTest */
|
||||
public RGBAnimationTest() {
|
||||
frames = new Frame[4];
|
||||
|
||||
|
||||
frames[0] = new Frame(new Color[] {Color.red, Color.green});
|
||||
frames[1] = new Frame(new Color[] {Color.green, Color.cyan});
|
||||
frames[2] = new Frame(new Color[] {Color.cyan, Color.yellow});
|
||||
frames[3] = new Frame(new Color[] {Color.yellow, Color.red});
|
||||
|
||||
writer = ImageIO.getImageWritersByFormatName(format).next();
|
||||
reader = ImageIO.getImageReadersByFormatName(format).next();
|
||||
}
|
||||
|
||||
public void doTest() throws IOException {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
writer.reset();
|
||||
ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
|
||||
writer.setOutput(ios);
|
||||
|
||||
ImageWriteParam wparam = prepareWriteParam();
|
||||
|
||||
IIOMetadata streamMetadata = prepareStreamMetadata(wparam);
|
||||
|
||||
writer.prepareWriteSequence(streamMetadata);
|
||||
|
||||
for (int i = 0; i < frames.length; i++) {
|
||||
BufferedImage src = frames[i].getImage();
|
||||
IIOMetadata imageMetadata = prepareImageMetadata(i, src, wparam);
|
||||
IIOImage img = new IIOImage(src, null, imageMetadata);
|
||||
|
||||
writer.writeToSequence(img, wparam);
|
||||
}
|
||||
writer.endWriteSequence();
|
||||
ios.flush();
|
||||
ios.close();
|
||||
|
||||
if (doSave) {
|
||||
File f = File.createTempFile("wr_test_", "." + format, new File("."));
|
||||
System.out.println("Save to file: " + f.getCanonicalPath());
|
||||
FileOutputStream fos = new FileOutputStream(f);
|
||||
fos.write(baos.toByteArray());
|
||||
fos.flush();
|
||||
fos.close();
|
||||
}
|
||||
// read result
|
||||
reader.reset();
|
||||
ByteArrayInputStream bais =
|
||||
new ByteArrayInputStream(baos.toByteArray());
|
||||
reader.setInput(ImageIO.createImageInputStream(bais));
|
||||
|
||||
int minIndex = reader.getMinIndex();
|
||||
int numImages = reader.getNumImages(true);
|
||||
|
||||
for (int i = 0; i < numImages; i++) {
|
||||
BufferedImage dst = reader.read(i + minIndex);
|
||||
frames[i].checkResult(dst);
|
||||
}
|
||||
}
|
||||
|
||||
protected IIOMetadata prepareImageMetadata(int i, BufferedImage img, ImageWriteParam wparam) {
|
||||
GIFImageMetadata idata = (GIFImageMetadata)
|
||||
writer.getDefaultImageMetadata(ImageTypeSpecifier.createFromRenderedImage(img), wparam);
|
||||
|
||||
idata.delayTime = 100;
|
||||
idata.disposalMethod = 0;
|
||||
idata.transparentColorFlag = false;
|
||||
|
||||
if (i == 0) {
|
||||
ArrayList<byte[]> appIDs = new ArrayList<byte[]>();
|
||||
appIDs.add(new String("NETSCAPE").getBytes());
|
||||
ArrayList<byte[]> authCodes = new ArrayList<byte[]>();
|
||||
authCodes.add(new String("2.0").getBytes());
|
||||
ArrayList<byte[]> appData = new ArrayList<byte[]>();
|
||||
byte[] authData = {1, 0, 0};
|
||||
appData.add(authData);
|
||||
|
||||
idata.applicationIDs = appIDs;
|
||||
idata.authenticationCodes = authCodes;
|
||||
idata.applicationData = appData;
|
||||
}
|
||||
return idata;
|
||||
}
|
||||
|
||||
protected ImageWriteParam prepareWriteParam() {
|
||||
return writer.getDefaultWriteParam();
|
||||
}
|
||||
|
||||
protected IIOMetadata prepareStreamMetadata(ImageWriteParam wparam) {
|
||||
return writer.getDefaultStreamMetadata(wparam);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class Frame {
|
||||
protected static int type = BufferedImage.TYPE_INT_RGB;
|
||||
protected static int dx = 100;
|
||||
protected static int h = 100;
|
||||
|
||||
protected Color[] colors;
|
||||
protected BufferedImage img;
|
||||
|
||||
public Frame(Color[] colors) {
|
||||
this.colors = colors;
|
||||
img = null;
|
||||
}
|
||||
|
||||
public BufferedImage getImage() {
|
||||
if (img == null) {
|
||||
img = new BufferedImage(dx * colors.length, h, type);
|
||||
Graphics2D g = img.createGraphics();
|
||||
for (int i = 0; i < colors.length; i++) {
|
||||
g.setColor(colors[i]);
|
||||
g.fillRect(dx * i, 0, dx, h);
|
||||
}
|
||||
}
|
||||
return img;
|
||||
}
|
||||
|
||||
public void checkResult(BufferedImage dst) {
|
||||
int y = h / 2;
|
||||
int x = dx / 2;
|
||||
for (int i = 0; i < colors.length; i++) {
|
||||
|
||||
int srcRgb = img.getRGB(i * dx + x, y);
|
||||
int dstRgb = dst.getRGB(i * dx + x, y);
|
||||
|
||||
if (srcRgb != dstRgb) {
|
||||
throw new RuntimeException("Test failed due to color difference: " +
|
||||
Integer.toHexString(dstRgb) + " instead of " +
|
||||
Integer.toHexString(srcRgb));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
116
jdk/test/javax/imageio/plugins/gif/RGBImageTest.java
Normal file
116
jdk/test/javax/imageio/plugins/gif/RGBImageTest.java
Normal file
@ -0,0 +1,116 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2017, 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 6286578
|
||||
* @summary Test verifies that RGB images does not convert to gray-scaled if
|
||||
* default image metadata is used
|
||||
*/
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.imageio.IIOImage;
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.ImageReader;
|
||||
import javax.imageio.ImageTypeSpecifier;
|
||||
import javax.imageio.ImageWriteParam;
|
||||
import javax.imageio.ImageWriter;
|
||||
import javax.imageio.metadata.IIOMetadata;
|
||||
import javax.imageio.stream.ImageInputStream;
|
||||
import javax.imageio.stream.ImageOutputStream;
|
||||
|
||||
public class RGBImageTest {
|
||||
|
||||
Color[] usedColors = {
|
||||
Color.red, Color.green, Color.blue, Color.yellow,
|
||||
Color.cyan, Color.magenta, Color.white, Color.black };
|
||||
|
||||
BufferedImage src = null;
|
||||
int dx= 20;
|
||||
int height = 100;
|
||||
|
||||
protected BufferedImage getSrc() {
|
||||
if (src == null) {
|
||||
src = new BufferedImage(dx * usedColors.length, height,
|
||||
BufferedImage.TYPE_INT_RGB);
|
||||
Graphics g = src.createGraphics();
|
||||
for (int i = 0; i < usedColors.length; i++) {
|
||||
g.setColor(usedColors[i]);
|
||||
g.fillRect(dx * i, 0, dx, height);
|
||||
}
|
||||
}
|
||||
return src;
|
||||
}
|
||||
|
||||
protected void doTest() throws IOException {
|
||||
BufferedImage biSrc = getSrc();
|
||||
|
||||
ImageWriter writer = ImageIO.getImageWritersByFormatName("GIF").next();
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
|
||||
writer.setOutput(ios);
|
||||
|
||||
ImageWriteParam writeParam = writer.getDefaultWriteParam();
|
||||
IIOMetadata imageMetadata =
|
||||
writer.getDefaultImageMetadata(new ImageTypeSpecifier(biSrc), writeParam);
|
||||
|
||||
IIOMetadata streamMetadata = writer.getDefaultStreamMetadata(writeParam);
|
||||
|
||||
IIOImage iioImg = new IIOImage(biSrc, null, imageMetadata);
|
||||
writer.write(streamMetadata, iioImg, writeParam);
|
||||
ios.close();
|
||||
|
||||
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
|
||||
ImageInputStream iis = ImageIO.createImageInputStream(bais);
|
||||
ImageReader reader = ImageIO.getImageReader(writer);
|
||||
reader.setInput(iis);
|
||||
BufferedImage dst = reader.read(0);
|
||||
|
||||
// do test
|
||||
int x = dx / 2;
|
||||
int y = height / 2;
|
||||
|
||||
for (int i = 0; i < usedColors.length; i++) {
|
||||
int dstRgb = dst.getRGB(x, y);
|
||||
System.out.println("dstColor: " + Integer.toHexString(dstRgb));
|
||||
int srcRgb = usedColors[i].getRGB();
|
||||
System.out.println("srcColor: " + Integer.toHexString(srcRgb));
|
||||
if (dstRgb != srcRgb) {
|
||||
throw new RuntimeException("wrong color " + i + ": " + Integer.toHexString(dstRgb));
|
||||
}
|
||||
x += dx;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
RGBImageTest t = new RGBImageTest();
|
||||
t.doTest();
|
||||
}
|
||||
}
|
78
jdk/test/javax/imageio/plugins/gif/StreamMetadataTest.java
Normal file
78
jdk/test/javax/imageio/plugins/gif/StreamMetadataTest.java
Normal file
@ -0,0 +1,78 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2017, 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 6319418
|
||||
* @summary Test verifies that GIF stream metadata could be merged with tree
|
||||
* representation for all supported formats
|
||||
*/
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.ImageWriteParam;
|
||||
import javax.imageio.ImageWriter;
|
||||
import javax.imageio.metadata.IIOInvalidTreeException;
|
||||
import javax.imageio.metadata.IIOMetadata;
|
||||
|
||||
import org.w3c.dom.Node;
|
||||
|
||||
public class StreamMetadataTest {
|
||||
protected static final String format = "GIF";
|
||||
|
||||
ImageWriter writer = null;
|
||||
IIOMetadata streamData = null;
|
||||
ImageWriteParam wparam = null;
|
||||
boolean doMerge = true;
|
||||
|
||||
public StreamMetadataTest() {
|
||||
writer = ImageIO.getImageWritersByFormatName(format).next();
|
||||
wparam = writer.getDefaultWriteParam();
|
||||
streamData = writer.getDefaultStreamMetadata(wparam);
|
||||
}
|
||||
|
||||
public void doTest() throws IIOInvalidTreeException {
|
||||
if (streamData == null) {
|
||||
throw new RuntimeException("No stream metadata available");
|
||||
}
|
||||
|
||||
String[] formatNames = streamData.getMetadataFormatNames();
|
||||
for(String fname : formatNames) {
|
||||
System.out.println("Format name: " + fname);
|
||||
Node root = streamData.getAsTree(fname);
|
||||
if (streamData.isReadOnly()) {
|
||||
throw new RuntimeException("Stream metadata is readonly!");
|
||||
}
|
||||
streamData.reset();
|
||||
streamData.mergeTree(fname, root);
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String args[]) {
|
||||
StreamMetadataTest test = new StreamMetadataTest();
|
||||
try {
|
||||
test.doTest();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Test failed.", e);
|
||||
}
|
||||
}
|
||||
}
|
145
jdk/test/javax/imageio/plugins/gif/TransparencyTest.java
Normal file
145
jdk/test/javax/imageio/plugins/gif/TransparencyTest.java
Normal file
@ -0,0 +1,145 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2017, 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 4339415
|
||||
* @summary Tests that GIF writer plugin is able to write images with BITMASK
|
||||
* transparency
|
||||
*/
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.image.IndexColorModel;
|
||||
import java.awt.image.WritableRaster;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.ImageWriter;
|
||||
|
||||
public class TransparencyTest {
|
||||
|
||||
protected static final String fname = "ttest.gif";
|
||||
protected BufferedImage src;
|
||||
protected BufferedImage dst;
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Test indexed image...");
|
||||
IndexColorModel icm = createIndexedBitmaskColorModel();
|
||||
BufferedImage img = createIndexedImage(200, 200, icm);
|
||||
TransparencyTest t = new TransparencyTest(img);
|
||||
|
||||
try {
|
||||
t.doTest();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Test failed!", e);
|
||||
}
|
||||
System.out.println("Test passed.");
|
||||
}
|
||||
|
||||
protected TransparencyTest(BufferedImage src) {
|
||||
this.src = src;
|
||||
}
|
||||
|
||||
protected void doTest() throws IOException {
|
||||
int w = src.getWidth();
|
||||
int h = src.getHeight();
|
||||
|
||||
System.out.println("Write image...");
|
||||
try {
|
||||
ImageWriter writer =
|
||||
ImageIO.getImageWritersByFormatName("GIF").next();
|
||||
writer.setOutput(ImageIO.createImageOutputStream(new File(fname)));
|
||||
writer.write(src);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Test failed.", e);
|
||||
}
|
||||
System.out.println("Read image....");
|
||||
dst = ImageIO.read(new File(fname));
|
||||
|
||||
BufferedImage tmp = new BufferedImage(w, 2 * h,
|
||||
BufferedImage.TYPE_INT_ARGB);
|
||||
Graphics2D g = tmp.createGraphics();
|
||||
g.setColor(Color.pink);
|
||||
g.fillRect(0, 0, tmp.getWidth(), tmp.getHeight());
|
||||
|
||||
g.drawImage(src, 0, 0, null);
|
||||
g.drawImage(dst, 0, h, null);
|
||||
|
||||
int width = w / 8;
|
||||
int x = 5 * width + width / 2;
|
||||
for (int y = 0; y < h; y++) {
|
||||
int argb = tmp.getRGB(x, y);
|
||||
if (Color.pink.getRGB() != argb) {
|
||||
throw new RuntimeException("Bad color at " + x + "," + y +
|
||||
" - " + Integer.toHexString(argb));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected static BufferedImage createIndexedImage(int w, int h,
|
||||
IndexColorModel icm)
|
||||
{
|
||||
BufferedImage img = new BufferedImage(w, h,
|
||||
BufferedImage.TYPE_BYTE_INDEXED,
|
||||
icm);
|
||||
|
||||
int mapSize = icm.getMapSize();
|
||||
int width = w / mapSize;
|
||||
|
||||
WritableRaster wr = img.getRaster();
|
||||
for (int i = 0; i < mapSize; i++) {
|
||||
for (int y = 0; y < h; y++) {
|
||||
for (int x = 0; x < width; x++) {
|
||||
wr.setSample(i * width + x, y, 0, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
return img;
|
||||
}
|
||||
|
||||
protected static IndexColorModel createIndexedBitmaskColorModel() {
|
||||
int paletteSize = 8;
|
||||
byte[] red = new byte[paletteSize];
|
||||
byte[] green = new byte[paletteSize];
|
||||
byte[] blue = new byte[paletteSize];
|
||||
|
||||
red[0] = (byte)0xff; green[0] = (byte)0x00; blue[0] = (byte)0x00;
|
||||
red[1] = (byte)0x00; green[1] = (byte)0xff; blue[1] = (byte)0x00;
|
||||
red[2] = (byte)0x00; green[2] = (byte)0x00; blue[2] = (byte)0xff;
|
||||
red[3] = (byte)0xff; green[3] = (byte)0xff; blue[3] = (byte)0xff;
|
||||
red[4] = (byte)0x00; green[4] = (byte)0x00; blue[4] = (byte)0x00;
|
||||
red[5] = (byte)0x80; green[5] = (byte)0x80; blue[5] = (byte)0x80;
|
||||
red[6] = (byte)0xff; green[6] = (byte)0xff; blue[6] = (byte)0x00;
|
||||
red[7] = (byte)0x00; green[7] = (byte)0xff; blue[7] = (byte)0xff;
|
||||
|
||||
int numBits = 3;
|
||||
|
||||
IndexColorModel icm = new IndexColorModel(numBits, paletteSize,
|
||||
red, green, blue, 5);
|
||||
|
||||
return icm;
|
||||
}
|
||||
}
|
@ -0,0 +1,77 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2017, 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 6294363
|
||||
* @summary Test verifies that creation of tree representation of the native
|
||||
* image metadata for USHORT_GRAY images does not cause the
|
||||
* OutOfMemoryError
|
||||
* @run main/othervm -Xms32M -Xmx32M UshortOutOfMemoryTest
|
||||
*/
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.ImageTypeSpecifier;
|
||||
import javax.imageio.ImageWriteParam;
|
||||
import javax.imageio.ImageWriter;
|
||||
import javax.imageio.metadata.IIOMetadata;
|
||||
|
||||
public class UshortOutOfMemoryTest {
|
||||
private int type;
|
||||
private ImageWriter w;
|
||||
|
||||
public UshortOutOfMemoryTest(int type) {
|
||||
this.type = type;
|
||||
w = ImageIO.getImageWritersByFormatName("GIF").next();
|
||||
}
|
||||
|
||||
public void testGetAsTree() {
|
||||
ImageWriteParam p = w.getDefaultWriteParam();
|
||||
IIOMetadata m =
|
||||
w.getDefaultImageMetadata(ImageTypeSpecifier.createFromBufferedImageType(type), p);
|
||||
|
||||
String format = m.getNativeMetadataFormatName();
|
||||
System.out.println("native format: " + format);
|
||||
|
||||
int count = 0;
|
||||
try {
|
||||
while (count < 100) {
|
||||
System.out.println(" test " + count++);
|
||||
m.getAsTree(format);
|
||||
}
|
||||
} catch (OutOfMemoryError e) {
|
||||
System.gc();
|
||||
throw new RuntimeException("Test failed. Number of performed operations: " + count, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
UshortOutOfMemoryTest t = new UshortOutOfMemoryTest(
|
||||
BufferedImage.TYPE_USHORT_GRAY);
|
||||
t.testGetAsTree();
|
||||
}
|
||||
}
|
81
jdk/test/javax/imageio/plugins/gif/WriteMetadataTest.java
Normal file
81
jdk/test/javax/imageio/plugins/gif/WriteMetadataTest.java
Normal file
@ -0,0 +1,81 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2017, 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 6287880
|
||||
* @summary Test verifies that default metadata for stream and image returned by
|
||||
* GIFImageWriter can be modified by the tree representation
|
||||
*/
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.ImageTypeSpecifier;
|
||||
import javax.imageio.ImageWriteParam;
|
||||
import javax.imageio.ImageWriter;
|
||||
import javax.imageio.metadata.IIOInvalidTreeException;
|
||||
import javax.imageio.metadata.IIOMetadata;
|
||||
import javax.imageio.metadata.IIOMetadataNode;
|
||||
|
||||
public class WriteMetadataTest {
|
||||
private static String format = "GIF";
|
||||
|
||||
public static void main(String[] args) {
|
||||
ImageWriter w = ImageIO.getImageWritersByFormatName(format).next();
|
||||
if (w == null) {
|
||||
throw new RuntimeException("No available writers for format " + format);
|
||||
}
|
||||
ImageWriteParam p = w.getDefaultWriteParam();
|
||||
|
||||
ImageTypeSpecifier t =
|
||||
ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB);
|
||||
|
||||
IIOMetadata m = w.getDefaultImageMetadata(t, p);
|
||||
System.out.println("Default image metadata is " + m);
|
||||
testWritableMetadata(m);
|
||||
|
||||
IIOMetadata sm = w.getDefaultStreamMetadata(p);
|
||||
System.out.println("Default stream metadata is " + sm);
|
||||
testWritableMetadata(sm);
|
||||
}
|
||||
|
||||
public static void testWritableMetadata(IIOMetadata m) {
|
||||
String nativeFormatName =
|
||||
m.getNativeMetadataFormatName();
|
||||
System.out.println("Format: " + nativeFormatName);
|
||||
IIOMetadataNode root = (IIOMetadataNode)m.getAsTree(nativeFormatName);
|
||||
if (m.isReadOnly()) {
|
||||
throw new RuntimeException("Metadata is read only!");
|
||||
}
|
||||
try {
|
||||
m.setFromTree(nativeFormatName, root);
|
||||
} catch (IIOInvalidTreeException e) {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException("Test failed!", e);
|
||||
} catch (IllegalStateException e) {
|
||||
throw new RuntimeException("Test failed!", e);
|
||||
}
|
||||
System.out.println("Test passed.\n\n");
|
||||
}
|
||||
}
|
79
jdk/test/javax/imageio/plugins/gif/WriterResetTest.java
Normal file
79
jdk/test/javax/imageio/plugins/gif/WriterResetTest.java
Normal file
@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2017, 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 6275251
|
||||
* @summary Verifies that GIF image writer throws IllegalStateException if
|
||||
* assigned output stream was cleared by reset() method
|
||||
*/
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.ImageWriter;
|
||||
import javax.imageio.stream.ImageOutputStream;
|
||||
|
||||
public class WriterResetTest {
|
||||
public static void main(String[] args) throws IOException {
|
||||
ImageWriter w = ImageIO.getImageWritersByFormatName("GIF").next();
|
||||
if (w == null) {
|
||||
throw new RuntimeException("No writers available!");
|
||||
}
|
||||
|
||||
ByteArrayOutputStream baos =
|
||||
new ByteArrayOutputStream();
|
||||
|
||||
ImageOutputStream ios =
|
||||
ImageIO.createImageOutputStream(baos);
|
||||
|
||||
w.setOutput(ios);
|
||||
|
||||
BufferedImage img = createTestImage();
|
||||
|
||||
try {
|
||||
w.reset();
|
||||
w.write(img);
|
||||
} catch (IllegalStateException e) {
|
||||
System.out.println("Test passed");
|
||||
} catch (Throwable e) {
|
||||
throw new RuntimeException("Test failed", e);
|
||||
}
|
||||
}
|
||||
|
||||
private static BufferedImage createTestImage() {
|
||||
BufferedImage img = new BufferedImage(100, 100,
|
||||
BufferedImage.TYPE_INT_RGB);
|
||||
Graphics2D g = img.createGraphics();
|
||||
g.setColor(Color.white);
|
||||
g.fillRect(0, 0, 100, 100);
|
||||
g.setColor(Color.black);
|
||||
g.fillRect(20, 20, 60, 60);
|
||||
|
||||
return img;
|
||||
}
|
||||
}
|
157
jdk/test/javax/imageio/plugins/gif/WriterReuseTest.java
Normal file
157
jdk/test/javax/imageio/plugins/gif/WriterReuseTest.java
Normal file
@ -0,0 +1,157 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2017, 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 6283089
|
||||
* @summary Test verifies that abort flag is cleared by the next write() call
|
||||
*/
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.imageio.IIOImage;
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.ImageWriteParam;
|
||||
import javax.imageio.ImageWriter;
|
||||
import javax.imageio.event.IIOWriteProgressListener;
|
||||
import javax.imageio.metadata.IIOMetadata;
|
||||
import javax.imageio.stream.ImageOutputStream;
|
||||
|
||||
public class WriterReuseTest implements IIOWriteProgressListener {
|
||||
|
||||
boolean isFirst = true;
|
||||
boolean isWritingCompleted = false;
|
||||
boolean isWritingAborted = false;
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
doTest(false);
|
||||
doTest(true);
|
||||
}
|
||||
|
||||
public static void doTest(boolean writeSequence) throws IOException {
|
||||
String format = "GIF";
|
||||
ImageWriter writer =
|
||||
ImageIO.getImageWritersByFormatName(format).next();
|
||||
if (writer == null) {
|
||||
throw new RuntimeException("No writer available for " + format);
|
||||
}
|
||||
|
||||
BufferedImage img = createTestImage();
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
|
||||
writer.setOutput(ios);
|
||||
|
||||
WriterReuseTest t = new WriterReuseTest();
|
||||
writer.addIIOWriteProgressListener(t);
|
||||
|
||||
ImageWriteParam param = writer.getDefaultWriteParam();
|
||||
IIOMetadata streamMetadata = writer.getDefaultStreamMetadata(param);
|
||||
IIOImage iioImg = new IIOImage(img, null, null);
|
||||
if (writeSequence) {
|
||||
writer.prepareWriteSequence(streamMetadata);
|
||||
writer.writeToSequence(iioImg, param);
|
||||
} else {
|
||||
writer.write(img);
|
||||
}
|
||||
|
||||
if (!t.isWritingAborted || t.isWritingCompleted) {
|
||||
throw new RuntimeException("Test failed.");
|
||||
}
|
||||
t.reset();
|
||||
|
||||
// next attempt after abort
|
||||
ImageOutputStream ios2 =
|
||||
ImageIO.createImageOutputStream(new ByteArrayOutputStream());
|
||||
writer.setOutput(ios2);
|
||||
if (writeSequence) {
|
||||
writer.writeToSequence(iioImg, param);
|
||||
} else {
|
||||
writer.write(img);
|
||||
}
|
||||
|
||||
if (t.isWritingAborted || !t.isWritingCompleted) {
|
||||
throw new RuntimeException("Test failed.");
|
||||
}
|
||||
System.out.println("Test passed.");
|
||||
}
|
||||
|
||||
public static BufferedImage createTestImage() {
|
||||
BufferedImage img = new BufferedImage(100, 100, BufferedImage.TYPE_BYTE_INDEXED);
|
||||
Graphics g = img.createGraphics();
|
||||
g.setColor(Color.black);
|
||||
g.fillRect(0, 0, 100, 100);
|
||||
|
||||
g.setColor(Color.white);
|
||||
g.fillRect(10, 10, 80, 80);
|
||||
|
||||
return img;
|
||||
}
|
||||
|
||||
public WriterReuseTest() {
|
||||
isFirst = true;
|
||||
reset();
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
isWritingAborted = false;
|
||||
isWritingCompleted = false;
|
||||
}
|
||||
|
||||
public void imageComplete(ImageWriter source) {
|
||||
System.out.println("Image Completed");
|
||||
this.isWritingCompleted = true;
|
||||
}
|
||||
|
||||
public void imageProgress(ImageWriter source, float percentageDone) {
|
||||
System.out.println("Image Progress "+percentageDone);
|
||||
if (percentageDone > 50 && isFirst) {
|
||||
isFirst = false;
|
||||
source.abort();
|
||||
}
|
||||
}
|
||||
|
||||
public void imageStarted(ImageWriter source, int imageIndex) {
|
||||
System.out.println("Image Started "+imageIndex);
|
||||
}
|
||||
|
||||
public void thumbnailComplete(ImageWriter source) {
|
||||
System.out.println("Thubnail completed");
|
||||
}
|
||||
|
||||
public void thumbnailProgress(ImageWriter source, float percentageDone) {
|
||||
System.out.println("Thubnail Progress " + percentageDone);
|
||||
}
|
||||
|
||||
public void thumbnailStarted(ImageWriter source, int imageIndex, int thumbnailIndex) {
|
||||
System.out.println("Thubnail started " + imageIndex);
|
||||
}
|
||||
|
||||
public void writeAborted(ImageWriter source) {
|
||||
System.out.println("Writing Aborted");
|
||||
this.isWritingAborted = true;
|
||||
}
|
||||
}
|
93
jdk/test/javax/imageio/plugins/jpeg/ByteBinaryTest.java
Normal file
93
jdk/test/javax/imageio/plugins/jpeg/ByteBinaryTest.java
Normal file
@ -0,0 +1,93 @@
|
||||
/*
|
||||
* Copyright (c) 2002, 2017, 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 4450894
|
||||
* @summary Tests if the JPEG writer properly encodes IndexColorModel images
|
||||
* that contain less than 8-bit indices (such as TYPE_BYTE_BINARY)
|
||||
*/
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
public class ByteBinaryTest {
|
||||
|
||||
private static final int[] expectedVals =
|
||||
{ 0xffffffff, 0xff000000, 0xffffffff };
|
||||
|
||||
public static void main(String[] args) {
|
||||
BufferedImage bi = new BufferedImage(100, 100,
|
||||
BufferedImage.TYPE_BYTE_BINARY);
|
||||
|
||||
Graphics g = bi.createGraphics();
|
||||
g.setColor(Color.white);
|
||||
g.fillRect(0, 0, 100, 100);
|
||||
g.setColor(Color.black);
|
||||
g.fillRect(20, 20, 40, 40);
|
||||
g.setColor(Color.white);
|
||||
g.fillRect(25, 25, 25, 25);
|
||||
g.dispose();
|
||||
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
boolean success;
|
||||
|
||||
try {
|
||||
success = ImageIO.write(bi, "jpeg", baos);
|
||||
} catch (IOException ioe) {
|
||||
throw new RuntimeException("Could not write JPEG to stream");
|
||||
}
|
||||
|
||||
if (!success) {
|
||||
throw new RuntimeException("Could not find valid JPEG writer...");
|
||||
}
|
||||
|
||||
byte[] bytearr = baos.toByteArray();
|
||||
ByteArrayInputStream bais = new ByteArrayInputStream(bytearr);
|
||||
BufferedImage bi2 = null;
|
||||
|
||||
try {
|
||||
bi2 = ImageIO.read(bais);
|
||||
} catch (IOException ioe) {
|
||||
throw new RuntimeException("Could not read JPEG stream");
|
||||
}
|
||||
|
||||
int[] actualVals = new int[3];
|
||||
|
||||
actualVals[0] = bi2.getRGB(27, 5);
|
||||
actualVals[1] = bi2.getRGB(27, 22);
|
||||
actualVals[2] = bi2.getRGB(35, 35);
|
||||
|
||||
for (int i = 0; i < actualVals.length; i++) {
|
||||
if (actualVals[i] != expectedVals[i]) {
|
||||
throw new RuntimeException("Pixel mismatch at index: " + i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
55
jdk/test/javax/imageio/plugins/jpeg/CanEncodeIndexed.java
Normal file
55
jdk/test/javax/imageio/plugins/jpeg/CanEncodeIndexed.java
Normal file
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright (c) 2002, 2017, 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 4528585
|
||||
* @summary Tests whether the JPEGImageWriterSpi advertises that it is capable
|
||||
* of writing images using an IndexColorModel. The test fails if an
|
||||
* exception is thrown.
|
||||
*/
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.Iterator;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.ImageTypeSpecifier;
|
||||
|
||||
public class CanEncodeIndexed {
|
||||
|
||||
public static void main(String[] args) {
|
||||
BufferedImage img = new BufferedImage(32, 32,
|
||||
BufferedImage.TYPE_BYTE_INDEXED);
|
||||
|
||||
ImageTypeSpecifier spec =
|
||||
ImageTypeSpecifier.createFromRenderedImage(img);
|
||||
|
||||
Iterator writers = ImageIO.getImageWriters(spec, "jpeg");
|
||||
|
||||
if (!writers.hasNext()) {
|
||||
throw new RuntimeException("Test failed: " +
|
||||
"no JPEG writer found for " +
|
||||
"image with IndexColorModel");
|
||||
}
|
||||
}
|
||||
}
|
120
jdk/test/javax/imageio/plugins/jpeg/CompressionBug.java
Normal file
120
jdk/test/javax/imageio/plugins/jpeg/CompressionBug.java
Normal file
@ -0,0 +1,120 @@
|
||||
/*
|
||||
* Copyright (c) 2001, 2017, 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 4415068 4622201
|
||||
* @summary Tests if the JPEG writer responds to the compression quality setting
|
||||
*/
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Iterator;
|
||||
import java.util.Random;
|
||||
|
||||
import javax.imageio.IIOImage;
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.ImageTypeSpecifier;
|
||||
import javax.imageio.ImageWriteParam;
|
||||
import javax.imageio.ImageWriter;
|
||||
import javax.imageio.stream.ImageOutputStream;
|
||||
|
||||
public class CompressionBug {
|
||||
|
||||
public CompressionBug() throws IOException {
|
||||
File fileHighComp = File.createTempFile("CompressionHigh", ".jpg");
|
||||
File fileLowComp = File.createTempFile("CompressionLow", ".jpg");
|
||||
|
||||
fileHighComp.deleteOnExit();
|
||||
fileLowComp.deleteOnExit();
|
||||
|
||||
ImageOutputStream iosHighComp =
|
||||
ImageIO.createImageOutputStream(fileHighComp);
|
||||
ImageOutputStream iosLowComp =
|
||||
ImageIO.createImageOutputStream(fileLowComp);
|
||||
|
||||
int width = 100;
|
||||
int height = 100;
|
||||
BufferedImage bi =
|
||||
new BufferedImage(width, height,
|
||||
BufferedImage.TYPE_INT_RGB);
|
||||
Graphics g = bi.createGraphics();
|
||||
Random r = new Random();
|
||||
for (int i = 0; i < 100; i++) {
|
||||
Color c = new Color(r.nextInt(256),
|
||||
r.nextInt(256),
|
||||
r.nextInt(256));
|
||||
int x = r.nextInt(width);
|
||||
int y = r.nextInt(height);
|
||||
int w = r.nextInt(width - x);
|
||||
int h = r.nextInt(height - y);
|
||||
g.setColor(c);
|
||||
g.fillRect(x, y, w, h);
|
||||
}
|
||||
|
||||
ImageTypeSpecifier typeSpecifier =
|
||||
new ImageTypeSpecifier(bi.getColorModel(),
|
||||
bi.getSampleModel());
|
||||
|
||||
ImageWriter writer = null;
|
||||
Iterator iter = ImageIO.getImageWriters(typeSpecifier,"jpeg");
|
||||
while (iter.hasNext()) {
|
||||
writer = (ImageWriter)iter.next();
|
||||
break;
|
||||
}
|
||||
|
||||
IIOImage iioImg = new IIOImage(bi, null, null);
|
||||
ImageWriteParam wParam = writer.getDefaultWriteParam();
|
||||
wParam.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
|
||||
|
||||
// write the highly compressed image (a compression quality setting of
|
||||
// 0.1f means low visual quality and small file size)
|
||||
wParam.setCompressionQuality(0.1f);
|
||||
writer.setOutput(iosHighComp);
|
||||
writer.write(null, iioImg, wParam);
|
||||
|
||||
// write the somewhat compressed image (a compression quality setting
|
||||
// of 0.9f means high visual quality and large file size)
|
||||
wParam.setCompressionQuality(0.9f);
|
||||
writer.setOutput(iosLowComp);
|
||||
writer.write(null, iioImg, wParam);
|
||||
|
||||
long sizeOfFileLowComp = fileLowComp.length();
|
||||
long sizeOfFileHighComp = fileHighComp.length();
|
||||
|
||||
// the highly compressed image file should have a smaller file size
|
||||
// than the image file with low compression; throw an exception if
|
||||
// this isn't the case
|
||||
if (sizeOfFileLowComp < sizeOfFileHighComp) {
|
||||
throw new RuntimeException("Lower compression quality did not " +
|
||||
"reduce file size!");
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String args[]) throws IOException {
|
||||
new CompressionBug();
|
||||
}
|
||||
}
|
47
jdk/test/javax/imageio/plugins/jpeg/CompressionVals.java
Normal file
47
jdk/test/javax/imageio/plugins/jpeg/CompressionVals.java
Normal file
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2017, 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 4972087
|
||||
* @summary Verifies that JPEGImageWriteParam.getCompressionQualityValues()
|
||||
* returns an array that is one longer than the one returned by
|
||||
* getCompressionQualityDescriptions()
|
||||
*/
|
||||
|
||||
import javax.imageio.ImageWriteParam;
|
||||
import javax.imageio.plugins.jpeg.JPEGImageWriteParam;
|
||||
|
||||
public class CompressionVals {
|
||||
|
||||
public static void main(String[] args) {
|
||||
ImageWriteParam iwp = new JPEGImageWriteParam(null);
|
||||
iwp.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
|
||||
float[] vals = iwp.getCompressionQualityValues();
|
||||
String[] descs = iwp.getCompressionQualityDescriptions();
|
||||
if (vals.length != (descs.length + 1)) {
|
||||
throw new RuntimeException("Test failed: Values array is not " +
|
||||
"one larger than descriptions array");
|
||||
}
|
||||
}
|
||||
}
|
135
jdk/test/javax/imageio/plugins/jpeg/CrashAfterDispose.java
Normal file
135
jdk/test/javax/imageio/plugins/jpeg/CrashAfterDispose.java
Normal file
@ -0,0 +1,135 @@
|
||||
/*
|
||||
* Copyright (c) 2002, 2017, 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 4660047
|
||||
* @summary Tests if the JPEG reader/writer crashes the VM if certain methods
|
||||
* are called after a call to dispose()
|
||||
*/
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.Iterator;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.ImageReader;
|
||||
import javax.imageio.ImageWriter;
|
||||
import javax.imageio.stream.ImageInputStream;
|
||||
import javax.imageio.stream.ImageOutputStream;
|
||||
|
||||
public class CrashAfterDispose {
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
InputStream bais = new ByteArrayInputStream(new byte[100]);
|
||||
ImageInputStream iis = ImageIO.createImageInputStream(bais);
|
||||
|
||||
// find the JPEG reader
|
||||
ImageReader reader = null;
|
||||
Iterator readers = ImageIO.getImageReadersByFormatName("jpeg");
|
||||
if (readers.hasNext()) {
|
||||
reader = (ImageReader)readers.next();
|
||||
} else {
|
||||
throw new RuntimeException("Unable to find a reader!");
|
||||
}
|
||||
|
||||
// dispose the reader, then poke and prod it... the reader should
|
||||
// throw exceptions (which will be caught by this test), but it
|
||||
// should not crash the VM
|
||||
reader.dispose();
|
||||
|
||||
try {
|
||||
reader.setInput(iis);
|
||||
} catch (IllegalStateException e) {
|
||||
}
|
||||
|
||||
try {
|
||||
reader.read(0);
|
||||
} catch (IllegalStateException e) {
|
||||
}
|
||||
|
||||
try {
|
||||
reader.abort();
|
||||
} catch (IllegalStateException e) {
|
||||
}
|
||||
|
||||
try {
|
||||
reader.reset();
|
||||
} catch (IllegalStateException e) {
|
||||
}
|
||||
|
||||
try {
|
||||
reader.dispose();
|
||||
} catch (IllegalStateException e) {
|
||||
}
|
||||
|
||||
// find the JPEG writer
|
||||
ImageWriter writer = null;
|
||||
Iterator writers = ImageIO.getImageWritersByFormatName("jpeg");
|
||||
if (writers.hasNext()) {
|
||||
writer = (ImageWriter)writers.next();
|
||||
} else {
|
||||
throw new RuntimeException("Unable to find a writer!");
|
||||
}
|
||||
|
||||
// set up output stream
|
||||
OutputStream baos = new ByteArrayOutputStream();
|
||||
ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
|
||||
BufferedImage bi = new BufferedImage(10, 10,
|
||||
BufferedImage.TYPE_INT_RGB);
|
||||
|
||||
// dispose the writer, then poke and prod it... the writer should
|
||||
// throw exceptions (which will be caught by this test), but it
|
||||
// should not crash the VM
|
||||
writer.dispose();
|
||||
|
||||
try {
|
||||
writer.setOutput(ios);
|
||||
} catch (IllegalStateException e) {
|
||||
}
|
||||
|
||||
try {
|
||||
writer.write(bi);
|
||||
} catch (IllegalStateException e) {
|
||||
}
|
||||
|
||||
try {
|
||||
writer.abort();
|
||||
} catch (IllegalStateException e) {
|
||||
}
|
||||
|
||||
try {
|
||||
writer.reset();
|
||||
} catch (IllegalStateException e) {
|
||||
}
|
||||
|
||||
try {
|
||||
writer.dispose();
|
||||
} catch (IllegalStateException e) {
|
||||
}
|
||||
}
|
||||
}
|
157
jdk/test/javax/imageio/plugins/jpeg/DestTypeTest.java
Normal file
157
jdk/test/javax/imageio/plugins/jpeg/DestTypeTest.java
Normal file
@ -0,0 +1,157 @@
|
||||
/*
|
||||
* Copyright (c) 2004, 2017, 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 5028259
|
||||
* @summary Verifies that usage of the destination type does not cause the
|
||||
* increase of size of the result jpeg file
|
||||
*/
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.imageio.IIOImage;
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.ImageReader;
|
||||
import javax.imageio.ImageTypeSpecifier;
|
||||
import javax.imageio.ImageWriteParam;
|
||||
import javax.imageio.ImageWriter;
|
||||
import javax.imageio.event.IIOReadWarningListener;
|
||||
import javax.imageio.event.IIOWriteWarningListener;
|
||||
import javax.imageio.metadata.IIOMetadata;
|
||||
import javax.imageio.stream.ImageOutputStream;
|
||||
|
||||
public class DestTypeTest implements IIOWriteWarningListener, IIOReadWarningListener {
|
||||
|
||||
ImageWriter w;
|
||||
ImageReader r;
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
BufferedImage bi_rgb = createTestImage(BufferedImage.TYPE_INT_RGB);
|
||||
|
||||
DestTypeTest bug = new DestTypeTest();
|
||||
byte[] rgb_data = bug.writeTest(bi_rgb);
|
||||
|
||||
System.out.println("rgb jpeg data length is " + rgb_data.length);
|
||||
|
||||
BufferedImage bi_argb = createTestImage(BufferedImage.TYPE_INT_ARGB);
|
||||
|
||||
ImageWriteParam p = bug.getWriteParam();
|
||||
IIOMetadata m = bug.getMetadata(p);
|
||||
|
||||
byte[] submeta_data = bug.writeTest(bi_argb, p, m);
|
||||
System.out.println("desttype and metadata jpeg data length is " + submeta_data.length);
|
||||
|
||||
p = bug.getWriteParam();
|
||||
byte[] subbanded_data = bug.writeTest(bi_argb, p);
|
||||
System.out.println("desttype jpeg data length is " + subbanded_data.length);
|
||||
|
||||
if (submeta_data.length > rgb_data.length) {
|
||||
throw new RuntimeException("Too big result jpeg: " + submeta_data.length +
|
||||
"(rgb image size is " + rgb_data.length + ")");
|
||||
}
|
||||
if (subbanded_data.length > rgb_data.length) {
|
||||
throw new RuntimeException("Too big result jpeg: " + subbanded_data.length +
|
||||
"(rgb image size is " + rgb_data.length + ")");
|
||||
}
|
||||
}
|
||||
|
||||
public DestTypeTest() {
|
||||
w = (ImageWriter)
|
||||
ImageIO.getImageWritersByFormatName("jpeg").next();
|
||||
w.addIIOWriteWarningListener(this);
|
||||
|
||||
r = (ImageReader)
|
||||
ImageIO.getImageReadersByFormatName("jpeg").next();
|
||||
r.addIIOReadWarningListener(this);
|
||||
}
|
||||
|
||||
public ImageWriteParam getWriteParam() {
|
||||
ImageWriteParam p = w.getDefaultWriteParam();
|
||||
p.setSourceBands(new int[] {0, 1, 2});
|
||||
ImageTypeSpecifier type =
|
||||
ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB);
|
||||
p.setDestinationType(type);
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
public IIOMetadata getMetadata(ImageWriteParam p) {
|
||||
return w.getDefaultImageMetadata(p.getDestinationType(), null);
|
||||
}
|
||||
|
||||
public byte[] writeTest(BufferedImage bi) throws IOException {
|
||||
return writeTest(bi, null);
|
||||
}
|
||||
|
||||
public byte[] writeTest(BufferedImage bi,
|
||||
ImageWriteParam p) throws IOException {
|
||||
return writeTest(bi, p, null);
|
||||
}
|
||||
public byte[] writeTest(BufferedImage bi,
|
||||
ImageWriteParam p,
|
||||
IIOMetadata m) throws IOException {
|
||||
ByteArrayOutputStream baos =
|
||||
new ByteArrayOutputStream();
|
||||
|
||||
// write test image as jpeg
|
||||
ImageOutputStream ios =
|
||||
ImageIO.createImageOutputStream(baos);
|
||||
w.setOutput(ios);
|
||||
w.write(null,
|
||||
new IIOImage(bi, null, m),
|
||||
p);
|
||||
ios.close();
|
||||
return baos.toByteArray();
|
||||
}
|
||||
|
||||
public static BufferedImage createTestImage(int type) {
|
||||
int w = 100;
|
||||
int h = 500;
|
||||
BufferedImage bi = new BufferedImage(3*w, h, type);
|
||||
Graphics g = bi.createGraphics();
|
||||
g.setColor(Color.red);
|
||||
g.fillRect(0,0,w,h);
|
||||
g.setColor(Color.green);
|
||||
g.fillRect(w, 0,w,h);
|
||||
g.setColor(Color.blue);
|
||||
g.fillRect(2*w,0,w,h);
|
||||
|
||||
return bi;
|
||||
}
|
||||
|
||||
public void warningOccurred(ImageWriter source,
|
||||
int imageIndex,
|
||||
String warning) {
|
||||
System.out.println("WRITING WARNING: " + warning);
|
||||
}
|
||||
|
||||
public void warningOccurred(ImageReader source,
|
||||
String warning) {
|
||||
System.out.println("READING WARNING: " + warning);
|
||||
}
|
||||
}
|
365
jdk/test/javax/imageio/plugins/jpeg/JPEGsNotAcceleratedTest.java
Normal file
365
jdk/test/javax/imageio/plugins/jpeg/JPEGsNotAcceleratedTest.java
Normal file
@ -0,0 +1,365 @@
|
||||
/*
|
||||
* Copyright (c) 2004, 2017, 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 4994702
|
||||
* @key headful
|
||||
* @summary verifies that no regression were introduced with the fix for this
|
||||
* bug
|
||||
*/
|
||||
|
||||
import java.awt.AlphaComposite;
|
||||
import java.awt.Color;
|
||||
import java.awt.Component;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Frame;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.ImageCapabilities;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.image.DataBuffer;
|
||||
import java.awt.image.VolatileImage;
|
||||
import java.awt.image.WritableRaster;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.imageio.IIOImage;
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.ImageReadParam;
|
||||
import javax.imageio.ImageReader;
|
||||
import javax.imageio.ImageWriteParam;
|
||||
import javax.imageio.ImageWriter;
|
||||
import javax.imageio.stream.FileImageInputStream;
|
||||
import javax.imageio.stream.ImageOutputStream;
|
||||
|
||||
public class JPEGsNotAcceleratedTest {
|
||||
|
||||
public static final int testRGB = Color.red.getRGB();
|
||||
public static final int TEST_W = 100;
|
||||
public static final int TEST_H = 100;
|
||||
public static final Rectangle roi =
|
||||
new Rectangle(TEST_W/4, TEST_H/4, TEST_W/2, TEST_H/2);
|
||||
|
||||
static Frame f;
|
||||
static boolean showRes = false;
|
||||
static int testsFinished = 0;
|
||||
static int testsStarted = 0;
|
||||
static boolean lowCompression = false;
|
||||
|
||||
static boolean failed = false;
|
||||
|
||||
public JPEGsNotAcceleratedTest(String name) {
|
||||
BufferedImage bi = readTestImage(name, null, null);
|
||||
runTestOnImage("no dest image, no region of interest", bi, null);
|
||||
|
||||
BufferedImage destBI = getDestImage();
|
||||
bi = readTestImage(name, destBI, null);
|
||||
runTestOnImage("w/ dest image, no region of interest", bi, null);
|
||||
|
||||
// steal the raster, see if the destination image
|
||||
// gets accelerated
|
||||
destBI = getDestImage();
|
||||
DataBuffer db =
|
||||
((WritableRaster)destBI.getRaster()).getDataBuffer();
|
||||
bi = readTestImage(name, destBI, null);
|
||||
runTestOnImage("w/ dest image (with stolen raster),"+
|
||||
" no region of interest", bi, null);
|
||||
|
||||
bi = readTestImage(name, null, roi);
|
||||
runTestOnImage("no dest image, region of interest", bi, roi);
|
||||
|
||||
destBI = getDestImage();
|
||||
bi = readTestImage(name, destBI, roi);
|
||||
runTestOnImage("w/ dest image, region of interest", bi, roi);
|
||||
|
||||
// accelerate the destination image first, then load
|
||||
// an image into it. Check that the accelerated copy gets
|
||||
// updated
|
||||
destBI = getDestImage();
|
||||
accelerateImage(destBI);
|
||||
bi = readTestImage(name, destBI, roi);
|
||||
runTestOnImage("w/ accelerated dest image,"+
|
||||
" region of interest", bi, roi);
|
||||
|
||||
synchronized (JPEGsNotAcceleratedTest.class) {
|
||||
testsFinished++;
|
||||
JPEGsNotAcceleratedTest.class.notify();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static BufferedImage readTestImage(String fileName,
|
||||
BufferedImage dest,
|
||||
Rectangle srcROI)
|
||||
{
|
||||
BufferedImage bi = null;
|
||||
|
||||
try {
|
||||
FileImageInputStream is =
|
||||
new FileImageInputStream(new File(fileName));
|
||||
ImageReader reader =
|
||||
(ImageReader)ImageIO.getImageReaders(is).next();
|
||||
ImageReadParam param = reader.getDefaultReadParam();
|
||||
if (dest != null) {
|
||||
param.setDestination(dest);
|
||||
}
|
||||
if (srcROI != null) {
|
||||
param.setSourceRegion(srcROI);
|
||||
}
|
||||
reader.setInput(is);
|
||||
bi = reader.read(0, param);
|
||||
} catch (IOException e) {
|
||||
System.err.println("Error " + e +
|
||||
" when reading file: " + fileName);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
return bi;
|
||||
}
|
||||
|
||||
public static void writeTestImage(String fileName) {
|
||||
BufferedImage bi =
|
||||
new BufferedImage(TEST_W, TEST_H, BufferedImage.TYPE_INT_RGB);
|
||||
Graphics g = bi.getGraphics();
|
||||
g.setColor(new Color(testRGB));
|
||||
g.fillRect(0, 0, TEST_W, TEST_H);
|
||||
try {
|
||||
System.err.printf("Writing %s\n", fileName);
|
||||
if (lowCompression) {
|
||||
ImageWriter iw = (ImageWriter)ImageIO.getImageWritersBySuffix("jpeg").next();
|
||||
if(iw == null) {
|
||||
throw new RuntimeException("No available image writer for "
|
||||
+ "jpeg "
|
||||
+ " Test failed.");
|
||||
}
|
||||
|
||||
File file = new File(fileName);
|
||||
ImageOutputStream ios = ImageIO.createImageOutputStream(file);
|
||||
iw.setOutput(ios);
|
||||
|
||||
ImageWriteParam param = iw.getDefaultWriteParam();
|
||||
param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
|
||||
param.setCompressionQuality(1);
|
||||
|
||||
IIOImage iioImg = new IIOImage(bi, null, null);
|
||||
iw.write(null, iioImg, param);
|
||||
|
||||
} else {
|
||||
ImageIO.write(bi, "jpeg", new File(fileName));
|
||||
}
|
||||
} catch (IOException e) {
|
||||
System.err.println("Error " + e +
|
||||
" when writing file: " + fileName);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public VolatileImage accelerateImage(BufferedImage bi) {
|
||||
VolatileImage testVI = f.createVolatileImage(TEST_W, TEST_H);
|
||||
do {
|
||||
if (testVI.validate(f.getGraphicsConfiguration()) ==
|
||||
VolatileImage.IMAGE_INCOMPATIBLE)
|
||||
{
|
||||
testVI = f.createVolatileImage(TEST_W, TEST_H);
|
||||
}
|
||||
Graphics2D g = testVI.createGraphics();
|
||||
g.setComposite(AlphaComposite.Src);
|
||||
g.setColor(Color.green);
|
||||
g.fillRect(0, 0, TEST_W, TEST_H);
|
||||
|
||||
g.drawImage(bi, 0, 0, null);
|
||||
g.drawImage(bi, 0, 0, null);
|
||||
g.drawImage(bi, 0, 0, null);
|
||||
g.dispose();
|
||||
} while (testVI.contentsLost());
|
||||
|
||||
return testVI;
|
||||
}
|
||||
|
||||
public BufferedImage getDestImage() {
|
||||
BufferedImage destBI =
|
||||
new BufferedImage(TEST_W, TEST_H, BufferedImage.TYPE_INT_RGB);
|
||||
Graphics2D g = (Graphics2D)destBI.getGraphics();
|
||||
g.setComposite(AlphaComposite.Src);
|
||||
g.setColor(Color.blue);
|
||||
g.fillRect(0, 0, TEST_W, TEST_H);
|
||||
return destBI;
|
||||
}
|
||||
|
||||
public void runTestOnImage(String desc, BufferedImage bi,
|
||||
Rectangle srcROI)
|
||||
{
|
||||
|
||||
if (srcROI == null) {
|
||||
srcROI = new Rectangle(0, 0, TEST_W, TEST_H);
|
||||
}
|
||||
|
||||
VolatileImage testVI = accelerateImage(bi);
|
||||
|
||||
ImageCapabilities ic =
|
||||
bi.getCapabilities(f.getGraphicsConfiguration());
|
||||
boolean accelerated = ic.isAccelerated();
|
||||
|
||||
System.err.println("Testing: " + desc +
|
||||
" -- bi.isAccelerated(): " + accelerated );
|
||||
|
||||
BufferedImage snapshot = testVI.getSnapshot();
|
||||
if (showRes) {
|
||||
showRes(desc, snapshot);
|
||||
}
|
||||
|
||||
for (int y = 0; y < srcROI.height; y++) {
|
||||
for (int x = 0; x < srcROI.width; x++) {
|
||||
int destRGB = snapshot.getRGB(x, y);
|
||||
if (destRGB != testRGB && destRGB != 0xfffe0000) {
|
||||
failed = true;
|
||||
System.err.printf("Test failed at %dx%d pixel=%x\n",
|
||||
x, y, snapshot.getRGB(x, y));
|
||||
if (!showRes) {
|
||||
showRes(desc, snapshot);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static int startX = 64, startY = 0;
|
||||
static int frameX = startX, frameY = startY;
|
||||
private static void showRes(String desc, final BufferedImage src) {
|
||||
final int w = src.getWidth();
|
||||
final int h = src.getHeight();
|
||||
|
||||
Frame f = new Frame(desc+": dbl-click to exit");
|
||||
Component c;
|
||||
f.add(c = new Component() {
|
||||
public Dimension getPreferredSize() {
|
||||
return new Dimension(w,h);
|
||||
}
|
||||
|
||||
public void paint(Graphics g) {
|
||||
g.clearRect(0, 0, getWidth(), getHeight());
|
||||
g.drawImage(src, 0,0, null);
|
||||
}
|
||||
});
|
||||
c.addMouseListener(new MouseAdapter() {
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
if (e.getClickCount() > 1) {
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
});
|
||||
f.pack();
|
||||
synchronized (JPEGsNotAcceleratedTest.class) {
|
||||
f.setLocation(frameX, frameY);
|
||||
frameX += f.getWidth();
|
||||
if ((frameX + f.getWidth()) >
|
||||
f.getGraphicsConfiguration().getBounds().width)
|
||||
{
|
||||
frameY += TEST_H;
|
||||
if ((frameY + f.getHeight()) >
|
||||
f.getGraphicsConfiguration().getBounds().height)
|
||||
{
|
||||
startY += 30;
|
||||
startX += 30;
|
||||
frameY = startY;
|
||||
}
|
||||
frameX = startX;
|
||||
}
|
||||
};
|
||||
f.setVisible(true);
|
||||
}
|
||||
|
||||
public static void usage() {
|
||||
System.err.println("Usage: java Test [file name] [-write][-show][-low]");
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.setProperty("sun.java2d.pmoffscreen", "true");
|
||||
System.setProperty("sun.java2d.ddforcevram", "true");
|
||||
String name = "red.jpg";
|
||||
|
||||
f = new Frame();
|
||||
f.pack();
|
||||
|
||||
if (f.getGraphicsConfiguration().getColorModel().getPixelSize() < 16) {
|
||||
System.err.println("8-bit display mode detected, dithering issues possible, "+
|
||||
"considering test passed.");
|
||||
f.dispose();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
for (String arg : args) {
|
||||
if (arg.equals("-write")) {
|
||||
writeTestImage(name);
|
||||
System.exit(0);
|
||||
} else if (arg.equals("-show")) {
|
||||
showRes = true;
|
||||
} else if (arg.equals("-low")) {
|
||||
lowCompression = true;
|
||||
name ="red_low.jpg";
|
||||
System.err.println("Using low jpeg compression");
|
||||
} else if (arg.equals("-help")) {
|
||||
usage();
|
||||
} else {
|
||||
final String filename = arg;
|
||||
testsStarted++;
|
||||
new Thread(new Runnable() {
|
||||
public void run() {
|
||||
new JPEGsNotAcceleratedTest(filename);
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
}
|
||||
|
||||
if (testsStarted == 0) {
|
||||
writeTestImage(name);
|
||||
testsStarted++;
|
||||
new JPEGsNotAcceleratedTest(name);
|
||||
}
|
||||
|
||||
|
||||
synchronized (JPEGsNotAcceleratedTest.class) {
|
||||
while (testsFinished < testsStarted) {
|
||||
try {
|
||||
JPEGsNotAcceleratedTest.class.wait(100);
|
||||
} catch (InterruptedException e) {
|
||||
failed = true; break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
f.dispose();
|
||||
if (failed) {
|
||||
throw new RuntimeException("Test failed");
|
||||
}
|
||||
|
||||
System.err.println("Passed.");
|
||||
}
|
||||
}
|
71
jdk/test/javax/imageio/plugins/jpeg/MergeTreeTest.java
Normal file
71
jdk/test/javax/imageio/plugins/jpeg/MergeTreeTest.java
Normal file
@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Copyright (c) 2004, 2017, 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 4895547
|
||||
* @summary Test verifies that mergeTree() of JPEGMetadata does not throw the
|
||||
* NPE
|
||||
*/
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.ImageTypeSpecifier;
|
||||
import javax.imageio.ImageWriter;
|
||||
import javax.imageio.metadata.IIOMetadata;
|
||||
import javax.imageio.stream.ImageOutputStream;
|
||||
|
||||
import org.w3c.dom.Node;
|
||||
|
||||
public class MergeTreeTest {
|
||||
public static void main(String[] args) throws IOException {
|
||||
ImageWriter iw =
|
||||
(ImageWriter)ImageIO.getImageWritersByFormatName("jpeg").next();
|
||||
|
||||
ImageTypeSpecifier type =
|
||||
ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB);
|
||||
|
||||
ImageOutputStream ios =
|
||||
ImageIO.createImageOutputStream(new File("MergeTreeTest.jpeg"));
|
||||
iw.setOutput(ios);
|
||||
|
||||
IIOMetadata meta = iw.getDefaultImageMetadata(type, null);
|
||||
|
||||
boolean isFailed = false;
|
||||
|
||||
String[] fmts = meta.getMetadataFormatNames();
|
||||
for (int i=0; i<fmts.length; i++) {
|
||||
System.out.print("Format: " + fmts[i] + " ... ");
|
||||
Node root = meta.getAsTree(fmts[i]);
|
||||
try {
|
||||
meta.mergeTree(fmts[i], root);
|
||||
} catch (NullPointerException e) {
|
||||
throw new RuntimeException("Test failed for format " + fmts[i], e);
|
||||
}
|
||||
System.out.println("PASSED");
|
||||
}
|
||||
}
|
||||
}
|
112
jdk/test/javax/imageio/plugins/jpeg/RasterWithMinXTest.java
Normal file
112
jdk/test/javax/imageio/plugins/jpeg/RasterWithMinXTest.java
Normal file
@ -0,0 +1,112 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 2017, 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 4843895
|
||||
* @summary Tests that we handle raster with non-zero minX and minY correctly
|
||||
* @modules java.desktop/com.sun.imageio.plugins.jpeg
|
||||
*/
|
||||
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.image.RasterFormatException;
|
||||
import java.awt.image.WritableRaster;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
|
||||
import javax.imageio.IIOImage;
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.ImageTypeSpecifier;
|
||||
import javax.imageio.ImageWriteParam;
|
||||
import javax.imageio.ImageWriter;
|
||||
import javax.imageio.metadata.IIOMetadata;
|
||||
import javax.imageio.stream.ImageOutputStream;
|
||||
import javax.imageio.stream.MemoryCacheImageOutputStream;
|
||||
|
||||
public class RasterWithMinXTest {
|
||||
|
||||
public static void main(String[] args) {
|
||||
String format = "jpeg";
|
||||
|
||||
// Set output file.
|
||||
ImageOutputStream output = new MemoryCacheImageOutputStream(new ByteArrayOutputStream());
|
||||
|
||||
// Create image.
|
||||
BufferedImage bi = new BufferedImage(256, 256,
|
||||
BufferedImage.TYPE_3BYTE_BGR);
|
||||
|
||||
// Populate image.
|
||||
int[] rgbArray = new int[256];
|
||||
for(int i = 0; i < 256; i++) {
|
||||
Arrays.fill(rgbArray, i);
|
||||
bi.setRGB(0, i, 256, 1, rgbArray, 0, 256);
|
||||
}
|
||||
|
||||
// create translated raster in order to get non-zero minX and minY
|
||||
WritableRaster r = (WritableRaster)bi.getRaster().createTranslatedChild(64,64);
|
||||
|
||||
Iterator i = ImageIO.getImageWritersByFormatName(format);
|
||||
ImageWriter iw = null;
|
||||
while(i.hasNext() && iw == null) {
|
||||
Object o = i.next();
|
||||
if (o instanceof com.sun.imageio.plugins.jpeg.JPEGImageWriter) {
|
||||
iw = (ImageWriter)o;
|
||||
}
|
||||
}
|
||||
if (iw == null) {
|
||||
throw new RuntimeException("No available image writer");
|
||||
}
|
||||
|
||||
ImageWriteParam iwp = iw.getDefaultWriteParam();
|
||||
IIOMetadata metadata = iw.getDefaultImageMetadata(new ImageTypeSpecifier(bi.getColorModel(), r.getSampleModel()), iwp);
|
||||
|
||||
IIOImage img = new IIOImage(r, null, metadata);
|
||||
|
||||
iw.setOutput(output);
|
||||
try {
|
||||
iw.write(img);
|
||||
} catch (RasterFormatException e) {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException("RasterException occurs. Test Failed!");
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
throw new RuntimeException("Unexpected Exception");
|
||||
}
|
||||
|
||||
// test case of theImageWriteParam with non-null sourceRegion
|
||||
iwp.setSourceRegion(new Rectangle(32,32,192,192));
|
||||
metadata = iw.getDefaultImageMetadata(new ImageTypeSpecifier(bi.getColorModel(), r.getSampleModel()), iwp);
|
||||
try {
|
||||
iw.write(metadata, img, iwp);
|
||||
} catch (RasterFormatException e) {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException("SetSourceRegion causes the RasterException. Test Failed!");
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
throw new RuntimeException("Unexpected Exception");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
46
jdk/test/javax/imageio/plugins/jpeg/ResetOutOfMemory.java
Normal file
46
jdk/test/javax/imageio/plugins/jpeg/ResetOutOfMemory.java
Normal file
@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (c) 2001, 2017, 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 4411955
|
||||
* @summary Checks that the JPEG writer does not throw an OutOfMemoryError from
|
||||
* its reset() method
|
||||
* @modules java.desktop/com.sun.imageio.plugins.jpeg
|
||||
*/
|
||||
|
||||
import javax.imageio.ImageWriter;
|
||||
|
||||
import com.sun.imageio.plugins.jpeg.JPEGImageWriter;
|
||||
|
||||
public class ResetOutOfMemory {
|
||||
|
||||
public static void main(String args[]) {
|
||||
ImageWriter writer = new JPEGImageWriter(null);
|
||||
try {
|
||||
writer.reset();
|
||||
} catch (OutOfMemoryError e) {
|
||||
throw new RuntimeException("Got OutOfMemoryError!");
|
||||
}
|
||||
}
|
||||
}
|
92
jdk/test/javax/imageio/plugins/jpeg/UshortGrayTest.java
Normal file
92
jdk/test/javax/imageio/plugins/jpeg/UshortGrayTest.java
Normal file
@ -0,0 +1,92 @@
|
||||
/*
|
||||
* Copyright (c) 2002, 2017, 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 4450894
|
||||
* @summary Tests if the JPEGImageWriter allows images with > 8-bit samples to
|
||||
* be written. Also tests the JPEGImageWriterSpi.canEncodeImage()
|
||||
* mechanism for this same behavior.
|
||||
*/
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
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 UshortGrayTest {
|
||||
|
||||
public static void main(String[] args) {
|
||||
Iterator iter;
|
||||
BufferedImage bi = new BufferedImage(10, 10,
|
||||
BufferedImage.TYPE_USHORT_GRAY);
|
||||
|
||||
// Part 1: ensure that JPEGImageWriter throws an exception if it
|
||||
// encounters an image with 16-bit samples
|
||||
ImageWriter writer = null;
|
||||
iter = ImageIO.getImageWritersByFormatName("jpeg");
|
||||
if (iter.hasNext()) {
|
||||
writer = (ImageWriter)iter.next();
|
||||
} else {
|
||||
throw new RuntimeException("No JPEG reader found");
|
||||
}
|
||||
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
ImageOutputStream ios = null;
|
||||
boolean exceptionThrown = false;
|
||||
|
||||
try {
|
||||
ios = ImageIO.createImageOutputStream(baos);
|
||||
} catch (IOException ioe) {
|
||||
throw new RuntimeException("Could not create ImageOutputStream");
|
||||
}
|
||||
|
||||
try {
|
||||
writer.setOutput(ios);
|
||||
writer.write(bi);
|
||||
} catch (IOException ioe) {
|
||||
exceptionThrown = true;
|
||||
}
|
||||
|
||||
if (!exceptionThrown) {
|
||||
throw new RuntimeException("JPEG writer should not be able to " +
|
||||
"write USHORT_GRAY images");
|
||||
}
|
||||
|
||||
// Part 2: ensure that JPEGImageWriterSpi.canEncodeImage() returns
|
||||
// false for images with 16-bit samples
|
||||
ImageTypeSpecifier its =
|
||||
ImageTypeSpecifier.createFromRenderedImage(bi);
|
||||
|
||||
iter = ImageIO.getImageWriters(its, "jpeg");
|
||||
if (iter.hasNext()) {
|
||||
throw new RuntimeException("JPEG writer should not be available" +
|
||||
" for USHORT_GRAY images");
|
||||
}
|
||||
}
|
||||
}
|
66
jdk/test/javax/imageio/plugins/png/CanEncodeShort.java
Normal file
66
jdk/test/javax/imageio/plugins/png/CanEncodeShort.java
Normal file
@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright (c) 2002, 2017, 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 4474819
|
||||
* @summary Tests whether the PNGImageWriterSpi advertises that it is capable of
|
||||
* writing images of TYPE_USHORT_565_RGB and TYPE_USHORT_555_RGB. The
|
||||
* test fails if an exception is thrown.
|
||||
*/
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.Iterator;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.ImageTypeSpecifier;
|
||||
|
||||
public class CanEncodeShort {
|
||||
|
||||
private static final int[] types = new int[] {
|
||||
BufferedImage.TYPE_USHORT_565_RGB,
|
||||
BufferedImage.TYPE_USHORT_555_RGB,
|
||||
};
|
||||
|
||||
private static final String[] typeNames = new String[] {
|
||||
"TYPE_USHORT_565_RGB",
|
||||
"TYPE_USHORT_555_RGB",
|
||||
};
|
||||
|
||||
public static void main(String[] args) {
|
||||
for (int i = 0; i < types.length; i++) {
|
||||
BufferedImage img = new BufferedImage(32, 32, types[i]);
|
||||
|
||||
ImageTypeSpecifier spec =
|
||||
ImageTypeSpecifier.createFromRenderedImage(img);
|
||||
|
||||
Iterator writers = ImageIO.getImageWriters(spec, "png");
|
||||
|
||||
if (!writers.hasNext()) {
|
||||
throw new RuntimeException("Test failed: " +
|
||||
"no PNG writer found for type " +
|
||||
typeNames[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
62
jdk/test/javax/imageio/plugins/png/ImageCompare.java
Normal file
62
jdk/test/javax/imageio/plugins/png/ImageCompare.java
Normal file
@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright (c) 2000, 2017, 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.
|
||||
*/
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.image.ColorModel;
|
||||
import java.awt.image.Raster;
|
||||
|
||||
// Utility to compare two BufferedImages for RGB equality
|
||||
public class ImageCompare {
|
||||
|
||||
public static void compare(BufferedImage oldimg,
|
||||
BufferedImage newimg) {
|
||||
int width = oldimg.getWidth();
|
||||
int height = oldimg.getHeight();
|
||||
if (newimg.getWidth() != width || newimg.getHeight() != height) {
|
||||
throw new RuntimeException("Dimensions changed!");
|
||||
}
|
||||
|
||||
Raster oldras = oldimg.getRaster();
|
||||
ColorModel oldcm = oldimg.getColorModel();
|
||||
Raster newras = newimg.getRaster();
|
||||
ColorModel newcm = newimg.getColorModel();
|
||||
|
||||
for (int j = 0; j < height; j++) {
|
||||
for (int i = 0; i < width; i++) {
|
||||
Object oldpixel = oldras.getDataElements(i, j, null);
|
||||
int oldrgb = oldcm.getRGB(oldpixel);
|
||||
int oldalpha = oldcm.getAlpha(oldpixel);
|
||||
|
||||
Object newpixel = newras.getDataElements(i, j, null);
|
||||
int newrgb = newcm.getRGB(newpixel);
|
||||
int newalpha = newcm.getAlpha(newpixel);
|
||||
|
||||
if (newrgb != oldrgb ||
|
||||
newalpha != oldalpha) {
|
||||
throw new RuntimeException("Pixels differ at " + i +
|
||||
", " + j);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
131
jdk/test/javax/imageio/plugins/png/PngPremultAlphaTest.java
Normal file
131
jdk/test/javax/imageio/plugins/png/PngPremultAlphaTest.java
Normal file
@ -0,0 +1,131 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 2017, 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 4888478
|
||||
* @summary Test that colors do not distort when buffered image with
|
||||
* premultiplied alpha is encoded to png format
|
||||
*/
|
||||
|
||||
import java.awt.AlphaComposite;
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
public class PngPremultAlphaTest {
|
||||
protected static int width = 100;
|
||||
protected static int height = 100;
|
||||
|
||||
protected static String format = "png";
|
||||
|
||||
protected static int[] iBufferedImageTypes = {
|
||||
BufferedImage.TYPE_INT_RGB,
|
||||
BufferedImage.TYPE_INT_ARGB,
|
||||
BufferedImage.TYPE_4BYTE_ABGR_PRE,
|
||||
BufferedImage.TYPE_INT_ARGB_PRE
|
||||
};
|
||||
|
||||
protected static String[] strBufferedImageTypes = {
|
||||
"TYPE_INT_RGB",
|
||||
"TYPE_INT_ARGB",
|
||||
"BufferedImage.TYPE_4BYTE_ABGR_PRE",
|
||||
"BufferedImage.TYPE_INT_ARGB_PRE"
|
||||
};
|
||||
|
||||
public static void main(String[] arg) {
|
||||
for(int i=0; i<iBufferedImageTypes.length; i++) {
|
||||
System.out.println("Test for " + strBufferedImageTypes[i]);
|
||||
doTest(iBufferedImageTypes[i]);
|
||||
}
|
||||
}
|
||||
|
||||
public static void doTest(int type) {
|
||||
try {
|
||||
BufferedImage src = new BufferedImage(100, 100,
|
||||
type);
|
||||
Graphics2D g = src.createGraphics();
|
||||
g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC, 0.5f));
|
||||
g.setColor(new Color(0x20, 0x40, 0x60));
|
||||
g.fillRect(0,0,100,100);
|
||||
|
||||
int[] samples = new int[src.getData().getNumBands()];
|
||||
src.getData().getPixels(0,0,1,1,samples);
|
||||
for(int i=0; i<samples.length; i++) {
|
||||
System.out.println("sample["+i+"]="+Integer.toHexString(samples[i]));
|
||||
}
|
||||
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
ImageIO.write(src, format, baos);
|
||||
baos.close();
|
||||
|
||||
|
||||
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
|
||||
BufferedImage dst = ImageIO.read(bais);
|
||||
|
||||
isSameColors(src, dst);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException("Test failed.");
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isSameColors(BufferedImage src, BufferedImage dst) {
|
||||
Object dstPixel = dst.getRaster().getDataElements(width/2, height/2, null);
|
||||
Object srcPixel = src.getRaster().getDataElements(width/2, height/2, null);
|
||||
|
||||
// take into account the rounding error
|
||||
if ( Math.abs(src.getColorModel().getRed(srcPixel) - dst.getColorModel().getRed(dstPixel)) > 1
|
||||
|| Math.abs(src.getColorModel().getGreen(srcPixel) - dst.getColorModel().getGreen(dstPixel)) > 1
|
||||
|| Math.abs(src.getColorModel().getBlue(srcPixel) - dst.getColorModel().getBlue(dstPixel)) > 1) {
|
||||
showPixel(src, width/2, height/2);
|
||||
showPixel(dst, width/2, height/2);
|
||||
|
||||
throw new RuntimeException( "Colors are different: "
|
||||
+ Integer.toHexString(src.getColorModel().getRGB(srcPixel))
|
||||
+ " and "
|
||||
+ Integer.toHexString(dst.getColorModel().getRGB(dstPixel)));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private static void showPixel(BufferedImage src, int x, int y) {
|
||||
System.out.println("Img is " + src);
|
||||
System.out.println("CM is " + src.getColorModel().getClass().getName());
|
||||
Object p = src.getRaster().getDataElements(x, y, null);
|
||||
System.out.println("RGB: " +
|
||||
Integer.toHexString(src.getColorModel().getRGB(p)));
|
||||
System.out.println("Red: " +
|
||||
Integer.toHexString(src.getColorModel().getRed(p)));
|
||||
System.out.println("Green: " +
|
||||
Integer.toHexString(src.getColorModel().getGreen(p)));
|
||||
System.out.println("Blue: " +
|
||||
Integer.toHexString(src.getColorModel().getBlue(p)));
|
||||
System.out.println("Alpha: " +
|
||||
Integer.toHexString(src.getColorModel().getAlpha(p)));
|
||||
}
|
||||
}
|
83
jdk/test/javax/imageio/plugins/png/ShortPaletteTest.java
Normal file
83
jdk/test/javax/imageio/plugins/png/ShortPaletteTest.java
Normal file
@ -0,0 +1,83 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 2017, 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 4826548
|
||||
* @summary Tests for reading PNG images with 5,6,7 and 8 colors in palette
|
||||
*/
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.image.IndexColorModel;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
public class ShortPaletteTest {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
for (int numberColors = 2; numberColors <= 16; numberColors++) {
|
||||
try {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
BufferedImage image = createImage(numberColors);
|
||||
ImageIO.write(image, "png", baos);
|
||||
baos.close();
|
||||
System.out.println("Number of colors: " + numberColors);
|
||||
byte[] buffer = baos.toByteArray();
|
||||
ByteArrayInputStream bais = new ByteArrayInputStream(buffer);
|
||||
ImageIO.read(bais);
|
||||
System.out.println("OK");
|
||||
} catch (ArrayIndexOutOfBoundsException e) {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException("Test failed.");
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException("Unexpected exception was thrown."
|
||||
+ " Test failed.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static IndexColorModel createColorModel(int numberColors) {
|
||||
|
||||
byte[] colors = new byte[numberColors*3];
|
||||
int depth = 4;
|
||||
int startIndex = 0;
|
||||
|
||||
return new IndexColorModel(depth,
|
||||
numberColors,
|
||||
colors,
|
||||
startIndex,
|
||||
false);
|
||||
}
|
||||
|
||||
private static BufferedImage createImage(int numberColors) {
|
||||
return new BufferedImage(32,
|
||||
32,
|
||||
BufferedImage.TYPE_BYTE_BINARY,
|
||||
createColorModel(numberColors));
|
||||
}
|
||||
}
|
84
jdk/test/javax/imageio/plugins/png/WriteProgressive.java
Normal file
84
jdk/test/javax/imageio/plugins/png/WriteProgressive.java
Normal file
@ -0,0 +1,84 @@
|
||||
/*
|
||||
* Copyright (c) 2001, 2017, 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 4432615
|
||||
* @summary Tests progressive writing in the PNG encoder
|
||||
* @modules java.desktop/com.sun.imageio.plugins.png
|
||||
*/
|
||||
|
||||
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 java.util.Random;
|
||||
|
||||
import javax.imageio.IIOImage;
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.ImageWriteParam;
|
||||
import javax.imageio.ImageWriter;
|
||||
import javax.imageio.stream.ImageOutputStream;
|
||||
|
||||
public class WriteProgressive {
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
Iterator witer = ImageIO.getImageWritersByFormatName("png");
|
||||
ImageWriter w = (ImageWriter)witer.next();
|
||||
|
||||
File f = File.createTempFile("WriteProgressive", ".png");
|
||||
ImageOutputStream ios = ImageIO.createImageOutputStream(f);
|
||||
w.setOutput(ios);
|
||||
|
||||
BufferedImage bi = new BufferedImage(100, 100,
|
||||
BufferedImage.TYPE_3BYTE_BGR);
|
||||
Graphics2D g = bi.createGraphics();
|
||||
Random r = new Random(10);
|
||||
for (int i = 0; i < 10000; i++) {
|
||||
Color c =
|
||||
new Color(r.nextInt(256), r.nextInt(256), r.nextInt(256));
|
||||
g.setColor(c);
|
||||
g.fillRect(r.nextInt(100), r.nextInt(100), 1, 1);
|
||||
}
|
||||
|
||||
IIOImage iioimage = new IIOImage(bi, null, null);
|
||||
|
||||
ImageWriteParam param = w.getDefaultWriteParam();
|
||||
param.setProgressiveMode(ImageWriteParam.MODE_DEFAULT);
|
||||
|
||||
try {
|
||||
w.write(null, iioimage, param);
|
||||
} catch (NullPointerException npe) {
|
||||
throw new RuntimeException("Got NPE during write!");
|
||||
}
|
||||
|
||||
ios.close();
|
||||
|
||||
BufferedImage bi2 = ImageIO.read(f);
|
||||
f.delete();
|
||||
|
||||
ImageCompare.compare(bi, bi2);
|
||||
}
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 2017, 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 4895483
|
||||
* @summary Test checks that the IllegalStateException was thrown if input was
|
||||
* not set to the WBMPImageReader
|
||||
*/
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.ImageReader;
|
||||
import javax.imageio.metadata.IIOMetadata;
|
||||
|
||||
public class EmptyInputWbmpMetadataTest {
|
||||
private static String fmt = "BMP";
|
||||
|
||||
public static void main(String[] args) {
|
||||
boolean isPassed = false;
|
||||
ImageReader ir = (ImageReader)ImageIO.getImageReadersByFormatName(fmt).next();
|
||||
|
||||
if (ir == null) {
|
||||
throw new RuntimeException("No available reader for " + fmt);
|
||||
}
|
||||
IIOMetadata meta = null;
|
||||
try {
|
||||
meta = ir.getImageMetadata(0);
|
||||
} catch (IllegalStateException e) {
|
||||
System.out.println("Correct exception was thrown. Test passed.");
|
||||
isPassed = true;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (!isPassed) {
|
||||
throw new RuntimeException("The IllegalStateException was not thrown."
|
||||
+"Test failed.");
|
||||
}
|
||||
}
|
||||
}
|
68
jdk/test/javax/imageio/plugins/wbmp/GetImageTypesTest.java
Normal file
68
jdk/test/javax/imageio/plugins/wbmp/GetImageTypesTest.java
Normal file
@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 2017, 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 4928273
|
||||
* @summary Verifies what IllegalStateException is thrown if image input was not
|
||||
* set
|
||||
*/
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.ImageReader;
|
||||
|
||||
public class GetImageTypesTest {
|
||||
|
||||
private static final String format = "wbmp";
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
boolean passed = false;
|
||||
ImageReader ir = (ImageReader)ImageIO.getImageReadersByFormatName(format).next();
|
||||
|
||||
if (ir == null) {
|
||||
throw new RuntimeException("No matching reader found. Test Failed");
|
||||
}
|
||||
|
||||
try {
|
||||
Iterator types = ir.getImageTypes(0);
|
||||
} catch (IllegalStateException e) {
|
||||
System.out.println("Test passed.");
|
||||
passed = true;
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Unexpected exception was thrown. "
|
||||
+ "Test failed.");
|
||||
}
|
||||
|
||||
if (!passed) {
|
||||
throw new RuntimeException("IllegalStateException is not thrown when "
|
||||
+ "calling getImageTypes() without setting "
|
||||
+ "the input source for the image format: "
|
||||
+ format
|
||||
+ ". Test failed");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
93
jdk/test/javax/imageio/plugins/wbmp/ValidWbmpTest.java
Normal file
93
jdk/test/javax/imageio/plugins/wbmp/ValidWbmpTest.java
Normal file
@ -0,0 +1,93 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 2017, 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 4924512
|
||||
* @summary Test that wbmp image reader detects incorrect image format
|
||||
*/
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
|
||||
import javax.imageio.IIOException;
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.ImageReader;
|
||||
import javax.imageio.stream.ImageInputStream;
|
||||
|
||||
public class ValidWbmpTest {
|
||||
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
String[] formats = { "JPEG", "PNG", "BMP" };
|
||||
|
||||
BufferedImage img = new BufferedImage(100, 100,
|
||||
BufferedImage.TYPE_BYTE_GRAY);
|
||||
Graphics g = img.createGraphics();
|
||||
g.setColor(Color.white);
|
||||
g.fillRect(0,0,100,100);
|
||||
g.setColor(Color.black);
|
||||
g.fillRect(10,10,80,80);
|
||||
|
||||
ImageReader ir = (ImageReader)ImageIO.getImageReadersByFormatName("WBMP").next();
|
||||
if (ir==null) {
|
||||
throw new RuntimeException("No readers for WBMP format!");
|
||||
}
|
||||
for(int i=0; i<formats.length; i++) {
|
||||
System.out.println("Test " + formats[i] + " stream...");
|
||||
boolean passed = false;
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
ImageIO.write(img, formats[i], baos);
|
||||
baos.close();
|
||||
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
|
||||
|
||||
ImageInputStream iis = null;
|
||||
iis = ImageIO.createImageInputStream(bais);
|
||||
ir.setInput(iis);
|
||||
try {
|
||||
BufferedImage res = ir.read(0);
|
||||
} catch (IIOException e) {
|
||||
StackTraceElement[] stack = e.getStackTrace();
|
||||
if (ir.getClass().getName().equals(stack[0].getClassName())
|
||||
&& "readHeader".equals(stack[0].getMethodName()))
|
||||
{
|
||||
passed = true;
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
}
|
||||
|
||||
if (!passed) {
|
||||
throw new RuntimeException("Test failed!");
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException("Unexpected exception. Test failed.");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
230
jdk/test/javax/imageio/plugins/wbmp/WBMPPluginTest.java
Normal file
230
jdk/test/javax/imageio/plugins/wbmp/WBMPPluginTest.java
Normal file
@ -0,0 +1,230 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 2017, 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 4641872
|
||||
* @summary Tests writing and reading abilities of WBMP plugin
|
||||
*/
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.image.ColorModel;
|
||||
import java.awt.image.Raster;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Iterator;
|
||||
|
||||
import javax.imageio.IIOException;
|
||||
import javax.imageio.IIOImage;
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.ImageReader;
|
||||
import javax.imageio.ImageTypeSpecifier;
|
||||
import javax.imageio.ImageWriteParam;
|
||||
import javax.imageio.ImageWriter;
|
||||
import javax.imageio.metadata.IIOMetadata;
|
||||
|
||||
public class WBMPPluginTest {
|
||||
|
||||
private static final int[] types = {
|
||||
BufferedImage.TYPE_INT_RGB, // = 1;
|
||||
BufferedImage.TYPE_INT_ARGB, // = 2;
|
||||
BufferedImage.TYPE_INT_ARGB_PRE, // = 3;
|
||||
BufferedImage.TYPE_INT_BGR, // = 4;
|
||||
BufferedImage.TYPE_3BYTE_BGR, // = 5;
|
||||
BufferedImage.TYPE_4BYTE_ABGR, // = 6;
|
||||
BufferedImage.TYPE_4BYTE_ABGR_PRE, // 7
|
||||
BufferedImage.TYPE_USHORT_565_RGB, // 8
|
||||
BufferedImage.TYPE_USHORT_555_RGB, // 9
|
||||
BufferedImage.TYPE_BYTE_GRAY, // 10
|
||||
BufferedImage.TYPE_USHORT_GRAY, //11
|
||||
BufferedImage.TYPE_BYTE_BINARY, //12
|
||||
BufferedImage.TYPE_BYTE_INDEXED //13
|
||||
};
|
||||
|
||||
private static String format = "WBMP";
|
||||
|
||||
private static ImageReader ir = null;
|
||||
private static ImageWriter iw = null;
|
||||
private BufferedImage img;
|
||||
private ImageWriteParam param;
|
||||
private ByteArrayOutputStream baos;
|
||||
|
||||
private static void init() {
|
||||
|
||||
Iterator i = ImageIO.getImageWritersByFormatName(format);
|
||||
if (!i.hasNext()) {
|
||||
throw new RuntimeException("No available ImageWrites for "+format+" format!");
|
||||
}
|
||||
iw = (ImageWriter)i.next();
|
||||
|
||||
i = ImageIO.getImageReadersByFormatName(format);
|
||||
if (!i.hasNext()) {
|
||||
throw new RuntimeException("No available ImageReaders for " +format+" format!");
|
||||
}
|
||||
|
||||
ir = (ImageReader)i.next();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
if (args.length > 0) {
|
||||
format = args[0];
|
||||
System.out.println("Test format " + format);
|
||||
}
|
||||
|
||||
init();
|
||||
ImageIO.setUseCache(false);
|
||||
|
||||
for (int i=0; i<types.length; i++) {
|
||||
boolean bPassed = true;
|
||||
Object reason = null;
|
||||
|
||||
try {
|
||||
|
||||
BufferedImage image = createTestImage(types[i]);
|
||||
|
||||
ImageWriteParam param = iw.getDefaultWriteParam();
|
||||
|
||||
WBMPPluginTest t = new WBMPPluginTest(image, param);
|
||||
boolean res = false;
|
||||
res = t.test();
|
||||
if (!res) {
|
||||
bPassed = false;
|
||||
reason = new String("Null result");
|
||||
}
|
||||
} catch (IllegalArgumentException ex) {
|
||||
System.out.println("Expected exception type was caught: " + ex);
|
||||
|
||||
} catch (Throwable ex ) {
|
||||
System.out.println("FAILED");
|
||||
ex.printStackTrace();
|
||||
bPassed = false;
|
||||
reason = ex;
|
||||
throw new RuntimeException("Test for type " + types[i] + " FAILED due to exception");
|
||||
}
|
||||
/*
|
||||
System.out.println("Type " + types[i] + " result: " +
|
||||
(bPassed ? "PASSED" : "FAILED") +
|
||||
((reason != null) ? (" Reason: " + reason) : ""));
|
||||
*/
|
||||
System.out.println("Test for type " + types[i] + " PASSED");
|
||||
}
|
||||
|
||||
System.out.println("END OF TEST");
|
||||
}
|
||||
|
||||
public WBMPPluginTest(BufferedImage img, ImageWriteParam param) {
|
||||
|
||||
this.img = img;
|
||||
this.param = param;
|
||||
baos = new ByteArrayOutputStream();
|
||||
}
|
||||
|
||||
public boolean test() throws IIOException, IOException {
|
||||
|
||||
ir.reset();
|
||||
iw.reset();
|
||||
|
||||
String[] suffixes = iw.getOriginatingProvider().getFileSuffixes();
|
||||
|
||||
IIOMetadata md = iw.getDefaultImageMetadata(new ImageTypeSpecifier(img), param);
|
||||
IIOImage iio_img = new IIOImage(img, null, md);
|
||||
|
||||
System.out.println("Image type " + img.getType());
|
||||
|
||||
String fname = "test"+img.getType()+"."+suffixes[0];
|
||||
|
||||
iw.setOutput(ImageIO.createImageOutputStream(new FileOutputStream(new File(fname))));
|
||||
System.out.print("write image ... ");
|
||||
iw.write(iio_img);
|
||||
System.out.println("OK");
|
||||
System.out.print("read image ... ");
|
||||
|
||||
byte[] ba_image = baos.toByteArray();
|
||||
|
||||
ByteArrayInputStream bais = new ByteArrayInputStream(ba_image);
|
||||
|
||||
ir.setInput(ImageIO.createImageInputStream(new FileInputStream(new File(fname))));
|
||||
|
||||
BufferedImage res = ir.read(0);
|
||||
System.out.println("OK");
|
||||
|
||||
System.out.print("compare images ... ");
|
||||
boolean r = compare(img,res);
|
||||
System.out.println(r?"OK":"FAILED");
|
||||
return r;
|
||||
}
|
||||
|
||||
private boolean compare(BufferedImage in, BufferedImage out) {
|
||||
int width = in.getWidth();
|
||||
int height = in.getHeight();
|
||||
if (out.getWidth() != width || out.getHeight() != height) {
|
||||
throw new RuntimeException("Dimensions changed!");
|
||||
}
|
||||
|
||||
Raster oldras = in.getRaster();
|
||||
ColorModel oldcm = in.getColorModel();
|
||||
Raster newras = out.getRaster();
|
||||
ColorModel newcm = out.getColorModel();
|
||||
|
||||
for (int j = 0; j < height; j++) {
|
||||
for (int i = 0; i < width; i++) {
|
||||
Object oldpixel = oldras.getDataElements(i, j, null);
|
||||
int oldrgb = oldcm.getRGB(oldpixel);
|
||||
int oldalpha = oldcm.getAlpha(oldpixel);
|
||||
|
||||
Object newpixel = newras.getDataElements(i, j, null);
|
||||
int newrgb = newcm.getRGB(newpixel);
|
||||
int newalpha = newcm.getAlpha(newpixel);
|
||||
|
||||
if (newrgb != oldrgb ||
|
||||
newalpha != oldalpha) {
|
||||
throw new RuntimeException("Pixels differ at " + i +
|
||||
", " + j);
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
private static BufferedImage createTestImage(int type) throws IOException {
|
||||
|
||||
int w = 200;
|
||||
int h = 200;
|
||||
BufferedImage b = new BufferedImage(w, h, type);
|
||||
Graphics2D g = b.createGraphics();
|
||||
g.setColor(Color.white);
|
||||
g.fillRect(0,0, w, h);
|
||||
g.setColor(Color.black);
|
||||
g.fillOval(10, 10, w -20, h-20);
|
||||
|
||||
return b;
|
||||
}
|
||||
|
||||
}
|
106
jdk/test/javax/imageio/plugins/wbmp/WbmpBigDestinationTest.java
Normal file
106
jdk/test/javax/imageio/plugins/wbmp/WbmpBigDestinationTest.java
Normal file
@ -0,0 +1,106 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 2017, 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 4929367
|
||||
* @summary tests what BMP image was decoded correctly if destination buffered
|
||||
* image is bigger than source image
|
||||
*/
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Iterator;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.ImageReadParam;
|
||||
import javax.imageio.ImageReader;
|
||||
import javax.imageio.ImageTypeSpecifier;
|
||||
import javax.imageio.ImageWriter;
|
||||
|
||||
public class WbmpBigDestinationTest {
|
||||
static String format = "WBMP";
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
BufferedImage src = new BufferedImage(100, 100,
|
||||
BufferedImage.TYPE_BYTE_BINARY);
|
||||
Graphics2D g = src.createGraphics();
|
||||
g.setColor(Color.white);
|
||||
g.fillRect(0,0,100, 100);
|
||||
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
|
||||
ImageWriter iw =
|
||||
(ImageWriter)ImageIO.getImageWritersByFormatName(format).next();
|
||||
if (iw == null) {
|
||||
throw new RuntimeException("No writer available. Test failed.");
|
||||
}
|
||||
|
||||
iw.setOutput(ImageIO.createImageOutputStream(baos));
|
||||
iw.write(src);
|
||||
|
||||
byte[] data = baos.toByteArray();
|
||||
|
||||
ImageReader ir =
|
||||
(ImageReader)ImageIO.getImageReadersByFormatName(format).next();
|
||||
ir.setInput(
|
||||
ImageIO.createImageInputStream(
|
||||
new ByteArrayInputStream(data)));
|
||||
|
||||
Iterator specifiers = ir.getImageTypes(0);
|
||||
ImageTypeSpecifier typeSpecifier = null;
|
||||
|
||||
if (specifiers.hasNext()) {
|
||||
typeSpecifier = (ImageTypeSpecifier) specifiers.next();
|
||||
}
|
||||
ImageReadParam param = new ImageReadParam();
|
||||
BufferedImage dst = typeSpecifier.createBufferedImage(200, 200);
|
||||
param.setDestination(dst);
|
||||
|
||||
ir.read(0, param);
|
||||
|
||||
checkResults(src,dst);
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException("Unexpected exception. Test failed.");
|
||||
}
|
||||
}
|
||||
|
||||
private static void checkResults(BufferedImage src, BufferedImage dst) {
|
||||
for(int x=0; x<src.getWidth(); x++) {
|
||||
for(int y=0; y<src.getHeight(); y++) {
|
||||
int srcRgb = src.getRGB(x,y);
|
||||
int dstRgb = dst.getRGB(x,y);
|
||||
if (srcRgb != dstRgb) {
|
||||
throw new RuntimeException("Images are different at point ["
|
||||
+ x + "," + y + "]");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,152 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 2017, 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 4895512
|
||||
* @summary Test that WBMPImageWriter return non-null default image metadata
|
||||
*/
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.Iterator;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.ImageTypeSpecifier;
|
||||
import javax.imageio.ImageWriteParam;
|
||||
import javax.imageio.ImageWriter;
|
||||
import javax.imageio.metadata.IIOMetadata;
|
||||
|
||||
import org.w3c.dom.NamedNodeMap;
|
||||
import org.w3c.dom.Node;
|
||||
|
||||
public class WbmpDefaultImageMetadataTest {
|
||||
ImageWriter writer = null;
|
||||
IIOMetadata imageData = null;
|
||||
ImageWriteParam writeParam = null;
|
||||
BufferedImage bimg = null;
|
||||
|
||||
public WbmpDefaultImageMetadataTest(String format) {
|
||||
try {
|
||||
bimg = new BufferedImage(200, 200, bimg.TYPE_INT_RGB);
|
||||
Graphics gg = bimg.getGraphics();
|
||||
gg.setColor(Color.red);
|
||||
gg.fillRect(50, 50, 100, 100);
|
||||
|
||||
Iterator it = ImageIO.getImageWritersByFormatName(format);
|
||||
if (it.hasNext()) {
|
||||
writer = (ImageWriter) it.next();
|
||||
}
|
||||
if (writer == null) {
|
||||
throw new RuntimeException("No writer available for the given format."
|
||||
+ " Test failed.");
|
||||
}
|
||||
writeParam = writer.getDefaultWriteParam();
|
||||
|
||||
System.out.println("Testing Image Metadata for "+format+"\n");
|
||||
imageData = writer.getDefaultImageMetadata(new ImageTypeSpecifier(bimg), writeParam);
|
||||
if (imageData == null) {
|
||||
System.out.println("return value is null. No default image metadata is associated with "+format+" writer");
|
||||
throw new RuntimeException("Default image metadata is null."
|
||||
+ " Test failed.");
|
||||
}
|
||||
int j = 0;
|
||||
String imageDataNames[] = null;
|
||||
if(imageData != null) {
|
||||
System.out.println("Is standard metadata format supported (Image) ? "+
|
||||
imageData.isStandardMetadataFormatSupported() );
|
||||
imageDataNames = imageData.getMetadataFormatNames();
|
||||
System.out.println("\nAll supported Metadata Format Names\n");
|
||||
if(imageDataNames!=null){
|
||||
for(j=0; j<imageDataNames.length; j++) {
|
||||
System.out.println("FORMAT NAME: "+imageDataNames[j]);
|
||||
if (imageDataNames[j].equals(imageData.getNativeMetadataFormatName())) {
|
||||
System.out.println("This is a Native Metadata format\n");
|
||||
} else {
|
||||
System.out.println("\n");
|
||||
}
|
||||
System.out.println("");
|
||||
System.out.println("IIOImageMetadata DOM tree for "+imageDataNames[j]);
|
||||
System.out.println("");
|
||||
Node imageNode = imageData.getAsTree(imageDataNames[j]);
|
||||
displayMetadata(imageNode);
|
||||
System.out.println("\n\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
}catch(Exception e){
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException("Exception was thrown."
|
||||
+ " Test failed.");
|
||||
}
|
||||
}
|
||||
|
||||
public void displayMetadata(Node root) {
|
||||
displayMetadata(root, 0);
|
||||
}
|
||||
|
||||
void indent(int level) {
|
||||
for (int i = 0; i < level; i++) {
|
||||
System.out.print(" ");
|
||||
}
|
||||
}
|
||||
|
||||
void displayMetadata(Node node, int level) {
|
||||
indent(level); // emit open tag
|
||||
System.out.print("<" + node.getNodeName());
|
||||
NamedNodeMap map = node.getAttributes();
|
||||
if (map != null) { // print attribute values
|
||||
int length = map.getLength();
|
||||
for (int i = 0; i < length; i++) {
|
||||
Node attr = map.item(i);
|
||||
System.out.print(" " + attr.getNodeName() +
|
||||
"=\"" + attr.getNodeValue() + "\"");
|
||||
}
|
||||
}
|
||||
Node child = node.getFirstChild();
|
||||
|
||||
if (node.getNodeValue() != null && !node.getNodeValue().equals("") ) {
|
||||
System.out.println(">");
|
||||
indent(level);
|
||||
System.out.println(node.getNodeValue());
|
||||
indent(level); // emit close tag
|
||||
System.out.println("</" + node.getNodeName() + ">");
|
||||
} else if (child != null) {
|
||||
System.out.println(">"); // close current tag
|
||||
while (child != null) { // emit child tags recursively
|
||||
displayMetadata(child, level + 1);
|
||||
child = child.getNextSibling();
|
||||
}
|
||||
indent(level); // emit close tag
|
||||
System.out.println("</" + node.getNodeName() + ">");
|
||||
} else {
|
||||
System.out.println("/>");
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String args[]) {
|
||||
WbmpDefaultImageMetadataTest test =
|
||||
new WbmpDefaultImageMetadataTest("wbmp");
|
||||
}
|
||||
}
|
@ -0,0 +1,272 @@
|
||||
#!/bin/ksh -p
|
||||
# Copyright (c) 2005, 2017, 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 6342404 7078379 8167503
|
||||
#
|
||||
# @summary Test verifies that incorrectly configured ImageIO plugin spi
|
||||
# does not affect registration of other ImageIO plugin in the
|
||||
# applet context.
|
||||
#
|
||||
#
|
||||
# @compile IIOPluginTest.java
|
||||
# @compile DummyReaderPluginSpi.java
|
||||
# @run shell BadPluginConfigurationTest.sh
|
||||
|
||||
# There are several resources which need to be present before many
|
||||
# shell scripts can run. Following are examples of how to check for
|
||||
# many common ones.
|
||||
#
|
||||
# Note that the shell used is the Korn Shell, KSH
|
||||
#
|
||||
# Also note, it is recommended that make files NOT be used. Rather,
|
||||
# put the individual commands directly into this file. That way,
|
||||
# it is possible to use command line arguments and other shell tech-
|
||||
# niques to find the compiler, etc on different systems. For example,
|
||||
# a different path could be used depending on whether this were a
|
||||
# Solaris or Win32 machine, which is more difficult (if even possible)
|
||||
# in a make file.
|
||||
|
||||
|
||||
# Beginning of subroutines:
|
||||
status=1
|
||||
|
||||
#Call this from anywhere to fail the test with an error message
|
||||
# usage: fail "reason why the test failed"
|
||||
fail()
|
||||
{ echo "The test failed :-("
|
||||
echo "$*" 1>&2
|
||||
echo "exit status was $status"
|
||||
exit $status
|
||||
} #end of fail()
|
||||
|
||||
#Call this from anywhere to pass the test with a message
|
||||
# usage: pass "reason why the test passed if applicable"
|
||||
pass()
|
||||
{ echo "The test passed!!!"
|
||||
echo "$*" 1>&2
|
||||
exit 0
|
||||
} #end of pass()
|
||||
|
||||
# end of subroutines
|
||||
|
||||
|
||||
# The beginning of the script proper
|
||||
|
||||
# Checking for proper OS
|
||||
OS=`uname -s`
|
||||
case "$OS" in
|
||||
SunOS | Linux | Darwin )
|
||||
FILESEP="/"
|
||||
PATHSEP=":"
|
||||
TMP=`cd /tmp; pwd -P`
|
||||
;;
|
||||
|
||||
Windows* )
|
||||
FILESEP="\\"
|
||||
PATHSEP=";"
|
||||
TMP=`cd "${SystemRoot}/Temp"; echo ${PWD}`
|
||||
;;
|
||||
|
||||
CYGWIN* )
|
||||
FILESEP="/"
|
||||
PATHSEP=";"
|
||||
TMP="/tmp"
|
||||
;;
|
||||
|
||||
# catch all other OSs
|
||||
* )
|
||||
echo "Unrecognized system! $OS"
|
||||
fail "Unrecognized system! $OS"
|
||||
;;
|
||||
esac
|
||||
|
||||
# Want this test to run standalone as well as in the harness, so do the
|
||||
# following to copy the test's directory into the harness's scratch directory
|
||||
# and set all appropriate variables:
|
||||
|
||||
if [ -z "${TESTJAVA}" ] ; then
|
||||
# TESTJAVA is not set, so the test is running stand-alone.
|
||||
# TESTJAVA holds the path to the root directory of the build of the JDK
|
||||
# to be tested. That is, any java files run explicitly in this shell
|
||||
# should use TESTJAVA in the path to the java interpreter.
|
||||
# So, we'll set this to the JDK spec'd on the command line. If none
|
||||
# is given on the command line, tell the user that and use a cheesy
|
||||
# default.
|
||||
# THIS IS THE JDK BEING TESTED.
|
||||
if [ -n "$1" ] ;
|
||||
then TESTJAVA=$1
|
||||
else fail "no JDK specified on command line!"
|
||||
fi
|
||||
TESTSRC=.
|
||||
TESTCLASSES=.
|
||||
STANDALONE=1;
|
||||
fi
|
||||
echo "JDK under test is: $TESTJAVA"
|
||||
|
||||
#Deal with .class files:
|
||||
if [ -n "${STANDALONE}" ] ;
|
||||
then
|
||||
#if standalone, remind user to cd to dir. containing test before running it
|
||||
echo "Just a reminder: cd to the dir containing this test when running it"
|
||||
# then compile all .java files (if there are any) into .class files
|
||||
if [ -a *.java ] ;
|
||||
then echo "Reminder, this test should be in its own directory with all"
|
||||
echo "supporting files it needs in the directory with it."
|
||||
${COMPILEJAVA}/bin/javac ./*.java ;
|
||||
fi
|
||||
# else in harness so copy all the class files from where jtreg put them
|
||||
# over to the scratch directory this test is running in.
|
||||
else cp ${TESTCLASSES}/*.class . ;
|
||||
fi
|
||||
|
||||
#if in test harness, then copy the entire directory that the test is in over
|
||||
# to the scratch directory. This catches any support files needed by the test.
|
||||
if [ -z "${STANDALONE}" ] ;
|
||||
then cp ${TESTSRC}/*.java .
|
||||
fi
|
||||
|
||||
#Just before executing anything, make sure it has executable permission!
|
||||
chmod 777 ./*
|
||||
|
||||
############### YOUR TEST CODE HERE!!!!!!! #############
|
||||
|
||||
#All files required for the test should be in the same directory with
|
||||
# this file. If converting a standalone test to run with the harness,
|
||||
# as long as all files are in the same directory and it returns 0 for
|
||||
# pass, you should be able to cut and paste it into here and it will
|
||||
# run with the test harness.
|
||||
|
||||
# This is an example of running something -- test
|
||||
# The stuff below catches the exit status of test then passes or fails
|
||||
# this shell test as appropriate ( 0 status is considered a pass here )
|
||||
|
||||
echo
|
||||
echo ------ PREPARE TEST PLUGIN ---------
|
||||
|
||||
# note that we can not use some subdirectory of the
|
||||
# scratch dir as the plugin dst dir because the test
|
||||
# app have file read permission for all subdirs of the
|
||||
# scratch dir
|
||||
|
||||
PLUGINDST_DIR=${TMP}/test_ext
|
||||
#PLUGINDST_DIR=${TESTJAVA}/lib/ext
|
||||
TEST_PLUGIN=dummy.jar
|
||||
|
||||
if [ ! -d ${PLUGINDST_DIR} ] ; then
|
||||
mkdir ${PLUGINDST_DIR}
|
||||
fi
|
||||
|
||||
# remove old service declaration
|
||||
if [ -d META-INF ] ; then
|
||||
rm -rf META-INF
|
||||
fi
|
||||
|
||||
# generate the service declaration
|
||||
if [ ! -d META_INF ] ; then
|
||||
mkdir META-INF
|
||||
mkdir META-INF/services
|
||||
fi
|
||||
|
||||
# add wrong record to the service configuration
|
||||
echo "BadReaderPluginSpi" > META-INF/services/javax.imageio.spi.ImageReaderSpi
|
||||
|
||||
echo "DummyReaderPluginSpi" >> META-INF/services/javax.imageio.spi.ImageReaderSpi
|
||||
|
||||
|
||||
${TESTJAVA}/bin/jar -cvf ${TEST_PLUGIN} DummyReaderPluginSpi*.class META-INF/services/javax.imageio.spi.ImageReaderSpi
|
||||
|
||||
echo ----- TEST PLUGIN IS READY --------
|
||||
echo
|
||||
echo ----- INSTALL PLUGIN --------
|
||||
echo "Install test plugin to ${PLUGINDST_DIR}"
|
||||
if [ -f ${PLUGINDST_DIR}/${TEST_PLUGIN} ] ; then
|
||||
echo "Remove old plugin..."
|
||||
rm -f ${PLUGINDST_DIR}/${TEST_PLUGIN}
|
||||
fi
|
||||
mv -f ${TEST_PLUGIN} ${PLUGINDST_DIR}
|
||||
if [ -f ${PLUGINDST_DIR}/${TEST_PLUGIN} ] ; then
|
||||
echo Test plugin is installed.
|
||||
else
|
||||
fail "Unable to install test plugin to $PLUGINDST_DIR"
|
||||
fi
|
||||
echo ----- PLUGIN IS INSTALLED ------
|
||||
echo
|
||||
echo ----- CLEAN PLUGIN TEMPORARY FILES -----
|
||||
rm -rf DummyReaderPluginSpi*.class META-INF
|
||||
echo ----- CLEANING IS COMPLETE -------
|
||||
echo
|
||||
|
||||
|
||||
case "$OS" in
|
||||
CYGWIN* )
|
||||
TEST_CODEBASE=$(cygpath -m ${PWD})
|
||||
TEST_PLUGIN_JAR=$(cygpath -m ${PLUGINDST_DIR}${FILESEP}${TEST_PLUGIN})
|
||||
;;
|
||||
|
||||
# catch all other OSs
|
||||
* )
|
||||
TEST_CODEBASE=${PWD}
|
||||
TEST_PLUGIN_JAR=${PLUGINDST_DIR}${FILESEP}${TEST_PLUGIN}
|
||||
;;
|
||||
esac
|
||||
|
||||
|
||||
# Update policy file to grant read permission
|
||||
echo "grant codeBase \"file:${TEST_CODEBASE}\" {" > classpath.policy
|
||||
echo " permission java.io.FilePermission \"${TEST_PLUGIN_JAR}\", \"read\";" >> classpath.policy
|
||||
echo " permission java.util.PropertyPermission \"test.5076692.property\", \"read\";" >> classpath.policy
|
||||
echo "};" >> classpath.policy
|
||||
echo "grant codeBase \"file:${TEST_PLUGIN_JAR}\" {" >> classpath.policy
|
||||
echo " permission java.util.PropertyPermission \"test.5076692.property\", \"read\";" >> classpath.policy
|
||||
echo "};" >> classpath.policy
|
||||
|
||||
echo ---------------------
|
||||
echo --- Applet policy ---
|
||||
echo ---------------------
|
||||
cat classpath.policy
|
||||
echo ---------------------
|
||||
echo
|
||||
|
||||
echo -------------------------------
|
||||
echo --- Applet Classpath Test ---
|
||||
echo -------------------------------
|
||||
#
|
||||
# please note that we need to use "==" in setup of the java.security.policy
|
||||
# property in order to overwrite policies defined in the user policy file
|
||||
# For more details see:
|
||||
# http://java.sun.com/j2se/1.5.0/docs/guide/security/PolicyFiles.html)
|
||||
#
|
||||
|
||||
${TESTJAVA}/bin/java ${TESTVMOPTS} -cp ".${PATHSEP}${TEST_PLUGIN_JAR}" \
|
||||
-Djava.security.policy==classpath.policy \
|
||||
-Djava.security.manager IIOPluginTest
|
||||
|
||||
status=$?
|
||||
|
||||
if [ $status -eq "0" ] ; then
|
||||
pass ""
|
||||
else
|
||||
fail "Test failed due to test plugin was not found."
|
||||
fi
|
||||
|
@ -0,0 +1,82 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2017, 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.
|
||||
*/
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Locale;
|
||||
|
||||
import javax.imageio.IIOException;
|
||||
import javax.imageio.ImageReader;
|
||||
import javax.imageio.spi.ImageReaderSpi;
|
||||
import javax.imageio.spi.ServiceRegistry;
|
||||
|
||||
public class DummyReaderPluginSpi extends ImageReaderSpi {
|
||||
|
||||
private static String [] writerSpiNames =
|
||||
{"DummyWriterPluginSpi"};
|
||||
public static String[] formatNames = {"test_5076692", "TEST_5076692"};
|
||||
public static String[] entensions = {"test_5076692"};
|
||||
public static String[] mimeType = {"image/test_5076692"};
|
||||
|
||||
private boolean registered = false;
|
||||
|
||||
public DummyReaderPluginSpi() {
|
||||
super("Sun Microsystems, Inc.",
|
||||
"1.0",
|
||||
formatNames,
|
||||
entensions,
|
||||
mimeType,
|
||||
"DummyPluginReader",
|
||||
STANDARD_INPUT_TYPE,
|
||||
writerSpiNames,
|
||||
false,
|
||||
null, null, null, null,
|
||||
false,
|
||||
"",
|
||||
"",
|
||||
null, null);
|
||||
}
|
||||
|
||||
public void onRegistration(ServiceRegistry registry,
|
||||
Class<?> category) {
|
||||
if (registered) {
|
||||
return;
|
||||
}
|
||||
|
||||
System.getProperty("test.5076692.property", "not found");
|
||||
|
||||
registered = true;
|
||||
}
|
||||
|
||||
public String getDescription(Locale locale) {
|
||||
return "Standard Dummy Image Reader";
|
||||
}
|
||||
|
||||
public boolean canDecodeInput(Object source) throws IOException {
|
||||
return false;
|
||||
}
|
||||
|
||||
public ImageReader createReaderInstance(Object extension)
|
||||
throws IIOException {
|
||||
return null;
|
||||
}
|
||||
}
|
@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2017, 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.
|
||||
*/
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
public class IIOPluginTest {
|
||||
|
||||
public static String[] dummyformatNames = {"test_5076692", "TEST_5076692"};
|
||||
public static String[] dummymimeType = {"image/test_5076692"};
|
||||
|
||||
public static void main(String[] args) {
|
||||
SecurityManager sm = System.getSecurityManager();
|
||||
System.out.println("Sm is " + sm);
|
||||
|
||||
String formatNames[] = ImageIO.getReaderFormatNames();
|
||||
String readerMimeTypes[] = ImageIO.getReaderMIMETypes();
|
||||
|
||||
if (!isPresent(dummyformatNames, formatNames) ||
|
||||
!isPresent(dummymimeType, readerMimeTypes)) {
|
||||
throw new RuntimeException("No test plugin available!");
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isPresent(String[] t, String[] r) {
|
||||
for (int i=0; i<t.length; i++) {
|
||||
if (!isPresent(t[i], r)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean isPresent(String s, String[] a) {
|
||||
for (int i=0; i<a.length; i++) {
|
||||
System.out.println(a[i] + " ");
|
||||
if (s.equals(a[i])) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright (c) 2001, 2017, 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 4415456
|
||||
* @summary Tests the ability to create a MemoryCacheImageOutputStream using the
|
||||
* normal service provider interface mechanisms
|
||||
*/
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.stream.ImageOutputStream;
|
||||
|
||||
public class CreateMemoryCacheOutputStream {
|
||||
|
||||
public static void main(String[] args) {
|
||||
ImageIO.setUseCache(false);
|
||||
OutputStream os = new ByteArrayOutputStream();
|
||||
ImageOutputStream stream = null;
|
||||
try {
|
||||
stream = ImageIO.createImageOutputStream(os);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Got exception " + e);
|
||||
}
|
||||
if (stream == null) {
|
||||
throw new RuntimeException("Got null stream!");
|
||||
}
|
||||
}
|
||||
}
|
158
jdk/test/javax/imageio/spi/DeregisterAllSpiTest.java
Normal file
158
jdk/test/javax/imageio/spi/DeregisterAllSpiTest.java
Normal file
@ -0,0 +1,158 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 2017, 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 4835841
|
||||
* @summary This test verifies that we will able to register new SPI after
|
||||
* deregistration all previously registered SPIs by using
|
||||
* deregisterAll() method
|
||||
*/
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Locale;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.ImageReader;
|
||||
import javax.imageio.spi.IIORegistry;
|
||||
import javax.imageio.spi.ImageReaderSpi;
|
||||
import javax.imageio.spi.ServiceRegistry;
|
||||
import javax.imageio.stream.ImageInputStream;
|
||||
|
||||
public class DeregisterAllSpiTest {
|
||||
|
||||
public DeregisterAllSpiTest() throws Exception {
|
||||
ImageReaderSpi BMPSpi = new BMPImageReaderSPI();
|
||||
IIORegistry.getDefaultInstance().registerServiceProvider(BMPSpi);
|
||||
|
||||
System.out.println("Reader Format Names available in the registry");
|
||||
String formatNames[] = ImageIO.getReaderFormatNames();
|
||||
if( formatNames == null || formatNames.length <= 0) {
|
||||
throw new RuntimeException("No registered ImageReaders!");
|
||||
}
|
||||
for (int x=0; x < formatNames.length; x++) {
|
||||
System.out.println("format "+formatNames[x]);
|
||||
}
|
||||
|
||||
IIORegistry.getDefaultInstance().deregisterAll();
|
||||
|
||||
System.out.println("\nReader Format Names after deregistering all SPIs");
|
||||
formatNames = ImageIO.getReaderFormatNames();
|
||||
if(formatNames.length == 0) {
|
||||
System.out.println("No readers available\n");
|
||||
} else {
|
||||
throw new RuntimeException("Some providers was not deregistered!");
|
||||
}
|
||||
|
||||
IIORegistry.getDefaultInstance().registerServiceProvider(BMPSpi);
|
||||
System.out.println("Reader Format Names after re-register of BMP Plugin");
|
||||
formatNames = ImageIO.getReaderFormatNames();
|
||||
if(formatNames.length == 0) {
|
||||
throw new RuntimeException("Unable to register new SPI after deregisterAll()!");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void main(String args[]) throws Exception{
|
||||
DeregisterAllSpiTest regis = new DeregisterAllSpiTest();
|
||||
}
|
||||
|
||||
|
||||
public static class BMPImageReaderSPI extends javax.imageio.spi.ImageReaderSpi{
|
||||
|
||||
private static final String vendorName = "Javasoft";
|
||||
|
||||
private static final String version = "2.0";
|
||||
|
||||
private static final String[] names = { "bmp" };
|
||||
|
||||
private static final String[] suffixes = { "bmp" };
|
||||
|
||||
private static final String[] MIMETypes = { "image/x-bmp"};
|
||||
|
||||
private static final String readerClassName =
|
||||
"com.sun.imageio.plugins.png.PNGImageReader";
|
||||
|
||||
private static final String[] writerSpiNames = {
|
||||
"com.sun.imageio.plugins.png.PNGImageWriterSpi"
|
||||
};
|
||||
|
||||
public BMPImageReaderSPI() {
|
||||
super(vendorName,
|
||||
version,
|
||||
names,
|
||||
suffixes,
|
||||
MIMETypes,
|
||||
readerClassName,
|
||||
STANDARD_INPUT_TYPE,
|
||||
writerSpiNames,
|
||||
false,
|
||||
null, null,
|
||||
null, null,
|
||||
true,
|
||||
"BMP Native Metadata",
|
||||
"com.sun.imageio.plugins.png.PNGMetadataFormat",
|
||||
null, null
|
||||
);
|
||||
}
|
||||
|
||||
public String getDescription(Locale locale) {
|
||||
return "Standard BMP image reader";
|
||||
}
|
||||
|
||||
public boolean canDecodeInput(Object input) throws IOException {
|
||||
if (!(input instanceof ImageInputStream)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ImageInputStream stream = (ImageInputStream)input;
|
||||
byte[] b = new byte[8];
|
||||
stream.mark();
|
||||
stream.readFully(b);
|
||||
stream.reset();
|
||||
|
||||
return (b[0] == (byte)137 &&
|
||||
b[1] == (byte)80 &&
|
||||
b[2] == (byte)78 &&
|
||||
b[3] == (byte)71 &&
|
||||
b[4] == (byte)13 &&
|
||||
b[5] == (byte)10 &&
|
||||
b[6] == (byte)26 &&
|
||||
b[7] == (byte)10);
|
||||
}
|
||||
|
||||
public ImageReader createReaderInstance(Object extension) {
|
||||
//return new PNGImageReader(this);
|
||||
return null;
|
||||
}
|
||||
public void onRegistration(ServiceRegistry sr, Class<?> category) {
|
||||
System.out.println("\nfrom OnRegistration: BMP plugin Registered\n");
|
||||
super.onRegistration(sr, category);
|
||||
}
|
||||
|
||||
public void onDeregistration(ServiceRegistry sr, Class<?> category) {
|
||||
System.out.println("\nfrom OnDeregistration: BMP plugin De-Registered\n");
|
||||
//super.onRegistration(sr, category);
|
||||
}
|
||||
}
|
||||
}
|
69
jdk/test/javax/imageio/spi/DeregisterOrderedSpiTest.java
Normal file
69
jdk/test/javax/imageio/spi/DeregisterOrderedSpiTest.java
Normal file
@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 2017, 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 4936495 8037743
|
||||
* @summary This test verifies whether deregistering an ordered spi object does
|
||||
* not throw any exception
|
||||
* @modules java.desktop/com.sun.imageio.plugins.bmp
|
||||
* java.desktop/com.sun.imageio.plugins.gif
|
||||
* java.desktop/com.sun.imageio.plugins.jpeg
|
||||
* java.desktop/com.sun.imageio.plugins.png
|
||||
*/
|
||||
|
||||
import javax.imageio.spi.IIORegistry;
|
||||
import javax.imageio.spi.ImageReaderSpi;
|
||||
import javax.imageio.spi.ServiceRegistry;
|
||||
|
||||
public class DeregisterOrderedSpiTest {
|
||||
|
||||
public DeregisterOrderedSpiTest() {
|
||||
|
||||
try {
|
||||
|
||||
ServiceRegistry reg = IIORegistry.getDefaultInstance();
|
||||
ImageReaderSpi gifSpi = (ImageReaderSpi) reg.getServiceProviderByClass(com.sun.imageio.plugins.gif.GIFImageReaderSpi.class);
|
||||
ImageReaderSpi pngSpi = (ImageReaderSpi) reg.getServiceProviderByClass(com.sun.imageio.plugins.png.PNGImageReaderSpi.class);
|
||||
ImageReaderSpi jpgSpi = (ImageReaderSpi) reg.getServiceProviderByClass(com.sun.imageio.plugins.jpeg.JPEGImageReaderSpi.class);
|
||||
ImageReaderSpi bmpSpi = (ImageReaderSpi) reg.getServiceProviderByClass(com.sun.imageio.plugins.bmp.BMPImageReaderSpi.class);
|
||||
|
||||
boolean ordered = reg.setOrdering(ImageReaderSpi.class, pngSpi,
|
||||
gifSpi);
|
||||
|
||||
ordered = reg.setOrdering(ImageReaderSpi.class, gifSpi, jpgSpi);
|
||||
ordered = reg.setOrdering(ImageReaderSpi.class, bmpSpi, gifSpi);
|
||||
reg.deregisterServiceProvider(gifSpi);
|
||||
System.out.println("PASS");
|
||||
|
||||
} catch (Exception e) {
|
||||
System.out.println("FAIL");
|
||||
throw new RuntimeException("Deregistering a spi object involved in some "
|
||||
+ "ordering throws the following exception: " + e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String args[]) {
|
||||
DeregisterOrderedSpiTest test = new DeregisterOrderedSpiTest();
|
||||
}
|
||||
}
|
72
jdk/test/javax/imageio/spi/OrderingTest.java
Normal file
72
jdk/test/javax/imageio/spi/OrderingTest.java
Normal file
@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 2017, 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 4936445
|
||||
* @summary This test verifies whether setting the order reversely between 2 spi
|
||||
* objects removes the previous ordering that was set between the
|
||||
* same set of spi objects. This is verified by invoking
|
||||
* unsetOrdering() method twice consecutively with respect to the same
|
||||
* spi objects and unsetOrdering() is supposed to return false when
|
||||
* called for the second time.
|
||||
* @modules java.desktop/com.sun.imageio.plugins.gif
|
||||
* java.desktop/com.sun.imageio.plugins.png
|
||||
*/
|
||||
|
||||
import javax.imageio.spi.IIORegistry;
|
||||
import javax.imageio.spi.ImageReaderSpi;
|
||||
import javax.imageio.spi.ServiceRegistry;
|
||||
|
||||
public class OrderingTest {
|
||||
|
||||
public OrderingTest() {
|
||||
|
||||
ServiceRegistry reg = IIORegistry.getDefaultInstance();
|
||||
ImageReaderSpi gifSpi = (ImageReaderSpi) reg.getServiceProviderByClass(com.sun.imageio.plugins.gif.GIFImageReaderSpi.class);
|
||||
ImageReaderSpi pngSpi = (ImageReaderSpi) reg.getServiceProviderByClass(com.sun.imageio.plugins.png.PNGImageReaderSpi.class);
|
||||
|
||||
boolean ordered = reg.setOrdering(ImageReaderSpi.class, gifSpi, pngSpi);
|
||||
|
||||
ordered = reg.setOrdering(ImageReaderSpi.class, pngSpi, gifSpi);
|
||||
|
||||
boolean unordered = reg.unsetOrdering(ImageReaderSpi.class, gifSpi,
|
||||
pngSpi);
|
||||
boolean unordered1 = reg.unsetOrdering(ImageReaderSpi.class, gifSpi,
|
||||
pngSpi);
|
||||
|
||||
if (unordered1) {
|
||||
throw new RuntimeException("FAIL: Ordering 2 spi objects in the "
|
||||
+ "reverse direction does not remove the previous ordering "
|
||||
+ "set between the spi objects and hence unsetOrdering() "
|
||||
+ "returns true for the same spi objects when called consecutively");
|
||||
} else {
|
||||
System.out.println("PASS");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void main(String args[]) {
|
||||
OrderingTest test = new OrderingTest();
|
||||
}
|
||||
}
|
96
jdk/test/javax/imageio/spi/PluginSpiTest.java
Normal file
96
jdk/test/javax/imageio/spi/PluginSpiTest.java
Normal file
@ -0,0 +1,96 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2017, 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 6275112
|
||||
* @summary Test verifies that imageReaders for base image formats return
|
||||
* meaningful name of service provider interface (SPI) for base image
|
||||
* formats
|
||||
* @modules java.desktop/com.sun.imageio.plugins.gif
|
||||
* java.desktop/com.sun.imageio.plugins.png
|
||||
* java.desktop/com.sun.imageio.plugins.jpeg
|
||||
* java.desktop/com.sun.imageio.plugins.bmp
|
||||
* java.desktop/com.sun.imageio.plugins.wbmp
|
||||
*/
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.ImageReader;
|
||||
import javax.imageio.ImageWriter;
|
||||
import javax.imageio.spi.ImageReaderSpi;
|
||||
|
||||
public class PluginSpiTest {
|
||||
|
||||
public static void main(String[] args) {
|
||||
String format[] = { "GIF", "PNG", "JPEG", "BMP", "WBMP" };
|
||||
for (int i = 0; i < format.length; i++) {
|
||||
System.out.println("\nFormat " + format[i]);
|
||||
testFormat(format[i]);
|
||||
}
|
||||
}
|
||||
|
||||
public static void testFormat(String format) {
|
||||
ImageReader reader =
|
||||
ImageIO.getImageReadersByFormatName(format).next();
|
||||
if (reader == null) {
|
||||
throw new RuntimeException("Failed to get reader for " + format);
|
||||
}
|
||||
|
||||
ImageReaderSpi readerSpi = reader.getOriginatingProvider();
|
||||
System.out.println(format + " Reader SPI: " + readerSpi);
|
||||
|
||||
String writerSpiNames[] = readerSpi.getImageWriterSpiNames();
|
||||
if (writerSpiNames == null || writerSpiNames.length == 0) {
|
||||
throw new RuntimeException("Failed to get writer spi names for " +
|
||||
format);
|
||||
}
|
||||
|
||||
System.out.println("Available writer spi names:");
|
||||
for (int i = 0; i < writerSpiNames.length; i++) {
|
||||
System.out.println(writerSpiNames[i]);
|
||||
try {
|
||||
Class spiClass = Class.forName(writerSpiNames[i]);
|
||||
if (spiClass == null) {
|
||||
throw new RuntimeException("Failed to get spi class " +
|
||||
writerSpiNames[i]);
|
||||
}
|
||||
System.out.println("Got class " + spiClass.getName());
|
||||
|
||||
Object spiObject = spiClass.newInstance();
|
||||
if (spiObject == null) {
|
||||
throw new RuntimeException("Failed to instantiate spi " +
|
||||
writerSpiNames[i]);
|
||||
}
|
||||
System.out.println("Got instance " + spiObject);
|
||||
} catch (Throwable e) {
|
||||
throw new RuntimeException("Failed to test spi " +
|
||||
writerSpiNames[i]);
|
||||
}
|
||||
}
|
||||
|
||||
ImageWriter writer = ImageIO.getImageWriter(reader);
|
||||
if (writer == null) {
|
||||
throw new RuntimeException("Failed to get writer for " + format);
|
||||
}
|
||||
}
|
||||
}
|
160
jdk/test/javax/imageio/spi/RegisterPluginTwiceTest.java
Normal file
160
jdk/test/javax/imageio/spi/RegisterPluginTwiceTest.java
Normal file
@ -0,0 +1,160 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 2017, 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 4836432 8037743
|
||||
* @summary This test attempts to register two instances of one ImageReaderSPI.
|
||||
* Expected behavior is that only one instance of ImageReaderSPI will
|
||||
* be registered.
|
||||
*/
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Iterator;
|
||||
import java.util.Locale;
|
||||
|
||||
import javax.imageio.ImageReader;
|
||||
import javax.imageio.spi.IIORegistry;
|
||||
import javax.imageio.spi.ServiceRegistry;
|
||||
import javax.imageio.stream.ImageInputStream;
|
||||
|
||||
public class RegisterPluginTwiceTest {
|
||||
|
||||
public RegisterPluginTwiceTest() throws Exception {
|
||||
BMPImageReaderSPI BMPSpi = new BMPImageReaderSPI();
|
||||
BMPImageReaderSPI BMPSpi1 = new BMPImageReaderSPI();
|
||||
|
||||
IIORegistry regis = IIORegistry.getDefaultInstance();
|
||||
boolean res1
|
||||
= regis.registerServiceProvider(BMPSpi,
|
||||
javax.imageio.spi.ImageReaderSpi.class);
|
||||
boolean res2
|
||||
= regis.registerServiceProvider(BMPSpi1,
|
||||
javax.imageio.spi.ImageReaderSpi.class);
|
||||
|
||||
if(!res1 || res2) {
|
||||
throw new RuntimeException("Bad returned values for registerServiceProvider");
|
||||
}
|
||||
Iterator it = regis.getServiceProviders(Class.forName("javax.imageio.spi.ImageReaderSpi"), true);
|
||||
int count = 0;
|
||||
while (it.hasNext()) {
|
||||
Object o = it.next();
|
||||
if(o instanceof BMPImageReaderSPI) {
|
||||
count++;
|
||||
System.out.println("Found next BMPImageReaderSPI, count = " +count);
|
||||
}
|
||||
}
|
||||
if(count > 1) {
|
||||
throw new RuntimeException("Too many instances of the BMPImageReaderSPI was registered!");
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String args[]) throws Exception{
|
||||
RegisterPluginTwiceTest fnio = new RegisterPluginTwiceTest();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Not a perfect implementation of SPI. This is just a dummy implementation
|
||||
which denotes some arbitrary reader class. The intention is to check how this
|
||||
is getting registered in the registry. Hence some of the values in this class
|
||||
may be inappropriate..
|
||||
*/
|
||||
public static class BMPImageReaderSPI extends javax.imageio.spi.ImageReaderSpi{
|
||||
|
||||
private static final String vendorName = "Javasoft";
|
||||
|
||||
private static final String version = "2.0";
|
||||
|
||||
private static final String[] names = { "bmp" };
|
||||
|
||||
private static final String[] suffixes = { "bmp" };
|
||||
|
||||
private static final String[] MIMETypes = { "image/x-bmp"};
|
||||
|
||||
private static final String readerClassName =
|
||||
"com.sun.imageio.plugins.png.PNGImageReader";
|
||||
|
||||
private static final String[] writerSpiNames = {
|
||||
"com.sun.imageio.plugins.png.PNGImageWriterSpi"
|
||||
};
|
||||
|
||||
public BMPImageReaderSPI() {
|
||||
super(vendorName,
|
||||
version,
|
||||
names,
|
||||
suffixes,
|
||||
MIMETypes,
|
||||
readerClassName,
|
||||
STANDARD_INPUT_TYPE,
|
||||
writerSpiNames,
|
||||
false,
|
||||
null, null,
|
||||
null, null,
|
||||
true,
|
||||
"BMP Native Metadata",
|
||||
"com.sun.imageio.plugins.png.PNGMetadataFormat",
|
||||
null, null
|
||||
);
|
||||
}
|
||||
|
||||
public String getDescription(Locale locale) {
|
||||
return "Standard BMP image reader";
|
||||
}
|
||||
|
||||
public boolean canDecodeInput(Object input) throws IOException {
|
||||
if (!(input instanceof ImageInputStream)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ImageInputStream stream = (ImageInputStream)input;
|
||||
byte[] b = new byte[8];
|
||||
stream.mark();
|
||||
stream.readFully(b);
|
||||
stream.reset();
|
||||
|
||||
return (b[0] == (byte)137 &&
|
||||
b[1] == (byte)80 &&
|
||||
b[2] == (byte)78 &&
|
||||
b[3] == (byte)71 &&
|
||||
b[4] == (byte)13 &&
|
||||
b[5] == (byte)10 &&
|
||||
b[6] == (byte)26 &&
|
||||
b[7] == (byte)10);
|
||||
}
|
||||
|
||||
public ImageReader createReaderInstance(Object extension) {
|
||||
//return new PNGImageReader(this);
|
||||
return null;
|
||||
}
|
||||
public void onRegistration(ServiceRegistry sr, Class<?> category) {
|
||||
//System.out.println("Registered "+category);
|
||||
super.onRegistration(sr, category);
|
||||
}
|
||||
|
||||
public void onDeregistration(ServiceRegistry sr, Class<?> category) {
|
||||
//System.out.println("De-Registered "+category);
|
||||
//super.onRegistration(sr, category);
|
||||
}
|
||||
}
|
||||
}
|
390
jdk/test/javax/imageio/spi/SpiTest.java
Normal file
390
jdk/test/javax/imageio/spi/SpiTest.java
Normal file
@ -0,0 +1,390 @@
|
||||
/*
|
||||
* Copyright (c) 2001, 2017, 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 4395376
|
||||
* @summary Performs various sanity checks on Spi class constructors and get
|
||||
* methods
|
||||
*/
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.Locale;
|
||||
|
||||
import javax.imageio.ImageReader;
|
||||
import javax.imageio.ImageTypeSpecifier;
|
||||
import javax.imageio.ImageWriter;
|
||||
import javax.imageio.spi.IIORegistry;
|
||||
import javax.imageio.spi.IIOServiceProvider;
|
||||
import javax.imageio.spi.ImageReaderSpi;
|
||||
import javax.imageio.spi.ImageReaderWriterSpi;
|
||||
import javax.imageio.spi.ImageWriterSpi;
|
||||
import javax.imageio.spi.ServiceRegistry;
|
||||
|
||||
public class SpiTest {
|
||||
|
||||
String vendorName = null;
|
||||
String version = null;
|
||||
String[] names = null;
|
||||
String[] suffixes = null;
|
||||
String[] MIMETypes = null;
|
||||
String readerClassName = null;
|
||||
String writerClassName = null;
|
||||
Class[] inputTypes = null;
|
||||
Class[] outputTypes = null;
|
||||
String[] writerSpiNames = null;
|
||||
String[] readerSpiNames = null;
|
||||
String nativeStreamMetadataFormatName = null;
|
||||
String nativeStreamMetadataFormatClassName = null;
|
||||
String[] extraStreamMetadataFormatNames = null;
|
||||
String[] extraStreamMetadataFormatClassNames = null;
|
||||
String nativeImageMetadataFormatName = null;
|
||||
String nativeImageMetadataFormatClassName = null;
|
||||
String[] extraImageMetadataFormatNames = null;
|
||||
String[] extraImageMetadataFormatClassNames = null;
|
||||
|
||||
private void error(String message) {
|
||||
// System.out.println("Error: " + message);
|
||||
throw new RuntimeException(message);
|
||||
}
|
||||
|
||||
private void testSpi(IIOServiceProvider spi) {
|
||||
if (spi.getVendorName() == null) {
|
||||
error(spi + " getVendorName == null!");
|
||||
}
|
||||
if (spi.getVersion() == null) {
|
||||
error(spi + " getVersion == null!");
|
||||
}
|
||||
}
|
||||
|
||||
private void testSpi(ImageReaderWriterSpi spi) {
|
||||
testSpi((IIOServiceProvider)spi);
|
||||
if (spi.getFormatNames() == null) {
|
||||
error("spi.getFormatNames == null!");
|
||||
}
|
||||
String[] suffixes = spi.getFileSuffixes();
|
||||
if (suffixes != null && suffixes.length == 0) {
|
||||
error("suffixes.length == 0!");
|
||||
}
|
||||
String[] MIMETypes = spi.getMIMETypes();
|
||||
if (MIMETypes != null && MIMETypes.length == 0) {
|
||||
error("MIMETypes.length == 0!");
|
||||
}
|
||||
if (spi.getPluginClassName() == null) {
|
||||
error("spi.getPluginClassName == null!");
|
||||
}
|
||||
String[] extraStreamMetadataFormatNames =
|
||||
spi.getExtraStreamMetadataFormatNames();
|
||||
if (extraStreamMetadataFormatNames != null &&
|
||||
extraStreamMetadataFormatNames.length == 0) {
|
||||
error("extraStreamMetadataFormatNames.length == 0!");
|
||||
}
|
||||
String[] extraImageMetadataFormatNames =
|
||||
spi.getExtraImageMetadataFormatNames();
|
||||
if (extraImageMetadataFormatNames != null &&
|
||||
extraImageMetadataFormatNames.length == 0) {
|
||||
error("extraImageMetadataFormatNames.length == 0!");
|
||||
}
|
||||
}
|
||||
|
||||
public void testSpi(ImageReaderSpi spi) {
|
||||
testSpi((ImageReaderWriterSpi)spi);
|
||||
Class[] inputTypes = spi.getInputTypes();
|
||||
if (inputTypes == null) {
|
||||
error("inputTypes == null!");
|
||||
}
|
||||
if (inputTypes.length == 0) {
|
||||
error("inputTypes.length == 0!");
|
||||
}
|
||||
String[] writerSpiNames = spi.getImageWriterSpiNames();
|
||||
if (writerSpiNames != null && writerSpiNames.length == 0) {
|
||||
error("writerSpiNames.length == 0!");
|
||||
}
|
||||
}
|
||||
|
||||
public void testSpi(ImageWriterSpi spi) {
|
||||
testSpi((ImageReaderWriterSpi)spi);
|
||||
Class[] outputTypes = spi.getOutputTypes();
|
||||
if (outputTypes == null) {
|
||||
error("outputTypes == null!");
|
||||
}
|
||||
if (outputTypes.length == 0) {
|
||||
error("outputTypes.length == 0!");
|
||||
}
|
||||
String[] readerSpiNames = spi.getImageReaderSpiNames();
|
||||
if (readerSpiNames != null && readerSpiNames.length == 0) {
|
||||
error("readerSpiNames.length == 0!");
|
||||
}
|
||||
}
|
||||
|
||||
private void resetConstructorArguments() {
|
||||
vendorName = null;
|
||||
version = null;
|
||||
names = null;
|
||||
suffixes = null;
|
||||
MIMETypes = null;
|
||||
readerClassName = null;
|
||||
inputTypes = null;
|
||||
outputTypes = null;
|
||||
writerSpiNames = null;
|
||||
readerSpiNames = null;
|
||||
nativeStreamMetadataFormatName = null;
|
||||
nativeStreamMetadataFormatClassName = null;
|
||||
extraStreamMetadataFormatNames = null;
|
||||
extraStreamMetadataFormatClassNames = null;
|
||||
nativeImageMetadataFormatName = null;
|
||||
nativeImageMetadataFormatClassName = null;
|
||||
extraImageMetadataFormatNames = null;
|
||||
extraImageMetadataFormatClassNames = null;
|
||||
}
|
||||
|
||||
private ImageReaderSpi constructImageReaderSpi() {
|
||||
return new ImageReaderSpi(vendorName,
|
||||
version,
|
||||
names,
|
||||
suffixes,
|
||||
MIMETypes,
|
||||
readerClassName,
|
||||
inputTypes,
|
||||
writerSpiNames,
|
||||
false,
|
||||
nativeStreamMetadataFormatName,
|
||||
nativeStreamMetadataFormatClassName,
|
||||
extraStreamMetadataFormatNames,
|
||||
extraStreamMetadataFormatClassNames,
|
||||
false,
|
||||
nativeImageMetadataFormatName,
|
||||
nativeImageMetadataFormatClassName,
|
||||
extraImageMetadataFormatNames,
|
||||
extraImageMetadataFormatClassNames) {
|
||||
|
||||
public String getDescription(Locale locale) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean canDecodeInput(Object source) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public ImageReader createReaderInstance(Object extension) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private ImageWriterSpi constructImageWriterSpi() {
|
||||
return new ImageWriterSpi(vendorName,
|
||||
version,
|
||||
names,
|
||||
suffixes,
|
||||
MIMETypes,
|
||||
writerClassName,
|
||||
outputTypes,
|
||||
readerSpiNames,
|
||||
false,
|
||||
nativeStreamMetadataFormatName,
|
||||
nativeStreamMetadataFormatClassName,
|
||||
extraStreamMetadataFormatNames,
|
||||
extraStreamMetadataFormatClassNames,
|
||||
false,
|
||||
nativeImageMetadataFormatName,
|
||||
nativeImageMetadataFormatClassName,
|
||||
extraImageMetadataFormatNames,
|
||||
extraImageMetadataFormatClassNames) {
|
||||
|
||||
public String getDescription(Locale locale) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean canEncodeImage(ImageTypeSpecifier type) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public ImageWriter createWriterInstance(Object extension) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private void checkImageReaderSpiConstructor(boolean shouldFail) {
|
||||
boolean gotIAE = false;
|
||||
try {
|
||||
constructImageReaderSpi();
|
||||
} catch (Exception e) {
|
||||
if (!(e instanceof IllegalArgumentException)) {
|
||||
error("Got exception " + e);
|
||||
} else {
|
||||
gotIAE = true;
|
||||
}
|
||||
}
|
||||
if (gotIAE != shouldFail) {
|
||||
if (gotIAE) {
|
||||
error("ImageReaderSpi constructor threw an IAE!");
|
||||
} else {
|
||||
error("ImageReaderSpi constructor didn't throw an IAE!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void checkImageWriterSpiConstructor(boolean shouldFail) {
|
||||
boolean gotIAE = false;
|
||||
try {
|
||||
constructImageWriterSpi();
|
||||
} catch (Exception e) {
|
||||
if (!(e instanceof IllegalArgumentException)) {
|
||||
error("Got exception " + e);
|
||||
} else {
|
||||
gotIAE = true;
|
||||
}
|
||||
}
|
||||
if (gotIAE != shouldFail) {
|
||||
if (gotIAE) {
|
||||
error("ImageWriterSpi constructor threw an IAE!");
|
||||
} else {
|
||||
error("ImageWriterSpi constructor didn't throw an IAE!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void testImageReaderSpiConstructor() {
|
||||
resetConstructorArguments();
|
||||
|
||||
checkImageReaderSpiConstructor(true);
|
||||
vendorName = "My Vendor";
|
||||
checkImageReaderSpiConstructor(true);
|
||||
version = "My Version";
|
||||
checkImageReaderSpiConstructor(true);
|
||||
names = new String[0];
|
||||
checkImageReaderSpiConstructor(true);
|
||||
names = new String[1];
|
||||
names[0] = "My Format Name";
|
||||
checkImageReaderSpiConstructor(true);
|
||||
readerClassName = "com.mycompany.Reader";
|
||||
checkImageReaderSpiConstructor(true);
|
||||
inputTypes = new Class[0];
|
||||
checkImageReaderSpiConstructor(true);
|
||||
inputTypes = new Class[1];
|
||||
inputTypes[0] = Object.class;
|
||||
// Now it should work
|
||||
checkImageReaderSpiConstructor(false);
|
||||
|
||||
// Test normalization of zero-length arrays
|
||||
suffixes = new String[0];
|
||||
MIMETypes = new String[0];
|
||||
writerSpiNames = new String[0];
|
||||
extraStreamMetadataFormatNames = new String[0];
|
||||
extraImageMetadataFormatNames = new String[0];
|
||||
|
||||
ImageReaderSpi spi = constructImageReaderSpi();
|
||||
if (spi.getFileSuffixes() != null) {
|
||||
error("Failed to normalize suffixes!");
|
||||
}
|
||||
if (spi.getMIMETypes() != null) {
|
||||
error("Failed to normalize MIMETypes!");
|
||||
}
|
||||
if (spi.getImageWriterSpiNames() != null) {
|
||||
error("Failed to normalize writerSpiNames!");
|
||||
}
|
||||
if (spi.getExtraStreamMetadataFormatNames() != null) {
|
||||
error("Failed to normalize extraStreamMetadataFormatNames!");
|
||||
}
|
||||
if (spi.getExtraImageMetadataFormatNames() != null) {
|
||||
error("Failed to normalize extraImageMetadataFormatNames!");
|
||||
}
|
||||
}
|
||||
|
||||
public void testImageWriterSpiConstructor() {
|
||||
resetConstructorArguments();
|
||||
|
||||
checkImageWriterSpiConstructor(true);
|
||||
vendorName = "My Vendor";
|
||||
checkImageWriterSpiConstructor(true);
|
||||
version = "My Version";
|
||||
checkImageWriterSpiConstructor(true);
|
||||
names = new String[0];
|
||||
checkImageWriterSpiConstructor(true);
|
||||
names = new String[1];
|
||||
names[0] = "My Format Name";
|
||||
checkImageWriterSpiConstructor(true);
|
||||
writerClassName = "com.mycompany.Writer";
|
||||
checkImageWriterSpiConstructor(true);
|
||||
outputTypes = new Class[0];
|
||||
checkImageWriterSpiConstructor(true);
|
||||
outputTypes = new Class[1];
|
||||
outputTypes[0] = Object.class;
|
||||
// Now it should work
|
||||
checkImageWriterSpiConstructor(false);
|
||||
|
||||
// Test normalization of zero-length arrays
|
||||
suffixes = new String[0];
|
||||
MIMETypes = new String[0];
|
||||
readerSpiNames = new String[0];
|
||||
extraStreamMetadataFormatNames = new String[0];
|
||||
extraStreamMetadataFormatClassNames = new String[0];
|
||||
extraImageMetadataFormatNames = new String[0];
|
||||
extraImageMetadataFormatClassNames = new String[0];
|
||||
|
||||
ImageWriterSpi spi = constructImageWriterSpi();
|
||||
if (spi.getFileSuffixes() != null) {
|
||||
error("Failed to normalize suffixes!");
|
||||
}
|
||||
if (spi.getMIMETypes() != null) {
|
||||
error("Failed to normalize MIMETypes!");
|
||||
}
|
||||
if (spi.getImageReaderSpiNames() != null) {
|
||||
error("Failed to normalize readerSpiNames!");
|
||||
}
|
||||
if (spi.getExtraStreamMetadataFormatNames() != null) {
|
||||
error("Failed to normalize extraStreamMetadataFormatNames!");
|
||||
}
|
||||
if (spi.getExtraImageMetadataFormatNames() != null) {
|
||||
error("Failed to normalize extraImageMetadataFormatNames!");
|
||||
}
|
||||
}
|
||||
|
||||
public SpiTest() {
|
||||
testImageReaderSpiConstructor();
|
||||
testImageWriterSpiConstructor();
|
||||
|
||||
ServiceRegistry registry = IIORegistry.getDefaultInstance();
|
||||
Iterator readers = registry.getServiceProviders(ImageReaderSpi.class,
|
||||
false);
|
||||
while (readers.hasNext()) {
|
||||
ImageReaderSpi rspi = (ImageReaderSpi)readers.next();
|
||||
System.out.println("*** Testing " + rspi.getClass().getName());
|
||||
testSpi(rspi);
|
||||
}
|
||||
|
||||
Iterator writers = registry.getServiceProviders(ImageWriterSpi.class,
|
||||
false);
|
||||
while (writers.hasNext()) {
|
||||
ImageWriterSpi wspi = (ImageWriterSpi)writers.next();
|
||||
System.out.println("*** Testing " + wspi.getClass().getName());
|
||||
testSpi(wspi);
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
new SpiTest();
|
||||
}
|
||||
}
|
61
jdk/test/javax/imageio/spi/SpiVersionNumbers.java
Normal file
61
jdk/test/javax/imageio/spi/SpiVersionNumbers.java
Normal file
@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright (c) 2001, 2017, 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 4415450
|
||||
* @summary Checks the version number for the standard stream Spis
|
||||
* @modules java.desktop/com.sun.imageio.spi
|
||||
*/
|
||||
|
||||
import javax.imageio.spi.IIOServiceProvider;
|
||||
|
||||
import com.sun.imageio.spi.FileImageInputStreamSpi;
|
||||
import com.sun.imageio.spi.FileImageOutputStreamSpi;
|
||||
import com.sun.imageio.spi.InputStreamImageInputStreamSpi;
|
||||
import com.sun.imageio.spi.OutputStreamImageOutputStreamSpi;
|
||||
import com.sun.imageio.spi.RAFImageInputStreamSpi;
|
||||
import com.sun.imageio.spi.RAFImageOutputStreamSpi;
|
||||
|
||||
public class SpiVersionNumbers {
|
||||
|
||||
private static void check(IIOServiceProvider spi) {
|
||||
String version = spi.getVersion();
|
||||
if (!version.equals("1.0")) {
|
||||
throw new RuntimeException("Provider " +
|
||||
spi.getClass().getName() +
|
||||
" has version " + version + "!");
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
check(new FileImageInputStreamSpi());
|
||||
check(new InputStreamImageInputStreamSpi());
|
||||
check(new RAFImageInputStreamSpi());
|
||||
|
||||
check(new FileImageOutputStreamSpi());
|
||||
check(new OutputStreamImageOutputStreamSpi());
|
||||
check(new RAFImageOutputStreamSpi());
|
||||
}
|
||||
|
||||
}
|
58
jdk/test/javax/imageio/stream/BitPadding.java
Normal file
58
jdk/test/javax/imageio/stream/BitPadding.java
Normal file
@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright (c) 2001, 2017, 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 4430395
|
||||
* @summary Checks if write(int) properly pads unwritten bits with zeros
|
||||
*/
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import javax.imageio.stream.FileCacheImageOutputStream;
|
||||
|
||||
public class BitPadding {
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
OutputStream ostream = new ByteArrayOutputStream();
|
||||
File f = null;
|
||||
FileCacheImageOutputStream fcios =
|
||||
new FileCacheImageOutputStream(ostream, f);
|
||||
fcios.writeBit(1);
|
||||
fcios.write(96);
|
||||
|
||||
fcios.seek(0);
|
||||
int r1 = fcios.read();
|
||||
if (r1 != 128 ) {
|
||||
throw new RuntimeException("Failed, first byte is " + r1);
|
||||
}
|
||||
|
||||
int r2 = fcios.read();
|
||||
if (r2 != 96) {
|
||||
throw new RuntimeException("Failed, second byte is " + r2);
|
||||
}
|
||||
}
|
||||
}
|
75
jdk/test/javax/imageio/stream/DeleteOnExitTest.java
Normal file
75
jdk/test/javax/imageio/stream/DeleteOnExitTest.java
Normal file
@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2017, 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.
|
||||
*/
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.stream.ImageInputStream;
|
||||
import javax.imageio.stream.ImageOutputStream;
|
||||
|
||||
public class DeleteOnExitTest {
|
||||
public static void main(String[] args) throws IOException {
|
||||
ByteArrayInputStream is =
|
||||
new ByteArrayInputStream(new byte[100]);
|
||||
ByteArrayOutputStream os =
|
||||
new ByteArrayOutputStream();
|
||||
|
||||
String tmp = System.getProperty("java.io.tmpdir", ".");
|
||||
System.out.println("tmp: " + tmp);
|
||||
|
||||
// count number of files before test
|
||||
ImageIO.setUseCache(true);
|
||||
ImageIO.setCacheDirectory(new File(tmp));
|
||||
|
||||
File tmpDir = ImageIO.getCacheDirectory();
|
||||
System.out.println("tmpDir is " + tmpDir);
|
||||
int fnum_before = tmpDir.list().length;
|
||||
System.out.println("Files before test: " + fnum_before);
|
||||
|
||||
ImageInputStream iis =
|
||||
ImageIO.createImageInputStream(is);
|
||||
System.out.println("iis = " + iis);
|
||||
|
||||
ImageInputStream iis2 =
|
||||
ImageIO.createImageInputStream(is);
|
||||
|
||||
ImageOutputStream ios =
|
||||
ImageIO.createImageOutputStream(os);
|
||||
System.out.println("ios = " + ios);
|
||||
|
||||
ImageOutputStream ios2 =
|
||||
ImageIO.createImageOutputStream(os);
|
||||
|
||||
iis2.close();
|
||||
ios2.close();
|
||||
int fnum_after = tmpDir.list().length;
|
||||
System.out.println("Files after test: " + fnum_after);
|
||||
|
||||
if (fnum_before == fnum_after) {
|
||||
throw new RuntimeException("Test failed: cache was not used.");
|
||||
}
|
||||
}
|
||||
}
|
69
jdk/test/javax/imageio/stream/DeleteOnExitTest.sh
Normal file
69
jdk/test/javax/imageio/stream/DeleteOnExitTest.sh
Normal file
@ -0,0 +1,69 @@
|
||||
# Copyright (c) 2005, 2017, 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 6291034
|
||||
# @run shell DeleteOnExitTest.sh
|
||||
# @summary Verify that temporary imageio files files are deleted on VM exit.
|
||||
|
||||
if [ -z "${TESTSRC}" ]; then
|
||||
echo "TESTSRC undefined: defaulting to ."
|
||||
TESTSRC=.
|
||||
fi
|
||||
|
||||
if [ -z "${TESTCLASSES}" ]; then
|
||||
echo "TESTCLASSES undefined: defaulting to ."
|
||||
TESTCLASSES=.
|
||||
fi
|
||||
|
||||
if [ -z "${TESTJAVA}" ]; then
|
||||
echo "TESTJAVA undefined: can't continue."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "TESTJAVA=${TESTJAVA}"
|
||||
echo "TESTSRC=${TESTSRC}"
|
||||
echo "TESTCLASSES=${TESTCLASSES}"
|
||||
cd ${TESTSRC}
|
||||
${COMPILEJAVA}/bin/javac -d ${TESTCLASSES} DeleteOnExitTest.java
|
||||
|
||||
cd ${TESTCLASSES}
|
||||
|
||||
numfiles0=`ls ${TESTCLASSES} | grep "imageio*.tmp" | wc -l`
|
||||
|
||||
${TESTJAVA}/bin/java ${TESTVMOPTS} \
|
||||
-Djava.io.tmpdir=${TESTCLASSES} DeleteOnExitTest
|
||||
|
||||
if [ $? -ne 0 ]
|
||||
then
|
||||
echo "Test fails: exception thrown!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
numfiles1=`ls ${TESTCLASSES} | grep "imageio*.tmp" | wc -l`
|
||||
|
||||
if [ $numfiles0 -ne $numfiles1 ]
|
||||
then
|
||||
echo "Test fails: tmp file exists!"
|
||||
exit 1
|
||||
fi
|
||||
echo "Test passed."
|
||||
exit 0
|
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (c) 2001, 2017, 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 4428802
|
||||
* @summary Checks for IAE from FileCacheImageInputStream constructor with a
|
||||
* null value for 'stream'
|
||||
*/
|
||||
|
||||
import javax.imageio.stream.FileCacheImageInputStream;
|
||||
|
||||
public class FileCacheImageInputStreamNullTest {
|
||||
|
||||
public static void main (String[] args) throws Exception {
|
||||
boolean gotIAE = false;
|
||||
try {
|
||||
FileCacheImageInputStream fciis =
|
||||
new FileCacheImageInputStream(null, null);
|
||||
} catch (IllegalArgumentException e) {
|
||||
gotIAE = true;
|
||||
}
|
||||
|
||||
if (!gotIAE) {
|
||||
throw new RuntimeException
|
||||
("Failed to get IllegalArgumentException!");
|
||||
}
|
||||
}
|
||||
}
|
64
jdk/test/javax/imageio/stream/FlushBefore.java
Normal file
64
jdk/test/javax/imageio/stream/FlushBefore.java
Normal file
@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright (c) 2001, 2017, 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 4431503
|
||||
* @summary Checks if flushBefore(pos) throws an IndexOutOfBoundsException if
|
||||
* pos lies in the flushed portion of the stream
|
||||
*/
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import javax.imageio.stream.FileCacheImageOutputStream;
|
||||
import javax.imageio.stream.ImageOutputStream;
|
||||
import javax.imageio.stream.MemoryCacheImageOutputStream;
|
||||
|
||||
public class FlushBefore {
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
OutputStream ostream = new ByteArrayOutputStream();
|
||||
|
||||
FileCacheImageOutputStream fcios =
|
||||
new FileCacheImageOutputStream(ostream, null);
|
||||
test(fcios);
|
||||
|
||||
MemoryCacheImageOutputStream mcios =
|
||||
new MemoryCacheImageOutputStream(ostream);
|
||||
test(mcios);
|
||||
}
|
||||
|
||||
private static void test(ImageOutputStream ios) throws IOException {
|
||||
try {
|
||||
ios.write(new byte[10], 0, 10);
|
||||
ios.flushBefore(5);
|
||||
ios.flushBefore(4);
|
||||
|
||||
throw new RuntimeException
|
||||
("Failed to get IndexOutOfBoundsException!");
|
||||
} catch (IndexOutOfBoundsException e) {
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,115 @@
|
||||
/*
|
||||
* Copyright (c) 2001, 2017, 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 4417672 4422328
|
||||
* @summary Checks the functionality of MemoryCacheImageOutputStream
|
||||
* particularly with regard to seeking and flushing
|
||||
*/
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.imageio.stream.ImageOutputStream;
|
||||
import javax.imageio.stream.MemoryCacheImageOutputStream;
|
||||
|
||||
public class MemoryCacheImageOutputStreamTest {
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
try {
|
||||
MemoryCacheImageOutputStream stream =
|
||||
new MemoryCacheImageOutputStream(new ByteArrayOutputStream());
|
||||
stream.write(0); // or write anything, for that matter
|
||||
stream.flush();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Error flushing stream: " + e);
|
||||
}
|
||||
|
||||
ByteArrayOutputStream os = new ByteArrayOutputStream();
|
||||
ImageOutputStream ios = new MemoryCacheImageOutputStream(os);
|
||||
|
||||
byte[] b = new byte[30*256];
|
||||
byte byteVal = (byte)0;
|
||||
for (int i = 0; i < b.length; i++) {
|
||||
b[i] = byteVal++;
|
||||
}
|
||||
|
||||
// Write 261,120 bytes
|
||||
for (int i = 0; i < 34; i++) {
|
||||
ios.write(b);
|
||||
}
|
||||
// Scatter 256 values at positions 1000, 2000, ...
|
||||
// Using both write(int) and write(byte[])
|
||||
byte[] buf = new byte[1];
|
||||
for (int i = 0; i < 256; i += 2) {
|
||||
ios.seek(1000*i);
|
||||
ios.write(i);
|
||||
|
||||
ios.seek(1000*(i + 1));
|
||||
buf[0] = (byte)(i + 1);
|
||||
ios.write(buf);
|
||||
}
|
||||
|
||||
// Re-read scattered values
|
||||
for (int i = 0; i < 256; i++) {
|
||||
ios.seek(1000*i);
|
||||
int val = ios.read();
|
||||
if (val != i) {
|
||||
System.out.println("Got bad value (1) at pos = " + (1000*i));
|
||||
}
|
||||
}
|
||||
|
||||
// Discard two buffers and re-read scattered values
|
||||
ios.flushBefore(2*8192);
|
||||
|
||||
for (int i = 0; i < 256; i++) {
|
||||
long pos = 1000*i;
|
||||
if (pos >= 2*8192) {
|
||||
ios.seek(pos);
|
||||
int val = ios.read();
|
||||
if (val != i) {
|
||||
System.out.println("Got bad value (2) at pos = " + (1000*i));
|
||||
}
|
||||
}
|
||||
}
|
||||
ios.close();
|
||||
|
||||
byte[] data = os.toByteArray();
|
||||
for (int i = 0; i < data.length; i++) {
|
||||
byte val = data[i];
|
||||
if ((i < 256000) && (i % 1000) == 0) {
|
||||
if (val != (byte)(i/1000)) {
|
||||
System.out.println("Got bad value (3) at pos = " + i);
|
||||
}
|
||||
} else {
|
||||
byte gval = (byte)((i % (30*256)) % 256);
|
||||
if (val != gval) {
|
||||
System.out.println("Got bad value (4) at pos = " + i +
|
||||
"(got " + (val & 0xff) +
|
||||
" wanted " + (gval & 0xff) +")");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
56
jdk/test/javax/imageio/stream/ReadBytesIIOByteBuffer.java
Normal file
56
jdk/test/javax/imageio/stream/ReadBytesIIOByteBuffer.java
Normal file
@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright (c) 2004, 2017, 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 4446906
|
||||
* @summary Checks if ImageInputStreamImpl.readBytes(IIOByteBuffer) tests for
|
||||
* len < 0
|
||||
*/
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.InputStream;
|
||||
|
||||
import javax.imageio.stream.IIOByteBuffer;
|
||||
import javax.imageio.stream.ImageInputStream;
|
||||
import javax.imageio.stream.MemoryCacheImageInputStream;
|
||||
|
||||
public class ReadBytesIIOByteBuffer {
|
||||
|
||||
public static void main(String[] argv) {
|
||||
byte[] bar = {1, 1, 1};
|
||||
InputStream is = new ByteArrayInputStream(bar);
|
||||
|
||||
ImageInputStream iis = new MemoryCacheImageInputStream(is);
|
||||
byte[] b = new byte[10];
|
||||
IIOByteBuffer iiob = new IIOByteBuffer(b, 0, b.length);
|
||||
try {
|
||||
iis.readBytes(iiob, -1);
|
||||
} catch (IndexOutOfBoundsException e) {
|
||||
return;
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Unexpected exception: " + e);
|
||||
}
|
||||
throw new RuntimeException("No exception thrown for len < 0!");
|
||||
}
|
||||
}
|
146
jdk/test/javax/imageio/stream/ReadFullyTest.java
Normal file
146
jdk/test/javax/imageio/stream/ReadFullyTest.java
Normal file
@ -0,0 +1,146 @@
|
||||
/*
|
||||
* Copyright (c) 2001, 2017, 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 4422263
|
||||
* @summary Checks that ImageInputStream.readFully(type[], int int) handles sign
|
||||
* extension and byte ordering correctly
|
||||
*/
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.nio.ByteOrder;
|
||||
|
||||
import javax.imageio.stream.ImageInputStream;
|
||||
import javax.imageio.stream.MemoryCacheImageInputStream;
|
||||
|
||||
public class ReadFullyTest {
|
||||
|
||||
static final ByteOrder bigEndian = ByteOrder.BIG_ENDIAN;
|
||||
static final ByteOrder littleEndian = ByteOrder.LITTLE_ENDIAN;
|
||||
|
||||
private static void expect(long e, long g) {
|
||||
if (e != g) {
|
||||
throw new RuntimeException("Expected " + e + ", got " + g);
|
||||
}
|
||||
}
|
||||
|
||||
public static void main (String args[]) {
|
||||
try {
|
||||
byte[] b = {
|
||||
(byte)0x11, (byte)0x22, // low low
|
||||
(byte)0x44, (byte)0x99, // low high
|
||||
(byte)0xAA, (byte)0x33, // high low
|
||||
(byte)0xBB, (byte)0xCC // high high
|
||||
};
|
||||
InputStream in = new ByteArrayInputStream(b);
|
||||
ImageInputStream iin = new MemoryCacheImageInputStream(in);
|
||||
|
||||
short[] s = new short[b.length/2];
|
||||
char[] c = new char[b.length/2];
|
||||
int[] i = new int[b.length/4];
|
||||
long[] l = new long[b.length/8];
|
||||
float[] f = new float[b.length/4];
|
||||
double[] d = new double[b.length/8];
|
||||
|
||||
iin.seek(0L);
|
||||
iin.setByteOrder(bigEndian);
|
||||
iin.readFully(s, 0, s.length);
|
||||
expect(s[0] & 0xffff, 0x1122);
|
||||
expect(s[1] & 0xffff, 0x4499);
|
||||
expect(s[2] & 0xffff, 0xAA33);
|
||||
expect(s[3] & 0xffff, 0xBBCC);
|
||||
|
||||
iin.seek(0L);
|
||||
iin.setByteOrder(littleEndian);
|
||||
iin.readFully(s, 0, s.length);
|
||||
expect(s[0] & 0xffff, 0x2211);
|
||||
expect(s[1] & 0xffff, 0x9944);
|
||||
expect(s[2] & 0xffff, 0x33AA);
|
||||
expect(s[3] & 0xffff, 0xCCBB);
|
||||
|
||||
iin.seek(0L);
|
||||
iin.setByteOrder(bigEndian);
|
||||
iin.readFully(c, 0, c.length);
|
||||
expect(c[0], 0x1122);
|
||||
expect(c[1], 0x4499);
|
||||
expect(c[2], 0xAA33);
|
||||
expect(c[3], 0xBBCC);
|
||||
|
||||
iin.seek(0L);
|
||||
iin.setByteOrder(littleEndian);
|
||||
iin.readFully(c, 0, c.length);
|
||||
expect(c[0], 0x2211);
|
||||
expect(c[1], 0x9944);
|
||||
expect(c[2], 0x33AA);
|
||||
expect(c[3], 0xCCBB);
|
||||
|
||||
iin.seek(0L);
|
||||
iin.setByteOrder(bigEndian);
|
||||
iin.readFully(i, 0, i.length);
|
||||
expect(i[0] & 0xffffffff, 0x11224499);
|
||||
expect(i[1] & 0xffffffff, 0xAA33BBCC);
|
||||
|
||||
iin.seek(0L);
|
||||
iin.setByteOrder(littleEndian);
|
||||
iin.readFully(i, 0, i.length);
|
||||
expect(i[0] & 0xffffffff, 0x99442211);
|
||||
expect(i[1] & 0xffffffff, 0xCCBB33AA);
|
||||
|
||||
iin.seek(0L);
|
||||
iin.setByteOrder(bigEndian);
|
||||
iin.readFully(f, 0, f.length);
|
||||
expect(Float.floatToIntBits(f[0]) & 0xffffffff, 0x11224499);
|
||||
expect(Float.floatToIntBits(f[1]) & 0xffffffff, 0xAA33BBCC);
|
||||
|
||||
iin.seek(0L);
|
||||
iin.setByteOrder(littleEndian);
|
||||
iin.readFully(f, 0, f.length);
|
||||
expect(Float.floatToIntBits(f[0]) & 0xffffffff, 0x99442211);
|
||||
expect(Float.floatToIntBits(f[1]) & 0xffffffff, 0xCCBB33AA);
|
||||
|
||||
iin.seek(0L);
|
||||
iin.setByteOrder(bigEndian);
|
||||
iin.readFully(l, 0, l.length);
|
||||
expect(l[0], 0x11224499AA33BBCCL);
|
||||
|
||||
iin.seek(0L);
|
||||
iin.setByteOrder(littleEndian);
|
||||
iin.readFully(l, 0, l.length);
|
||||
expect(l[0], 0xCCBB33AA99442211L);
|
||||
|
||||
iin.seek(0L);
|
||||
iin.setByteOrder(bigEndian);
|
||||
iin.readFully(d, 0, d.length);
|
||||
expect(Double.doubleToLongBits(d[0]), 0x11224499AA33BBCCL);
|
||||
|
||||
iin.seek(0L);
|
||||
iin.setByteOrder(littleEndian);
|
||||
iin.readFully(d, 0, d.length);
|
||||
expect(Double.doubleToLongBits(d[0]), 0xCCBB33AA99442211L);
|
||||
} catch (Exception ex) {
|
||||
throw new RuntimeException("Got exception " + ex);
|
||||
}
|
||||
}
|
||||
}
|
62
jdk/test/javax/imageio/stream/ReadUnsignedIntTest.java
Normal file
62
jdk/test/javax/imageio/stream/ReadUnsignedIntTest.java
Normal file
@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 2017, 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 4949609
|
||||
* @summary Tests that the readUnsignedInt returns the positive value
|
||||
*/
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.stream.ImageInputStream;
|
||||
|
||||
public class ReadUnsignedIntTest {
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
DataOutputStream dos = new DataOutputStream(baos);
|
||||
|
||||
dos.writeInt(1);
|
||||
dos.writeInt(0x7fffffff);
|
||||
dos.writeInt(0x8fffffff);
|
||||
dos.writeInt(0xffffffff);
|
||||
|
||||
dos.close();
|
||||
|
||||
ByteArrayInputStream bais =
|
||||
new ByteArrayInputStream(baos.toByteArray());
|
||||
ImageInputStream iis = ImageIO.createImageInputStream(bais);
|
||||
for (int i=0; i<4; i++) {
|
||||
long res = iis.readUnsignedInt();
|
||||
if (res <= 0) {
|
||||
throw new RuntimeException("Negative number was read: "+
|
||||
Long.toString(res, 16));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
108
jdk/test/javax/imageio/stream/StreamFlush.java
Normal file
108
jdk/test/javax/imageio/stream/StreamFlush.java
Normal file
@ -0,0 +1,108 @@
|
||||
/*
|
||||
* Copyright (c) 2001, 2017, 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 4414990 4415041
|
||||
* @summary Checks that the output is flushed properly when using various
|
||||
* ImageOutputStreams and writers
|
||||
*/
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.stream.ImageOutputStream;
|
||||
|
||||
public class StreamFlush {
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
ImageIO.setUseCache(true);
|
||||
|
||||
// Create a FileImageOutputStream from a FileOutputStream
|
||||
File temp1 = File.createTempFile("imageio", ".tmp");
|
||||
temp1.deleteOnExit();
|
||||
ImageOutputStream fios = ImageIO.createImageOutputStream(temp1);
|
||||
|
||||
// Create a FileCacheImageOutputStream from a BufferedOutputStream
|
||||
File temp2 = File.createTempFile("imageio", ".tmp");
|
||||
temp2.deleteOnExit();
|
||||
FileOutputStream fos2 = new FileOutputStream(temp2);
|
||||
BufferedOutputStream bos = new BufferedOutputStream(fos2);
|
||||
ImageOutputStream fcios1 = ImageIO.createImageOutputStream(bos);
|
||||
|
||||
// Create a FileCacheImageOutputStream from a ByteArrayOutputStream
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
ImageOutputStream fcios2 = ImageIO.createImageOutputStream(baos);
|
||||
|
||||
BufferedImage bi =
|
||||
new BufferedImage(10, 10, BufferedImage.TYPE_3BYTE_BGR);
|
||||
|
||||
ImageIO.write(bi, "jpg", fios); // No bug, check it anyway
|
||||
ImageIO.write(bi, "png", fcios1); // Bug 4414990
|
||||
ImageIO.write(bi, "jpg", fcios2); // Bug 4415041
|
||||
|
||||
// It should not be necessary to flush any of the streams
|
||||
// If flushing does make a difference, it indicates a bug
|
||||
// in the writer or the stream implementation
|
||||
|
||||
// Get length of temp1 before and after flushing
|
||||
long file1NoFlushLength = temp1.length();
|
||||
fios.flush();
|
||||
long file1FlushLength = temp1.length();
|
||||
|
||||
// Get length of temp2 before and after flushing
|
||||
long file2NoFlushLength = temp2.length();
|
||||
fcios1.flush();
|
||||
bos.flush();
|
||||
long file2FlushLength = temp2.length();
|
||||
|
||||
byte[] b0 = baos.toByteArray();
|
||||
int cacheNoFlushLength = b0.length;
|
||||
fcios2.flush();
|
||||
byte[] b1 = baos.toByteArray();
|
||||
int cacheFlushLength = b1.length;
|
||||
|
||||
if (file1NoFlushLength != file1FlushLength) {
|
||||
// throw new RuntimeException
|
||||
System.out.println
|
||||
("FileImageOutputStream not flushed!");
|
||||
}
|
||||
|
||||
if (file2NoFlushLength != file2FlushLength) {
|
||||
// throw new RuntimeException
|
||||
System.out.println
|
||||
("FileCacheImageOutputStream/BufferedOutputStream not flushed!");
|
||||
}
|
||||
|
||||
if (cacheNoFlushLength != cacheFlushLength) {
|
||||
// throw new RuntimeException
|
||||
System.out.println
|
||||
("FileCacheImageOutputStream/ByteArrayOutputStream not flushed!");
|
||||
}
|
||||
}
|
||||
}
|
110
jdk/test/javax/imageio/stream/WriteBitsTest.java
Normal file
110
jdk/test/javax/imageio/stream/WriteBitsTest.java
Normal file
@ -0,0 +1,110 @@
|
||||
/*
|
||||
* Copyright (c) 2002, 2017, 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 4507868
|
||||
* @summary Checks that ImageOutputStreamImpl.writeBits() advances the stream
|
||||
* position and bit offset correctly. Also verifies that the
|
||||
* MemoryCacheImageOutputStream.read() variants reset the bitOffset
|
||||
* before the read actually occurs.
|
||||
*/
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.imageio.stream.ImageOutputStream;
|
||||
import javax.imageio.stream.MemoryCacheImageOutputStream;
|
||||
|
||||
public class WriteBitsTest {
|
||||
|
||||
private static void verify(ImageOutputStream ios,
|
||||
long expstreampos, int expbitoffset)
|
||||
throws IOException, RuntimeException
|
||||
{
|
||||
long actstreampos = ios.getStreamPosition();
|
||||
int actbitoffset = ios.getBitOffset();
|
||||
|
||||
if ((actstreampos != expstreampos) ||
|
||||
(actbitoffset != expbitoffset))
|
||||
{
|
||||
System.err.println("Expected stream position: " + expstreampos +
|
||||
" Actual: " + actstreampos);
|
||||
System.err.println("Expected bit offset: " + expbitoffset +
|
||||
" Actual: " + actbitoffset);
|
||||
throw new RuntimeException("Test failed.");
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String argv[]) throws RuntimeException {
|
||||
ByteArrayOutputStream ostream = new ByteArrayOutputStream();
|
||||
MemoryCacheImageOutputStream mcios = new
|
||||
MemoryCacheImageOutputStream(ostream);
|
||||
|
||||
try {
|
||||
// verify correct writeBits() functionality
|
||||
long streampos = 0;
|
||||
int bitoffset = 0;
|
||||
|
||||
mcios.setBitOffset(bitoffset);
|
||||
verify(mcios, streampos, bitoffset);
|
||||
|
||||
bitoffset = 3;
|
||||
mcios.setBitOffset(bitoffset);
|
||||
verify(mcios, streampos, bitoffset);
|
||||
|
||||
for (int incr = 3; incr <= 15; incr += 12) {
|
||||
for (int i = 0; i < 64; i += incr) {
|
||||
mcios.writeBits(10, incr);
|
||||
|
||||
bitoffset += incr;
|
||||
|
||||
if (bitoffset > 7) {
|
||||
int stroffset = bitoffset / 8;
|
||||
bitoffset = bitoffset % 8;
|
||||
streampos += stroffset;
|
||||
}
|
||||
|
||||
verify(mcios, streampos, bitoffset);
|
||||
}
|
||||
}
|
||||
|
||||
// verify correct read(byte[], int, int) functionality
|
||||
byte[] bytearr = new byte[2];
|
||||
mcios.seek(2);
|
||||
mcios.setBitOffset(3);
|
||||
int numread = mcios.read(bytearr, 0, 2);
|
||||
if (numread != 2) {
|
||||
throw new RuntimeException("Error in mcios.read([BII)I");
|
||||
}
|
||||
verify(mcios, 4, 0);
|
||||
|
||||
// verify correct read() functionality
|
||||
mcios.setBitOffset(3);
|
||||
mcios.read();
|
||||
verify(mcios, 5, 0);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Unexpected IOException: " + e);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user