mirror of
https://github.com/haraldk/TwelveMonkeys.git
synced 2025-08-03 03:25:28 -04:00
Merging TIFF pages failed, if a page contained a sub IFD without a TIFF.TAG_COMPRESSION entry
This commit is contained in:
parent
7cb1c6811a
commit
18800b6ee4
@ -477,12 +477,13 @@ public final class TIFFUtilities {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Entry compressionEntry = IFD.getEntryById(TIFF.TAG_COMPRESSION);
|
Entry compressionEntry = IFD.getEntryById(TIFF.TAG_COMPRESSION);
|
||||||
Number compression = (Number) compressionEntry.getValue();
|
if(compressionEntry != null) {
|
||||||
if (compression.shortValue() == TIFFExtension.COMPRESSION_OLD_JPEG) {
|
Number compression = (Number) compressionEntry.getValue();
|
||||||
newIFD.remove(compressionEntry);
|
if (compression.shortValue() == TIFFExtension.COMPRESSION_OLD_JPEG) {
|
||||||
newIFD.add(new TIFFEntry(TIFF.TAG_COMPRESSION, TIFF.TYPE_SHORT, TIFFExtension.COMPRESSION_JPEG));
|
newIFD.remove(compressionEntry);
|
||||||
|
newIFD.add(new TIFFEntry(TIFF.TAG_COMPRESSION, TIFF.TYPE_SHORT, TIFFExtension.COMPRESSION_JPEG));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return newIFD;
|
return newIFD;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -233,6 +233,34 @@ public class TIFFUtilitiesTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testMergeWithSubIFD() throws IOException {
|
||||||
|
String testFile = "/tiff/cmyk_jpeg.tif";
|
||||||
|
|
||||||
|
File output = File.createTempFile("imageiotest", ".tif");
|
||||||
|
ImageOutputStream outputStream = ImageIO.createImageOutputStream(output);
|
||||||
|
InputStream inputStream1 = getClassLoaderResource(testFile).openStream();
|
||||||
|
ImageInputStream imageInput1 = ImageIO.createImageInputStream(inputStream1);
|
||||||
|
InputStream inputStream2 = getClassLoaderResource(testFile).openStream();
|
||||||
|
ImageInputStream imageInput2 = ImageIO.createImageInputStream(inputStream2);
|
||||||
|
ArrayList<TIFFUtilities.TIFFPage> pages = new ArrayList<>();
|
||||||
|
pages.addAll(TIFFUtilities.getPages(imageInput1));
|
||||||
|
pages.addAll(TIFFUtilities.getPages(imageInput2));
|
||||||
|
TIFFUtilities.writePages(outputStream, pages);
|
||||||
|
|
||||||
|
ImageInputStream testOutput = ImageIO.createImageInputStream(output);
|
||||||
|
ImageReader reader = ImageIO.getImageReaders(testOutput).next();
|
||||||
|
reader.setInput(testOutput);
|
||||||
|
int numImages = reader.getNumImages(true);
|
||||||
|
for (int i = 0; i < numImages; i++) {
|
||||||
|
reader.read(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
imageInput1.close();
|
||||||
|
imageInput2.close();
|
||||||
|
outputStream.close();
|
||||||
|
}
|
||||||
|
|
||||||
protected URL getClassLoaderResource(final String pName) {
|
protected URL getClassLoaderResource(final String pName) {
|
||||||
return getClass().getResource(pName);
|
return getClass().getResource(pName);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user