Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DICOM writer: throw an exception if the provided tiles don't match the expected tile size #4097

Merged
merged 1 commit into from
Oct 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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