javax.imageio.spi.IIORegistry Java Examples
The following examples show how to use
javax.imageio.spi.IIORegistry.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TIFFJPEGCompressor.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
/** * Retrieves a JPEG reader which supports native JPEG stream metadata. */ private static ImageReader getJPEGTablesReader() { ImageReader jpegReader = null; try { IIORegistry registry = IIORegistry.getDefaultInstance(); Iterator<?> readerSPIs = registry.getServiceProviders(ImageReaderSpi.class, new JPEGSPIFilter(), true); if(readerSPIs.hasNext()) { ImageReaderSpi jpegReaderSPI = (ImageReaderSpi)readerSPIs.next(); jpegReader = jpegReaderSPI.createReaderInstance(); } } catch(Exception e) { // Ignore it ... } return jpegReader; }
Example #2
Source File: ImageValue.java From MyBox with Apache License 2.0 | 6 votes |
public static void registrySupportedImageFormats() { IIORegistry registry = IIORegistry.getDefaultInstance(); // registry.registerServiceProvider(new TIFFImageWriterSpi()); // registry.registerServiceProvider(new TIFFImageReaderSpi()); // registry.registerServiceProvider(new BMPImageWriterSpi()); // registry.registerServiceProvider(new BMPImageReaderSpi()); // registry.registerServiceProvider(new GIFImageWriterSpi()); // registry.registerServiceProvider(new WBMPImageWriterSpi()); // registry.registerServiceProvider(new WBMPImageReaderSpi()); registry.registerServiceProvider(new RawImageWriterSpi()); registry.registerServiceProvider(new RawImageReaderSpi()); registry.registerServiceProvider(new PCXImageWriterSpi()); registry.registerServiceProvider(new PCXImageReaderSpi()); registry.registerServiceProvider(new PNMImageWriterSpi()); registry.registerServiceProvider(new PNMImageReaderSpi()); // registry.registerServiceProvider(new J2KImageWriterSpi()); // registry.registerServiceProvider(new J2KImageReaderSpi()); // String readFormats[] = ImageIO.getReaderFormatNames(); // String writeFormats[] = ImageIO.getWriterFormatNames(); // logger.info("Readers:" + Arrays.asList(readFormats)); // logger.info("Writers:" + Arrays.asList(writeFormats)); //Readers:[JPG, JPEG 2000, tiff, bmp, PCX, gif, WBMP, PNG, RAW, JPEG, PNM, tif, TIFF, wbmp, jpeg, jpg, JPEG2000, BMP, pcx, GIF, png, raw, pnm, TIF, jpeg2000, jpeg 2000] //Writers:[JPEG 2000, JPG, tiff, bmp, PCX, gif, WBMP, PNG, RAW, JPEG, PNM, tif, TIFF, wbmp, jpeg, jpg, JPEG2000, BMP, pcx, GIF, png, raw, pnm, TIF, jpeg2000, jpeg 2000] }
Example #3
Source File: WriteAfterAbort.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
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 int numFailures = 0; while (iter.hasNext()) { final WriteAfterAbort writeAfterAbort = new WriteAfterAbort(); final ImageWriter writer = iter.next().createWriterInstance(); System.out.println("ImageWriter = " + writer); try { writeAfterAbort.test(writer); } catch (Exception e) { System.err.println("Test failed for \"" + writer.getOriginatingProvider().getFormatNames()[0] + "\" format."); numFailures++; } } if (numFailures == 0) { System.out.println("Test passed."); } else { throw new RuntimeException("Test failed."); } }
Example #4
Source File: GetReaderWriterInfoNullTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
public static void main (String[] args) throws IIOException { // Verify getReaderMIMETypes() behavior by keeping MIMEType as null. TestImageReaderSpi mimeNullReadSpi = new TestImageReaderSpi(FORMATNAMES, SUFFIXES, null); IIORegistry.getDefaultInstance(). registerServiceProvider(mimeNullReadSpi); ImageIO.getReaderMIMETypes(); IIORegistry.getDefaultInstance(). deregisterServiceProvider(mimeNullReadSpi); /* * Verify getReaderFileSuffixes() behavior by keeping * file suffix as null. */ TestImageReaderSpi suffixNullReadSpi = new TestImageReaderSpi(FORMATNAMES, null, MIMETYPES); IIORegistry.getDefaultInstance(). registerServiceProvider(suffixNullReadSpi); ImageIO.getReaderFileSuffixes(); IIORegistry.getDefaultInstance(). deregisterServiceProvider(suffixNullReadSpi); }
Example #5
Source File: MarkTryFinallyReproducer.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws IOException { MarkTryFinallyReproducerSpi spi = new MarkTryFinallyReproducerSpi(); IIORegistry.getDefaultInstance().registerServiceProvider(spi); ImageInputStream iis1 = new NotClosingImageInputStream(ImageIO.createImageInputStream(new ByteArrayInputStream(bmp))); iis1.readByte(); iis1.mark(); long p1 = iis1.getStreamPosition(); iis1.readByte(); iis1.mark(); long p2 = iis1.getStreamPosition(); BufferedImage bi1 = ImageIO.read(iis1); iis1.reset(); long pn2 = iis1.getStreamPosition(); iis1.reset(); long pn1 = iis1.getStreamPosition(); if (p1 != pn1 || p2!= pn2) { throw new RuntimeException("Exception from call to canDecodeInput in ImageIO. " + "Corrupted stack in ImageInputStream"); } }
Example #6
Source File: DeregisterOrderedSpiTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
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()); } }
Example #7
Source File: SpiTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
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); } }
Example #8
Source File: SnapApp.java From snap-desktop with GNU General Public License v3.0 | 6 votes |
private static void initImageIO() { // todo - actually this should be done in the activator of ceres-jai which does not exist yet Lookup.Result<ModuleInfo> moduleInfos = Lookup.getDefault().lookupResult(ModuleInfo.class); String ceresJaiCodeName = "org.esa.snap.ceres.jai"; Optional<? extends ModuleInfo> info = moduleInfos.allInstances().stream().filter( moduleInfo -> ceresJaiCodeName.equals(moduleInfo.getCodeName())).findFirst(); if (info.isPresent()) { ClassLoader classLoader = info.get().getClassLoader(); IIORegistry iioRegistry = IIORegistry.getDefaultInstance(); iioRegistry.registerServiceProviders(IIORegistry.lookupProviders(ImageReaderSpi.class, classLoader)); iioRegistry.registerServiceProviders(IIORegistry.lookupProviders(ImageWriterSpi.class, classLoader)); } else { LOG.warning(String.format("Module '%s' not found. Not able to load image-IO services.", ceresJaiCodeName)); } }
Example #9
Source File: OrderingTest.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
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"); } }
Example #10
Source File: SpiTest.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
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); } }
Example #11
Source File: DeregisterOrderedSpiTest.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
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()); } }
Example #12
Source File: TIFFJPEGCompressor.java From Bytecoder with Apache License 2.0 | 6 votes |
/** * Retrieves a JPEG reader which supports native JPEG stream metadata. */ private static ImageReader getJPEGTablesReader() { ImageReader jpegReader = null; try { IIORegistry registry = IIORegistry.getDefaultInstance(); Iterator<?> readerSPIs = registry.getServiceProviders(ImageReaderSpi.class, new JPEGSPIFilter(), true); if(readerSPIs.hasNext()) { ImageReaderSpi jpegReaderSPI = (ImageReaderSpi)readerSPIs.next(); jpegReader = jpegReaderSPI.createReaderInstance(); } } catch(Exception e) { // Ignore it ... } return jpegReader; }
Example #13
Source File: OutputImageTests.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
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); }
Example #14
Source File: OutputImageTests.java From hottub with GNU General Public License v2.0 | 5 votes |
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); }
Example #15
Source File: InputImageTests.java From hottub with GNU General Public License v2.0 | 5 votes |
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); }
Example #16
Source File: InputImageTests.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
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); }
Example #17
Source File: CanWriteSequence.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
public static void main(final String[] args) throws Exception { final IIORegistry registry = IIORegistry.getDefaultInstance(); final Iterator<ImageWriterSpi> iter = registry.getServiceProviders(ImageWriterSpi.class, provider -> true, true); // Validates all supported ImageWriters while (iter.hasNext()) { final ImageWriter writer = iter.next().createWriterInstance(); System.out.println("ImageWriter = " + writer); test(writer); } System.out.println("Test passed"); }
Example #18
Source File: OutputImageTests.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
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); }
Example #19
Source File: AppContextTest.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
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; } } }
Example #20
Source File: DeregisterAllSpiTest.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
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()!"); } }
Example #21
Source File: RegisterPluginTwiceTest.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
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!"); } }
Example #22
Source File: InputImageTests.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
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); }
Example #23
Source File: OutputImageTests.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
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); }
Example #24
Source File: CanWriteSequence.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
public static void main(final String[] args) throws Exception { final IIORegistry registry = IIORegistry.getDefaultInstance(); final Iterator<ImageWriterSpi> iter = registry.getServiceProviders(ImageWriterSpi.class, provider -> true, true); // Validates all supported ImageWriters while (iter.hasNext()) { final ImageWriter writer = iter.next().createWriterInstance(); System.out.println("ImageWriter = " + writer); test(writer); } System.out.println("Test passed"); }
Example #25
Source File: InputImageTests.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
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); }
Example #26
Source File: CanWriteSequence.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
public static void main(final String[] args) throws Exception { final IIORegistry registry = IIORegistry.getDefaultInstance(); final Iterator<ImageWriterSpi> iter = registry.getServiceProviders(ImageWriterSpi.class, provider -> true, true); // Validates all supported ImageWriters while (iter.hasNext()) { final ImageWriter writer = iter.next().createWriterInstance(); System.out.println("ImageWriter = " + writer); test(writer); } System.out.println("Test passed"); }
Example #27
Source File: AppContextTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
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; } } }
Example #28
Source File: JAIIIOServiceImpl.java From scifio with BSD 2-Clause "Simplified" License | 5 votes |
@Override public void writeImage(final OutputStream out, final BufferedImage img, final JPEG2000CodecOptions options) throws IOException, ServiceException { final ImageOutputStream ios = ImageIO.createImageOutputStream(out); final IIORegistry registry = IIORegistry.getDefaultInstance(); final Iterator<J2KImageWriterSpi> iter = ServiceRegistry.lookupProviders( J2KImageWriterSpi.class); registry.registerServiceProviders(iter); final J2KImageWriterSpi spi = registry.getServiceProviderByClass( J2KImageWriterSpi.class); final J2KImageWriter writer = new J2KImageWriter(spi); writer.setOutput(ios); final String filter = options.lossless ? J2KImageWriteParam.FILTER_53 : J2KImageWriteParam.FILTER_97; final IIOImage iioImage = new IIOImage(img, null, null); final J2KImageWriteParam param = (J2KImageWriteParam) writer .getDefaultWriteParam(); param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT); param.setCompressionType("JPEG2000"); param.setLossless(options.lossless); param.setFilter(filter); param.setCodeBlockSize(options.codeBlockSize); param.setEncodingRate(options.quality); if (options.tileWidth > 0 && options.tileHeight > 0) { param.setTiling(options.tileWidth, options.tileHeight, options.tileGridXOffset, options.tileGridYOffset); } if (options.numDecompositionLevels != null) { param.setNumDecompositionLevels(options.numDecompositionLevels .intValue()); } writer.write(null, iioImage, param); ios.close(); }
Example #29
Source File: RegisterPluginTwiceTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
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!"); } }
Example #30
Source File: DeregisterAllSpiTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
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()!"); } }