TMI-TIFF: Implemented pairwise ordering (before Apple-provided com.sun.imageio.plugins.tiff.TIFFImageReaderSpi).

Removed deprecation warning.
This commit is contained in:
Harald Kuhr 2013-11-20 20:26:06 +01:00
parent d6f5a1281c
commit 9a02e90ab9

View File

@ -33,6 +33,7 @@ import com.twelvemonkeys.imageio.spi.ProviderInfo;
import com.twelvemonkeys.imageio.util.IIOUtil; import com.twelvemonkeys.imageio.util.IIOUtil;
import javax.imageio.spi.ImageReaderSpi; import javax.imageio.spi.ImageReaderSpi;
import javax.imageio.spi.ServiceRegistry;
import javax.imageio.stream.ImageInputStream; import javax.imageio.stream.ImageInputStream;
import java.io.IOException; import java.io.IOException;
import java.nio.ByteOrder; import java.nio.ByteOrder;
@ -46,7 +47,6 @@ import java.util.Locale;
* @version $Id: TIFFImageReaderSpi.java,v 1.0 08.05.12 15:14 haraldk Exp$ * @version $Id: TIFFImageReaderSpi.java,v 1.0 08.05.12 15:14 haraldk Exp$
*/ */
public class TIFFImageReaderSpi extends ImageReaderSpi { public class TIFFImageReaderSpi extends ImageReaderSpi {
// TODO: Should we make sure we register (order) before the com.sun.imageio thing (that isn't what is says) provided by Apple?
/** /**
* Creates a {@code TIFFImageReaderSpi}. * Creates a {@code TIFFImageReaderSpi}.
*/ */
@ -64,7 +64,7 @@ public class TIFFImageReaderSpi extends ImageReaderSpi {
"image/tiff", "image/x-tiff" "image/tiff", "image/x-tiff"
}, },
"com.twelvemkonkeys.imageio.plugins.tiff.TIFFImageReader", "com.twelvemkonkeys.imageio.plugins.tiff.TIFFImageReader",
STANDARD_INPUT_TYPE, new Class[] {ImageInputStream.class},
// new String[]{"com.twelvemkonkeys.imageio.plugins.tif.TIFFImageWriterSpi"}, // new String[]{"com.twelvemkonkeys.imageio.plugins.tif.TIFFImageWriterSpi"},
null, null,
true, // supports standard stream metadata true, // supports standard stream metadata
@ -76,6 +76,23 @@ public class TIFFImageReaderSpi extends ImageReaderSpi {
); );
} }
@SuppressWarnings("unchecked")
@Override
public void onRegistration(final ServiceRegistry registry, final Class<?> category) {
// Make sure we're ordered before the Apple-provided TIFF reader on OS X
try {
Class<ImageReaderSpi> providerClass = (Class<ImageReaderSpi>) Class.forName("com.sun.imageio.plugins.tiff.TIFFImageReaderSpi");
ImageReaderSpi appleSpi = registry.getServiceProviderByClass(providerClass);
if (appleSpi != null && appleSpi.getVendorName() != null && appleSpi.getVendorName().startsWith("Apple")) {
registry.setOrdering((Class<ImageReaderSpi>) category, this, appleSpi);
}
}
catch (ClassNotFoundException ignore) {
// This is actually OK, now we don't have to do anything
}
}
public boolean canDecodeInput(final Object pSource) throws IOException { public boolean canDecodeInput(final Object pSource) throws IOException {
if (!(pSource instanceof ImageInputStream)) { if (!(pSource instanceof ImageInputStream)) {
return false; return false;