Search in sources :

Example 1 with IIORegistry

use of javax.imageio.spi.IIORegistry in project jdk8u_jdk by JetBrains.

the class WriteAfterAbort method main.

public static void main(final String[] args) throws IOException {
    final IIORegistry registry = IIORegistry.getDefaultInstance();
    final Iterator<ImageWriterSpi> iter = registry.getServiceProviders(ImageWriterSpi.class, provider -> true, true);
    // Validates all supported ImageWriters
    while (iter.hasNext()) {
        final WriteAfterAbort writeAfterAbort = new WriteAfterAbort();
        final ImageWriter writer = iter.next().createWriterInstance();
        System.out.println("ImageWriter = " + writer);
        writeAfterAbort.test(writer);
    }
    System.out.println("Test passed");
}
Also used : IIORegistry(javax.imageio.spi.IIORegistry) ImageWriter(javax.imageio.ImageWriter) ImageWriterSpi(javax.imageio.spi.ImageWriterSpi)

Example 2 with IIORegistry

use of javax.imageio.spi.IIORegistry in project jdk8u_jdk by JetBrains.

the class MetadataFormatPrinter method main.

public static void main(String[] args) {
    IIOMetadataFormat format = null;
    if (args.length == 0 || args[0].equals("javax_imageio_1.0")) {
        format = IIOMetadataFormatImpl.getStandardFormatInstance();
    } else {
        IIORegistry registry = IIORegistry.getDefaultInstance();
        Iterator iter = registry.getServiceProviders(ImageReaderSpi.class, false);
        while (iter.hasNext()) {
            ImageReaderSpi spi = (ImageReaderSpi) iter.next();
            if (args[0].equals(spi.getNativeStreamMetadataFormatName())) {
                System.out.print(spi.getDescription(null));
                System.out.println(": native stream format");
                format = spi.getStreamMetadataFormat(args[0]);
                break;
            }
            String[] extraStreamFormatNames = spi.getExtraStreamMetadataFormatNames();
            if (extraStreamFormatNames != null && Arrays.asList(extraStreamFormatNames).contains(args[0])) {
                System.out.print(spi.getDescription(null));
                System.out.println(": extra stream format");
                format = spi.getStreamMetadataFormat(args[0]);
                break;
            }
            if (args[0].equals(spi.getNativeImageMetadataFormatName())) {
                System.out.print(spi.getDescription(null));
                System.out.println(": native image format");
                format = spi.getImageMetadataFormat(args[0]);
                break;
            }
            String[] extraImageFormatNames = spi.getExtraImageMetadataFormatNames();
            if (extraImageFormatNames != null && Arrays.asList(extraImageFormatNames).contains(args[0])) {
                System.out.print(spi.getDescription(null));
                System.out.println(": extra image format");
                format = spi.getImageMetadataFormat(args[0]);
                break;
            }
        }
    }
    if (format == null) {
        System.err.println("Unknown format: " + args[0]);
        System.exit(0);
    }
    MetadataFormatPrinter printer = new MetadataFormatPrinter(System.out);
    printer.print(format);
}
Also used : IIOMetadataFormat(javax.imageio.metadata.IIOMetadataFormat) IIORegistry(javax.imageio.spi.IIORegistry) ImageReaderSpi(javax.imageio.spi.ImageReaderSpi) Iterator(java.util.Iterator)

Example 3 with IIORegistry

use of javax.imageio.spi.IIORegistry in project jdk8u_jdk by JetBrains.

the class RegisteredFormatsTest method main.

public static void main(String[] args) {
    fmts = new Hashtable();
    fmts.put("javax_imageio_jpeg_stream_1.0", Boolean.FALSE);
    fmts.put("javax_imageio_jpeg_image_1.0", Boolean.FALSE);
    fmts.put("javax_imageio_png_1.0", Boolean.FALSE);
    fmts.put("javax_imageio_bmp_1.0", Boolean.FALSE);
    fmts.put("javax_imageio_wbmp_1.0", Boolean.FALSE);
    fmts.put("javax_imageio_gif_stream_1.0", Boolean.FALSE);
    fmts.put("javax_imageio_gif_image_1.0", Boolean.FALSE);
    IIORegistry registry = IIORegistry.getDefaultInstance();
    Iterator iter = registry.getServiceProviders(ImageReaderSpi.class, false);
    while (iter.hasNext()) {
        ImageReaderSpi spi = (ImageReaderSpi) iter.next();
        String fmt_name;
        fmt_name = spi.getNativeStreamMetadataFormatName();
        testStreamMetadataFormat(spi, fmt_name);
        fmt_name = spi.getNativeImageMetadataFormatName();
        testImageMetadataFormat(spi, fmt_name);
        String[] fmt_names;
        fmt_names = spi.getExtraStreamMetadataFormatNames();
        for (int i = 0; fmt_names != null && i < fmt_names.length; i++) {
            testStreamMetadataFormat(spi, fmt_names[i]);
        }
        fmt_names = spi.getExtraImageMetadataFormatNames();
        for (int i = 0; fmt_names != null && i < fmt_names.length; i++) {
            testImageMetadataFormat(spi, fmt_names[i]);
        }
    }
    Enumeration keys = fmts.keys();
    while (keys.hasMoreElements()) {
        String key = (String) keys.nextElement();
        boolean val = ((Boolean) fmts.get(key)).booleanValue();
        if (!val) {
            throw new RuntimeException("Test failed: format " + key + "is not registered.");
        }
    }
}
Also used : IIORegistry(javax.imageio.spi.IIORegistry) ImageReaderSpi(javax.imageio.spi.ImageReaderSpi) Enumeration(java.util.Enumeration) Hashtable(java.util.Hashtable) Iterator(java.util.Iterator)

