@Override public String[] getReaderDescription() { return new String[] { "Image Codec: " + codec.getCodecName(), "Version: " + Core.VERSION, "Supports the common types of image files (JPEG, TIFF, PNG...)" }; //$NON-NLS-1$ }
private static void registerCodecPlugins(Codec codec) { if (codec != null && !BundleTools.CODEC_PLUGINS.contains(codec)) { BundleTools.CODEC_PLUGINS.add(codec); LOGGER.info("Register Image Codec Plug-in: {}", codec.getCodecName()); //$NON-NLS-1$ } }
@Override public synchronized List<Codec> getCodecPlugins() { ArrayList<Codec> codecPlugins = new ArrayList<>(1); synchronized (BundleTools.CODEC_PLUGINS) { for (Codec codec : BundleTools.CODEC_PLUGINS) { if (codec != null && "Sun java imageio".equals(codec.getCodecName()) == false //$NON-NLS-1$ && codec.isMimeTypeSupported("application/dicom") && !codecPlugins.contains(codec)) { //$NON-NLS-1$ codecPlugins.add(codec); } } } return codecPlugins; }
public static Codec getCodec(String mimeType, String preferredCodec) { Codec codec = null; synchronized (BundleTools.CODEC_PLUGINS) { for (Codec c : BundleTools.CODEC_PLUGINS) { if (c.isMimeTypeSupported(mimeType)) { if (c.getCodecName().equals(preferredCodec)) { codec = c; break; } // If the preferred codec cannot be find, the first-found codec is retained if (codec == null) { codec = c; } } } return codec; } }
@Override public synchronized void serviceChanged(ServiceEvent event) { ServiceReference<?> sRef = event.getServiceReference(); BundleContext context = AppProperties.getBundleContext(sRef); Codec codec = null; try { codec = (Codec) context.getService(sRef); } catch (RuntimeException e) { // TODO find why sometimes service cannot be returned LOGGER.info("Cannot get service of {}", sRef.getBundle()); //$NON-NLS-1$ } if (codec == null) { return; } // TODO manage when several identical MimeType, register the default one if (event.getType() == ServiceEvent.REGISTERED) { registerCodecPlugins(codec); } else if (event.getType() == ServiceEvent.UNREGISTERING) { if (BundleTools.CODEC_PLUGINS.contains(codec)) { LOGGER.info("Unregister Image Codec Plug-in: {}", codec.getCodecName()); //$NON-NLS-1$ BundleTools.CODEC_PLUGINS.remove(codec); } // Unget service object and null references. context.ungetService(sRef); } }