Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #317 : Writing compressed tiled TIFF is broken #318

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions plugin/tiff/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>it.geosolutions.imageio-ext</groupId>
<artifactId>imageio-ext-library</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.airlift</groupId>
<artifactId>aircompressor</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ public int compress(byte[] destData, int srcOffset, int srcLength,
int destOffset, int destLength) {
deflater.setInput(srcData, srcOffset, srcLength);
deflater.finish();
return deflater.deflate(destData, destOffset, destLength);
final int written = deflater.deflate(destData, destOffset, destLength);
deflater.reset();
return written;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,29 @@ public void writeZSTD() throws IOException {
writeParam.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
writeParam.setCompressionType("ZSTD");
writer.setOutput(new FileImageOutputStream(outputFile));
writer.write(image);
writer.write(null, new IIOImage(image, null, null), writeParam);
writer.dispose();
TIFFReadTest.assertImagesEqual(image, TIFFReadTest.readTiff(outputFile));
}

@Test
public void writeDeflatedTilled() throws IOException {
final File inputFile =TestData.file(this, "test.tif");
final File outputFile = TestData.temp(this, "testw.tif",true);
TIFFImageReader reader = (TIFFImageReader) new TIFFImageReaderSpi()
.createReaderInstance();
reader.setInput(new FileImageInputStream(inputFile));
BufferedImage image = reader.read(0);
final TIFFImageWriter writer= (TIFFImageWriter) new TIFFImageWriterSpi().createWriterInstance();
final ImageWriteParam writeParam= new TIFFImageWriteParam(Locale.getDefault());
writeParam.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
writeParam.setTilingMode(ImageWriteParam.MODE_EXPLICIT);
writeParam.setTiling(8, 8,0,0);
writeParam.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
writeParam.setCompressionType("Deflate");
writeParam.setCompressionQuality(1);
writer.setOutput(new FileImageOutputStream(outputFile));
writer.write(null, new IIOImage(image, null, null), writeParam);
writer.dispose();
TIFFReadTest.assertImagesEqual(image, TIFFReadTest.readTiff(outputFile));
}
Expand Down