Skip to content

Commit

Permalink
TiffSaver: reduce seeks and buffer strip writing
Browse files Browse the repository at this point in the history
  • Loading branch information
melissalinkert committed Sep 22, 2024
1 parent 88b846d commit 0b42e1b
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions components/formats-bsd/src/loci/formats/tiff/TiffSaver.java
Original file line number Diff line number Diff line change
Expand Up @@ -1176,15 +1176,13 @@ else if (isTiled) {
// return to original position
out.seek(stripStartPos);

ByteArrayOutputStream stripBuffer = new ByteArrayOutputStream();
long stripOffset = 0;
for (int i=0; i<strips.length; i++) {
out.seek(stripStartPos + stripOffset);
stripOffset += strips[i].length;
int index = interleaved ? i : (i / nChannels) * nChannels;
int c = interleaved ? 0 : i % nChannels;
int thisOffset = firstOffset + index + (c * tileCount);
offsets[thisOffset] = out.getFilePointer();
// byteCounts.set(thisOffset, new Long(strips[i].length));
offsets[thisOffset] = stripStartPos + stripOffset;
byteCounts[thisOffset] = strips[i].length;
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(String.format(
Expand All @@ -1193,8 +1191,12 @@ else if (isTiled) {
thisOffset + 1, totalTiles, byteCounts[thisOffset],
offsets[thisOffset]));
}
out.write(strips[i]);
stripBuffer.write(strips[i]);
stripOffset += strips[i].length;
}
stripBuffer.writeTo(out);
stripBuffer.close();
stripBuffer = null;
if (isTiled) {
ifd.putIFDValue(IFD.TILE_BYTE_COUNTS, byteCounts);
ifd.putIFDValue(IFD.TILE_OFFSETS, offsets);
Expand Down

0 comments on commit 0b42e1b

Please sign in to comment.