mirror of
https://github.com/haraldk/TwelveMonkeys.git
synced 2025-08-04 20:15:28 -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
|
// still thinks it has numComponents == cs.getNumComponents() + 1 for most operations
|
||||||
private final int numComponents;
|
private final int numComponents;
|
||||||
|
|
||||||
|
private final int componentSize;
|
||||||
|
|
||||||
ExtraSamplesColorModel(ColorSpace cs, boolean hasAlpha, boolean isAlphaPremultiplied, int dataType, int extraComponents) {
|
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");
|
Validate.isTrue(extraComponents > 0, "Extra components must be > 0");
|
||||||
this.numComponents = cs.getNumComponents() + (hasAlpha ? 1 : 0) + extraComponents;
|
this.numComponents = cs.getNumComponents() + (hasAlpha ? 1 : 0) + extraComponents;
|
||||||
}
|
this.componentSize = getDataTypeSize(dataType);
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -77,6 +68,11 @@ final class ExtraSamplesColorModel extends ComponentColorModel {
|
|||||||
return numComponents;
|
return numComponents;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getComponentSize(int componentIdx) {
|
||||||
|
return componentSize;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isCompatibleSampleModel(SampleModel sm) {
|
public boolean isCompatibleSampleModel(SampleModel sm) {
|
||||||
if (!(sm instanceof ComponentSampleModel)) {
|
if (!(sm instanceof ComponentSampleModel)) {
|
||||||
|
@ -40,6 +40,8 @@ import java.io.IOException;
|
|||||||
import java.nio.ByteOrder;
|
import java.nio.ByteOrder;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
|
import static com.twelvemonkeys.imageio.util.IIOUtil.lookupProviderByName;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TIFFImageReaderSpi
|
* TIFFImageReaderSpi
|
||||||
*
|
*
|
||||||
@ -51,6 +53,7 @@ public final class TIFFImageReaderSpi extends ImageReaderSpiBase {
|
|||||||
/**
|
/**
|
||||||
* Creates a {@code TIFFImageReaderSpi}.
|
* Creates a {@code TIFFImageReaderSpi}.
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("WeakerAccess")
|
||||||
public TIFFImageReaderSpi() {
|
public TIFFImageReaderSpi() {
|
||||||
super(new TIFFProviderInfo());
|
super(new TIFFProviderInfo());
|
||||||
}
|
}
|
||||||
@ -58,17 +61,13 @@ public final class TIFFImageReaderSpi extends ImageReaderSpiBase {
|
|||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
public void onRegistration(final ServiceRegistry registry, final Class<?> category) {
|
public void onRegistration(final ServiceRegistry registry, final Class<?> category) {
|
||||||
// Make sure we're ordered before the Apple-provided TIFF reader on OS X
|
// Make sure we're ordered before the new JEP 262 JRE bundled TIFF plugin
|
||||||
try {
|
// or the Apple-provided TIFF plugin on OS X (which both happen to have the same class name)...
|
||||||
Class<ImageReaderSpi> providerClass = (Class<ImageReaderSpi>) Class.forName("com.sun.imageio.plugins.tiff.TIFFImageReaderSpi");
|
ImageReaderSpi sunSpi = lookupProviderByName(registry, "com.sun.imageio.plugins.tiff.TIFFImageReaderSpi", ImageReaderSpi.class);
|
||||||
ImageReaderSpi appleSpi = registry.getServiceProviderByClass(providerClass);
|
|
||||||
|
|
||||||
if (appleSpi != null && appleSpi.getVendorName() != null && appleSpi.getVendorName().startsWith("Apple")) {
|
if (sunSpi != null && sunSpi.getVendorName() != null
|
||||||
registry.setOrdering((Class<ImageReaderSpi>) category, this, appleSpi);
|
&& (sunSpi.getVendorName().startsWith("Apple") || sunSpi.getVendorName().startsWith("Oracle"))) {
|
||||||
}
|
registry.setOrdering((Class<ImageReaderSpi>) category, this, sunSpi);
|
||||||
}
|
|
||||||
catch (ClassNotFoundException ignore) {
|
|
||||||
// This is actually OK, now we don't have to do anything
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,10 +33,12 @@ package com.twelvemonkeys.imageio.plugins.tiff;
|
|||||||
import com.twelvemonkeys.imageio.spi.ImageWriterSpiBase;
|
import com.twelvemonkeys.imageio.spi.ImageWriterSpiBase;
|
||||||
|
|
||||||
import javax.imageio.ImageTypeSpecifier;
|
import javax.imageio.ImageTypeSpecifier;
|
||||||
import javax.imageio.ImageWriter;
|
import javax.imageio.spi.ImageWriterSpi;
|
||||||
import java.io.IOException;
|
import javax.imageio.spi.ServiceRegistry;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
|
import static com.twelvemonkeys.imageio.util.IIOUtil.lookupProviderByName;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TIFFImageWriterSpi
|
* TIFFImageWriterSpi
|
||||||
*
|
*
|
||||||
@ -51,15 +53,25 @@ public final class TIFFImageWriterSpi extends ImageWriterSpiBase {
|
|||||||
super(new TIFFProviderInfo());
|
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
|
@Override
|
||||||
public boolean canEncodeImage(final ImageTypeSpecifier type) {
|
public boolean canEncodeImage(final ImageTypeSpecifier type) {
|
||||||
// TODO: Test bit depths compatibility
|
// TODO: Test bit depths compatibility
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ImageWriter createWriterInstance(final Object extension) throws IOException {
|
public TIFFImageWriter createWriterInstance(final Object extension) {
|
||||||
return new TIFFImageWriter(this);
|
return new TIFFImageWriter(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user