Skip to content

Commit

Permalink
Issue geosolutions-it#317 : Writing compressed tiled TIFF is broken
Browse files Browse the repository at this point in the history
  • Loading branch information
Frederic JURY committed Dec 11, 2024
1 parent 1e99450 commit 5014140
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
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

0 comments on commit 5014140

Please sign in to comment.