Skip to content

Commit

Permalink
bfconvert: convert DICOM data tile-wise any time -precompressed is …
Browse files Browse the repository at this point in the history
…used

This makes sure that the tiles actually saved match the tile sizes supplied to the writer.
  • Loading branch information
melissalinkert committed Jun 26, 2024
1 parent 23780de commit 4f2a96e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1228,6 +1228,14 @@ private boolean doTileConversion(IFormatWriter writer, String outputFile)
if (writer instanceof DicomWriter ||
(writer instanceof ImageWriter && ((ImageWriter) writer).getWriter(outputFile) instanceof DicomWriter))
{
// if we asked to try a precompressed conversion,
// then the writer's tile sizes will have been set automatically
// according to the input data
// the conversion must then be performed tile-wise to match the tile sizes,
// even if precompression doesn't end up being possible
if (precompressed) {
return true;
}
MetadataStore r = reader.getMetadataStore();
return !(r instanceof IPyramidStore) || ((IPyramidStore) r).getResolutionCount(reader.getSeries()) > 1;
}
Expand Down
15 changes: 1 addition & 14 deletions components/formats-bsd/src/loci/formats/out/DicomWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -235,14 +235,7 @@ public void saveCompressedBytes(int no, byte[] buf, int x, int y, int w, int h)
LOGGER.debug("savePrecompressedBytes(series={}, resolution={}, no={}, x={}, y={})",
series, resolution, no, x, y);

// TODO: may want better handling of non-tiled "extra" images (e.g. label, macro)
MetadataRetrieve r = getMetadataRetrieve();
if ((!(r instanceof IPyramidStore) ||
((IPyramidStore) r).getResolutionCount(series) == 1) &&
!isFullPlane(x, y, w, h))
{
throw new FormatException("DicomWriter does not allow tiles for non-pyramid images");
}

int bytesPerPixel = FormatTools.getBytesPerPixel(
FormatTools.pixelTypeFromString(
Expand Down Expand Up @@ -397,13 +390,7 @@ public void saveBytes(int no, byte[] buf, int x, int y, int w, int h)
int thisTileHeight = tileHeight[resolutionIndex];

MetadataRetrieve r = getMetadataRetrieve();
if ((!(r instanceof IPyramidStore) ||
((IPyramidStore) r).getResolutionCount(series) == 1) &&
!isFullPlane(x, y, w, h))
{
throw new FormatException("DicomWriter does not allow tiles for non-pyramid images");
}
else if (x % thisTileWidth != 0 || y % thisTileHeight != 0 ||
if (x % thisTileWidth != 0 || y % thisTileHeight != 0 ||
(w != thisTileWidth && x + w != getSizeX()) ||
(h != thisTileHeight && y + h != getSizeY()))
{
Expand Down

0 comments on commit 4f2a96e

Please sign in to comment.