Example 4 with IIORegistry

use of javax.imageio.spi.IIORegistry in project jdk8u_jdk by JetBrains.

the class OutputImageTests method initIIOWriteFormats.

private static void initIIOWriteFormats() {
    List spis = new ArrayList();
    List shortNames = new ArrayList();
    ImageIO.scanForPlugins();
    IIORegistry registry = IIORegistry.getDefaultInstance();
    java.util.Iterator writerspis = registry.getServiceProviders(ImageWriterSpi.class, false);
    while (writerspis.hasNext()) {
        // REMIND: there could be more than one non-core plugin for
        // a particular format, as is the case for JPEG2000 in the JAI
        // IIO Tools package, so we should support that somehow
        ImageWriterSpi spi = (ImageWriterSpi) writerspis.next();
        String klass = spi.getClass().getName();
        String format = spi.getFormatNames()[0].toLowerCase();
        String suffix = spi.getFileSuffixes()[0].toLowerCase();
        if (suffix == null || suffix.equals("")) {
            suffix = format;
        }
        String shortName;
        if (klass.startsWith("com.sun.imageio.plugins")) {
            shortName = "core-" + suffix;
        } else {
            shortName = "ext-" + suffix;
        }
        spis.add(spi);
        shortNames.add(shortName);
    }
    imageioWriterSpis = new ImageWriterSpi[spis.size()];
    imageioWriterSpis = (ImageWriterSpi[]) spis.toArray(imageioWriterSpis);
    imageioWriteFormatShortNames = new String[shortNames.size()];
    imageioWriteFormatShortNames = (String[]) shortNames.toArray(imageioWriteFormatShortNames);
}
Also used : IIORegistry(javax.imageio.spi.IIORegistry) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ImageWriterSpi(javax.imageio.spi.ImageWriterSpi)

Example 5 with IIORegistry

use of javax.imageio.spi.IIORegistry in project jdk8u_jdk by JetBrains.

the class InputImageTests method initIIOReadFormats.

private static void initIIOReadFormats() {
    List spis = new ArrayList();
    List shortNames = new ArrayList();
    ImageIO.scanForPlugins();
    IIORegistry registry = IIORegistry.getDefaultInstance();
    java.util.Iterator readerspis = registry.getServiceProviders(ImageReaderSpi.class, false);
    while (readerspis.hasNext()) {
        // REMIND: there could be more than one non-core plugin for
        // a particular format, as is the case for JPEG2000 in the JAI
        // IIO Tools package, so we should support that somehow
        ImageReaderSpi spi = (ImageReaderSpi) readerspis.next();
        String klass = spi.getClass().getName();
        String format = spi.getFormatNames()[0].toLowerCase();
        String suffix = spi.getFileSuffixes()[0].toLowerCase();
        if (suffix == null || suffix.equals("")) {
            suffix = format;
        }
        String shortName;
        if (klass.startsWith("com.sun.imageio.plugins")) {
            shortName = "core-" + suffix;
        } else {
            shortName = "ext-" + suffix;
        }
        spis.add(spi);
        shortNames.add(shortName);
    }
    imageioReaderSpis = new ImageReaderSpi[spis.size()];
    imageioReaderSpis = (ImageReaderSpi[]) spis.toArray(imageioReaderSpis);
    imageioReadFormatShortNames = new String[shortNames.size()];
    imageioReadFormatShortNames = (String[]) shortNames.toArray(imageioReadFormatShortNames);
}
Also used : IIORegistry(javax.imageio.spi.IIORegistry) ImageReaderSpi(javax.imageio.spi.ImageReaderSpi) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

IIORegistry (javax.imageio.spi.IIORegistry)8 ImageReaderSpi (javax.imageio.spi.ImageReaderSpi)5 Iterator (java.util.Iterator)4 ImageWriterSpi (javax.imageio.spi.ImageWriterSpi)4 ImageWriter (javax.imageio.ImageWriter)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 ImageReader (javax.imageio.ImageReader)2 BufferedImage (java.awt.image.BufferedImage)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 Enumeration (java.util.Enumeration)1 Hashtable (java.util.Hashtable)1 IIOMetadataFormat (javax.imageio.metadata.IIOMetadataFormat)1 ImageInputStream (javax.imageio.stream.ImageInputStream)1