Search in sources :

Example 6 with ImageReaderWriterSpi

use of javax.imageio.spi.ImageReaderWriterSpi in project imageio-ext by geosolutions-it.

the class KakaduUtilities method getJDKImageReaderWriterSPI.

public static List<ImageReaderWriterSpi> getJDKImageReaderWriterSPI(ServiceRegistry registry, String formatName, boolean isReader) {
    if (registry == null || !(registry instanceof IIORegistry))
        throw new IllegalArgumentException("Illegal registry provided");
    IIORegistry iioRegistry = (IIORegistry) registry;
    Class<? extends ImageReaderWriterSpi> spiClass;
    if (isReader)
        spiClass = ImageReaderSpi.class;
    else
        spiClass = ImageWriterSpi.class;
    final Iterator<? extends ImageReaderWriterSpi> iter = iioRegistry.getServiceProviders(spiClass, // useOrdering
    true);
    final ArrayList<ImageReaderWriterSpi> list = new ArrayList<ImageReaderWriterSpi>();
    while (iter.hasNext()) {
        final ImageReaderWriterSpi provider = (ImageReaderWriterSpi) iter.next();
        // Get the formatNames supported by this Spi
        final String[] formatNames = provider.getFormatNames();
        for (int i = 0; i < formatNames.length; i++) {
            if (formatNames[i].equalsIgnoreCase(formatName)) {
                // Must be a JDK provided ImageReader/ImageWriter
                list.add(provider);
                break;
            }
        }
    }
    return list;
}
Also used : ImageReaderWriterSpi(javax.imageio.spi.ImageReaderWriterSpi) IIORegistry(javax.imageio.spi.IIORegistry) ImageReaderSpi(javax.imageio.spi.ImageReaderSpi) ArrayList(java.util.ArrayList) ImageWriterSpi(javax.imageio.spi.ImageWriterSpi)

Example 7 with ImageReaderWriterSpi

use of javax.imageio.spi.ImageReaderWriterSpi in project imageio-ext by geosolutions-it.

the class ImageIOUtilities method getJDKImageReaderWriterSPI.

// Method to return JDK core ImageReaderSPI/ImageWriterSPI for a
// given formatName.
public static List<ImageReaderWriterSpi> getJDKImageReaderWriterSPI(ServiceRegistry registry, String formatName, boolean isReader) {
    IIORegistry iioRegistry = (IIORegistry) registry;
    final Class<? extends ImageReaderWriterSpi> spiClass;
    final String descPart;
    if (isReader) {
        spiClass = ImageReaderSpi.class;
        descPart = " image reader";
    } else {
        spiClass = ImageWriterSpi.class;
        descPart = " image writer";
    }
    // useOrdering
    final Iterator<? extends ImageReaderWriterSpi> iter = iioRegistry.getServiceProviders(spiClass, true);
    String[] formatNames;
    ImageReaderWriterSpi provider;
    String desc = "standard " + formatName + descPart;
    String jiioPath = "com.sun.media.imageioimpl";
    Locale locale = Locale.getDefault();
    ArrayList<ImageReaderWriterSpi> list = new ArrayList<ImageReaderWriterSpi>();
    while (iter.hasNext()) {
        provider = (ImageReaderWriterSpi) iter.next();
        // Look for JDK core ImageWriterSpi's
        if (provider.getVendorName().startsWith("Sun Microsystems") && desc.equalsIgnoreCase(provider.getDescription(locale)) && // not JAI Image I/O plugins
        !provider.getPluginClassName().startsWith(jiioPath)) {
            // Get the formatNames supported by this Spi
            formatNames = provider.getFormatNames();
            for (int i = 0; i < formatNames.length; i++) {
                if (formatNames[i].equalsIgnoreCase(formatName)) {
                    // Must be a JDK provided ImageReader/ImageWriter
                    list.add(provider);
                    break;
                }
            }
        }
    }
    return list;
}
Also used : ImageReaderWriterSpi(javax.imageio.spi.ImageReaderWriterSpi) Locale(java.util.Locale) IIORegistry(javax.imageio.spi.IIORegistry) ArrayList(java.util.ArrayList)

Example 8 with ImageReaderWriterSpi

use of javax.imageio.spi.ImageReaderWriterSpi in project imageio-ext by geosolutions-it.

the class ImageIOUtilities method replaceProvider.

/**
 * Replace the original provider with name originalProviderName with the provider with name
 * customProviderName for the class providerClass and for the provided format .
 * @param providerClass the {@link Class} for the providers.
 * @param customProviderName the name of the provider we want to use as new preferred provider.
 * @param originalProviderName the name of the provider we want to deregister.
 * @param format the format for this provi
 * @return <code>true</code> if we find both of the providers and the replacement succeed, <code>false</code> otherwise.
 */
public static boolean replaceProvider(final Class<? extends ImageReaderWriterSpi> providerClass, final String customProviderName, final String originalProviderName, final String format) {
    // now we need to set the order
    final IIORegistry registry = IIORegistry.getDefaultInstance();
    ImageReaderWriterSpi standard = null, custom = null;
    for (final Iterator<? extends ImageReaderWriterSpi> it = registry.getServiceProviders(providerClass, false); it.hasNext(); ) {
        final ImageReaderWriterSpi provider = it.next();
        final String providerClassName = provider.getClass().getName();
        final String[] formats = provider.getFormatNames();
        for (int i = 0; i < formats.length; i++) {
            if (formats[i].equalsIgnoreCase(format)) {
                if (providerClassName.equalsIgnoreCase(originalProviderName)) {
                    standard = provider;
                } else if (providerClassName.equalsIgnoreCase(customProviderName)) {
                    custom = provider;
                }
                if (standard != null && custom != null) {
                    if (ImageReaderSpi.class.isAssignableFrom(standard.getClass()))
                        return registry.setOrdering(ImageReaderSpi.class, (ImageReaderSpi) custom, (ImageReaderSpi) standard);
                    else
                        return registry.setOrdering(ImageWriterSpi.class, (ImageWriterSpi) custom, (ImageWriterSpi) standard);
                }
            }
        }
    }
    // we did not find them
    return false;
}
Also used : ImageReaderWriterSpi(javax.imageio.spi.ImageReaderWriterSpi) IIORegistry(javax.imageio.spi.IIORegistry) ImageReaderSpi(javax.imageio.spi.ImageReaderSpi) ImageWriterSpi(javax.imageio.spi.ImageWriterSpi)

Aggregations

ImageReaderWriterSpi (javax.imageio.spi.ImageReaderWriterSpi)8 IIORegistry (javax.imageio.spi.IIORegistry)5 ImageReaderSpi (javax.imageio.spi.ImageReaderSpi)5 ImageWriterSpi (javax.imageio.spi.ImageWriterSpi)4 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 Locale (java.util.Locale)1