mirror of
https://github.com/haraldk/TwelveMonkeys.git
synced 2025-08-05 04:25:29 -04:00
TMI-TIFF: Better ICC profile support + more BitsPerSample configurations.
This commit is contained in:
parent
d4e34d6109
commit
2bdfa4fccb
@ -435,6 +435,11 @@ public class TIFFImageReader extends ImageReaderBase {
|
|||||||
return ImageTypeSpecifiers.createBanded(cs, new int[] {0, 1, 2, 3}, new int[] {0, 0, 0, 0}, dataType, true, extraSamples[0] == 1);
|
return ImageTypeSpecifiers.createBanded(cs, new int[] {0, 1, 2, 3}, new int[] {0, 0, 0, 0}, dataType, true, extraSamples[0] == 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (bitsPerSample == 4) {
|
||||||
|
long[] extraSamples = getValueAsLongArray(TIFF.TAG_EXTRA_SAMPLES, "ExtraSamples", true);
|
||||||
|
|
||||||
|
return ImageTypeSpecifier.createPacked(cs, 0xF000, 0xF00, 0xF0, 0xF, DataBuffer.TYPE_USHORT, extraSamples[0] == 1);
|
||||||
|
}
|
||||||
// TODO: More samples might be ok, if multiple alpha or unknown samples
|
// TODO: More samples might be ok, if multiple alpha or unknown samples
|
||||||
default:
|
default:
|
||||||
throw new IIOException(String.format("Unsupported SamplesPerPixels/BitsPerSample combination for RGB TIFF (expected 3/8, 4/8, 3/16 or 4/16): %d/%d", samplesPerPixel, bitsPerSample));
|
throw new IIOException(String.format("Unsupported SamplesPerPixels/BitsPerSample combination for RGB TIFF (expected 3/8, 4/8, 3/16 or 4/16): %d/%d", samplesPerPixel, bitsPerSample));
|
||||||
@ -714,7 +719,8 @@ public class TIFFImageReader extends ImageReaderBase {
|
|||||||
|
|
||||||
int tilesAcross = (width + stripTileWidth - 1) / stripTileWidth;
|
int tilesAcross = (width + stripTileWidth - 1) / stripTileWidth;
|
||||||
int tilesDown = (height + stripTileHeight - 1) / stripTileHeight;
|
int tilesDown = (height + stripTileHeight - 1) / stripTileHeight;
|
||||||
WritableRaster rowRaster = rawType.getColorModel().createCompatibleWritableRaster(stripTileWidth, 1);
|
// WritableRaster rowRaster = rawType.getColorModel().createCompatibleWritableRaster(stripTileWidth, 1);
|
||||||
|
WritableRaster rowRaster = rawType.createBufferedImage(stripTileWidth, 1).getRaster();
|
||||||
Rectangle clip = new Rectangle(srcRegion);
|
Rectangle clip = new Rectangle(srcRegion);
|
||||||
int row = 0;
|
int row = 0;
|
||||||
|
|
||||||
@ -1563,17 +1569,19 @@ public class TIFFImageReader extends ImageReaderBase {
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ICC_Profile getICCProfile() {
|
private ICC_Profile getICCProfile() throws IOException {
|
||||||
Entry entry = currentIFD.getEntryById(TIFF.TAG_ICC_PROFILE);
|
Entry entry = currentIFD.getEntryById(TIFF.TAG_ICC_PROFILE);
|
||||||
|
|
||||||
if (entry != null) {
|
if (entry != null) {
|
||||||
byte[] value = (byte[]) entry.getValue();
|
byte[] value = (byte[]) entry.getValue();
|
||||||
ICC_Profile profile = ICC_Profile.getInstance(value);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
// WEIRDNESS: Reading profile from InputStream is somehow more compatible
|
||||||
|
// than reading from byte array (chops off extra bytes + validates profile).
|
||||||
|
ICC_Profile profile = ICC_Profile.getInstance(new ByteArrayInputStream(value));
|
||||||
return ColorSpaces.validateProfile(profile);
|
return ColorSpaces.validateProfile(profile);
|
||||||
}
|
}
|
||||||
catch (CMMException ignore) {
|
catch (CMMException | IllegalArgumentException ignore) {
|
||||||
processWarningOccurred("Ignoring broken/incompatible ICC profile: " + ignore.getMessage());
|
processWarningOccurred("Ignoring broken/incompatible ICC profile: " + ignore.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -85,6 +85,8 @@ public class TIFFImageReaderTest extends ImageReaderAbstractTest<TIFFImageReader
|
|||||||
new TestData(getClassLoaderResource("/tiff/signed-integral-8bit.tif"), new Dimension(439, 167)), // Gray, 8 bit *signed* integral
|
new TestData(getClassLoaderResource("/tiff/signed-integral-8bit.tif"), new Dimension(439, 167)), // Gray, 8 bit *signed* integral
|
||||||
new TestData(getClassLoaderResource("/tiff/floatingpoint-32bit.tif"), new Dimension(300, 100)), // RGB, 32 bit floating point
|
new TestData(getClassLoaderResource("/tiff/floatingpoint-32bit.tif"), new Dimension(300, 100)), // RGB, 32 bit floating point
|
||||||
new TestData(getClassLoaderResource("/tiff/general-cmm-error.tif"), new Dimension(1181, 860)), // RGB, LZW compression with broken/incompatible ICC profile
|
new TestData(getClassLoaderResource("/tiff/general-cmm-error.tif"), new Dimension(1181, 860)), // RGB, LZW compression with broken/incompatible ICC profile
|
||||||
|
new TestData(getClassLoaderResource("/tiff/lzw-rgba-padded-icc.tif"), new Dimension(19, 11)), // RGBA, LZW compression with padded ICC profile
|
||||||
|
new TestData(getClassLoaderResource("/tiff/lzw-rgba-4444.tif"), new Dimension(64, 64)), // RGBA, LZW compression with UINT 4/4/4/4 + gray 2/2
|
||||||
// CCITT
|
// CCITT
|
||||||
new TestData(getClassLoaderResource("/tiff/ccitt/group3_1d.tif"), new Dimension(6, 4)), // B/W, CCITT T4 1D
|
new TestData(getClassLoaderResource("/tiff/ccitt/group3_1d.tif"), new Dimension(6, 4)), // B/W, CCITT T4 1D
|
||||||
new TestData(getClassLoaderResource("/tiff/ccitt/group3_1d_fill.tif"), new Dimension(6, 4)), // B/W, CCITT T4 1D
|
new TestData(getClassLoaderResource("/tiff/ccitt/group3_1d_fill.tif"), new Dimension(6, 4)), // B/W, CCITT T4 1D
|
||||||
|
BIN
imageio/imageio-tiff/src/test/resources/tiff/lzw-rgba-4444.tif
Normal file
BIN
imageio/imageio-tiff/src/test/resources/tiff/lzw-rgba-4444.tif
Normal file
Binary file not shown.
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user