mirror of
https://github.com/haraldk/TwelveMonkeys.git
synced 2025-08-05 12:35:29 -04:00
Various Java 9 and beyond fixes:
- ExtraSamplesColorModel now overrides getComponentSize for correct size - TIFFImageReader/WriterSpi now recognizes the JEP 262 TIFF plugin - CCITTFaxEncoderStreamTest now directly creates writer (not JDK one)
This commit is contained in:
parent
de34d4642e
commit
7e0de14783
@ -54,22 +54,13 @@ final class ExtraSamplesColorModel extends ComponentColorModel {
|
||||
// still thinks it has numComponents == cs.getNumComponents() + 1 for most operations
|
||||
private final int numComponents;
|
||||
|
||||
private final int componentSize;
|
||||
|
||||
ExtraSamplesColorModel(ColorSpace cs, boolean hasAlpha, boolean isAlphaPremultiplied, int dataType, int extraComponents) {
|
||||
super(cs, bitsArrayHelper(cs, dataType, extraComponents + (hasAlpha ? 1 : 0)), hasAlpha, isAlphaPremultiplied, Transparency.TRANSLUCENT, dataType);
|
||||
super(cs, hasAlpha, isAlphaPremultiplied, Transparency.TRANSLUCENT, dataType);
|
||||
Validate.isTrue(extraComponents > 0, "Extra components must be > 0");
|
||||
this.numComponents = cs.getNumComponents() + (hasAlpha ? 1 : 0) + extraComponents;
|
||||
}
|
||||
|
||||
private static int[] bitsArrayHelper(ColorSpace cs, int dataType, int extraComponents) {
|
||||
int numBits = getDataTypeSize(dataType);
|
||||
int numComponents = cs.getNumComponents() + extraComponents;
|
||||
int[] bits = new int[numComponents];
|
||||
|
||||
for (int i = 0; i < numComponents; i++) {
|
||||
bits[i] = numBits;
|
||||
}
|
||||
|
||||
return bits;
|
||||
this.componentSize = getDataTypeSize(dataType);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -77,6 +68,11 @@ final class ExtraSamplesColorModel extends ComponentColorModel {
|
||||
return numComponents;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getComponentSize(int componentIdx) {
|
||||
return componentSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCompatibleSampleModel(SampleModel sm) {
|
||||
if (!(sm instanceof ComponentSampleModel)) {
|
||||
|
@ -40,6 +40,8 @@ import java.io.IOException;
|
||||
import java.nio.ByteOrder;
|
||||
import java.util.Locale;
|
||||
|
||||
import static com.twelvemonkeys.imageio.util.IIOUtil.lookupProviderByName;
|
||||
|
||||
/**
|
||||
* TIFFImageReaderSpi
|
||||
*
|
||||
@ -51,6 +53,7 @@ public final class TIFFImageReaderSpi extends ImageReaderSpiBase {
|
||||
/**
|
||||
* Creates a {@code TIFFImageReaderSpi}.
|
||||
*/
|
||||
@SuppressWarnings("WeakerAccess")
|
||||
public TIFFImageReaderSpi() {
|
||||
super(new TIFFProviderInfo());
|
||||
}
|
||||
@ -58,17 +61,13 @@ public final class TIFFImageReaderSpi extends ImageReaderSpiBase {
|
||||
@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);
|
||||
// Make sure we're ordered before the new JEP 262 JRE bundled TIFF plugin
|
||||
// or the Apple-provided TIFF plugin on OS X (which both happen to have the same class name)...
|
||||
ImageReaderSpi sunSpi = lookupProviderByName(registry, "com.sun.imageio.plugins.tiff.TIFFImageReaderSpi", ImageReaderSpi.class);
|
||||
|
||||
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
|
||||
if (sunSpi != null && sunSpi.getVendorName() != null
|
||||
&& (sunSpi.getVendorName().startsWith("Apple") || sunSpi.getVendorName().startsWith("Oracle"))) {
|
||||
registry.setOrdering((Class<ImageReaderSpi>) category, this, sunSpi);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -33,10 +33,12 @@ package com.twelvemonkeys.imageio.plugins.tiff;
|
||||
import com.twelvemonkeys.imageio.spi.ImageWriterSpiBase;
|
||||
|
||||
import javax.imageio.ImageTypeSpecifier;
|
||||
import javax.imageio.ImageWriter;
|
||||
import java.io.IOException;
|
||||
import javax.imageio.spi.ImageWriterSpi;
|
||||
import javax.imageio.spi.ServiceRegistry;
|
||||
import java.util.Locale;
|
||||
|
||||
import static com.twelvemonkeys.imageio.util.IIOUtil.lookupProviderByName;
|
||||
|
||||
/**
|
||||
* TIFFImageWriterSpi
|
||||
*
|
||||
@ -51,15 +53,25 @@ public final class TIFFImageWriterSpi extends ImageWriterSpiBase {
|
||||
super(new TIFFProviderInfo());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void onRegistration(final ServiceRegistry registry, final Class<?> category) {
|
||||
// Make sure we're ordered before the new JEP 262 JRE bundled TIFF plugin
|
||||
ImageWriterSpi sunSpi = lookupProviderByName(registry, "com.sun.imageio.plugins.tiff.TIFFImageWriterSpi", ImageWriterSpi.class);
|
||||
|
||||
if (sunSpi != null && sunSpi.getVendorName() != null && sunSpi.getVendorName().startsWith("Oracle")) {
|
||||
registry.setOrdering((Class<ImageWriterSpi>) category, this, sunSpi);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canEncodeImage(final ImageTypeSpecifier type) {
|
||||
// TODO: Test bit depths compatibility
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImageWriter createWriterInstance(final Object extension) throws IOException {
|
||||
public TIFFImageWriter createWriterInstance(final Object extension) {
|
||||
return new TIFFImageWriter(this);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user