Skip to content

Commit

Permalink
Merge pull request #4097 from melissalinkert/dicom-writer-limit-tile-…
Browse files Browse the repository at this point in the history
…size

DICOM writer: throw an exception if the provided tiles don't match the expected tile size
  • Loading branch information
dgault authored Oct 13, 2023
2 parents bd6b820 + 0034435 commit 09edddc
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions components/formats-bsd/src/loci/formats/out/DicomWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -188,18 +188,28 @@ public void saveBytes(int no, byte[] buf, int x, int y, int w, int h)
{
checkParams(no, buf, x, y, w, h);

int resolutionIndex = getIndex(series, resolution);
int thisTileWidth = tileWidth[resolutionIndex];
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 ||
(w != thisTileWidth && x + w != getSizeX()) ||
(h != thisTileHeight && y + h != getSizeY()))
{
throw new FormatException("Tile too small, expected " + thisTileWidth + "x" + thisTileHeight +
". Setting the tile size to " + getSizeX() + "x" + getSizeY() + " or smaller may work.");
}
checkPixelCount(false);

boolean first = x == 0 && y == 0;
boolean last = x + w == getSizeX() && y + h == getSizeY();
int resolutionIndex = getIndex(series, resolution);

// the compression type isn't supplied to the writer until
// after setId is called, so metadata that indicates or
Expand Down Expand Up @@ -264,8 +274,6 @@ public void saveBytes(int no, byte[] buf, int x, int y, int w, int h)

byte[] paddedBuf = null;

int thisTileWidth = tileWidth[resolutionIndex];
int thisTileHeight = tileHeight[resolutionIndex];
int thisTilePixels = thisTileWidth * thisTileHeight;

// pad the last row and column of tiles to match specified tile size
Expand Down

0 comments on commit 09edddc

Please sign in to comment.