Skip to content

Commit

Permalink
Fix strip padding when working with planar strips
Browse files Browse the repository at this point in the history
  • Loading branch information
melissalinkert committed Aug 8, 2024
1 parent 00ac6cc commit d341f4c
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions components/formats-bsd/src/loci/formats/tiff/TiffSaver.java
Original file line number Diff line number Diff line change
Expand Up @@ -350,15 +350,22 @@ public void writeImage(byte[] buf, IFD ifd, int no, int pixelType, int x,
stripOut[strip].write(buf, strip * stripSize, stripSize);
}
} else {
for (int strip = 0; strip < nStrips - 1; strip++) {
stripOut[strip].write(buf, strip * stripSize, stripSize);
}
// Sigh. Need to pad the last strip.
int pos = (nStrips - 1) * stripSize;
int len = buf.length - pos;
stripOut[nStrips - 1].write(buf, pos, len);
for (int n = len; n < stripSize; n++) {
stripOut[nStrips - 1].writeByte(0);
int effectiveStrips = !interleaved ? nStrips / nChannels : nStrips;
int planarChannels = !interleaved ? nChannels : 1;
int totalBytesPerChannel = buf.length / planarChannels;
for (int p=0; p<planarChannels; p++) {
for (int strip = 0; strip < effectiveStrips - 1; strip++) {
stripOut[p * effectiveStrips + strip].write(buf, strip * stripSize, stripSize);
}
// Sigh. Need to pad the last strip.
int pos = p * totalBytesPerChannel + (effectiveStrips - 1) * stripSize;
int len = (p + 1)*totalBytesPerChannel - pos;
int lastStripIndex = p * effectiveStrips + (effectiveStrips - 1);
stripOut[lastStripIndex].write(buf, pos, len);

byte[] extra = new byte[stripSize - len];
Arrays.fill(extra, (byte) 0);
stripOut[lastStripIndex].write(extra);
}
}
} else {
Expand Down

0 comments on commit d341f4c

Please sign in to comment.