Skip to content

Commit

Permalink
Merge pull request #199 from melissalinkert/opencv-type-error
Browse files Browse the repository at this point in the history
Throw an informative exception if OpenCV is used to downsample int8/int32
  • Loading branch information
sbesson authored May 19, 2023
2 parents 637808c + 39fffc4 commit 63bae15
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1883,6 +1883,15 @@ public void saveResolutions(int series)
readers.put(workingReader);
}

if ((pixelType == FormatTools.INT8 || pixelType == FormatTools.INT32) &&
getDownsampling() != Downsampling.SIMPLE && resolutions > 0)
{
String type = FormatTools.getPixelTypeString(pixelType);
throw new UnsupportedOperationException(
"OpenCV does not support downsampling " + type + " data. " +
"See https://github.com/opencv/opencv/issues/7862");
}

LOGGER.info(
"Preparing to write pyramid sizeX {} (tileWidth: {}) " +
"sizeY {} (tileWidth: {}) sizeZ {} (tileDepth: {}) imageCount {}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -972,6 +972,38 @@ public void testDownsampleTypes(Downsampling type) throws IOException {
}
}

/**
* Make sure an informative exception is thrown when trying to use
* OpenCV to downsample int8 data.
* See https://github.com/opencv/opencv/issues/7862
*/
@Test
public void testUnsupportedOpenCVType() throws Exception {
input = fake("pixelType", "int8");
assertThrows(ExecutionException.class, () -> {
assertTool("--downsample-type", "LINEAR");
});
}

/**
* Make sure an informative exception is thrown when trying to use
* OpenCV to downsample int32 data. Uses the API instead of
* command line arguments.
* See https://github.com/opencv/opencv/issues/7862
*/
@Test
public void testUnsupportedOpenCVTypeAPI() throws Exception {
input = fake("pixelType", "int32");
Converter apiConverter = new Converter();
apiConverter.setInputPath(input.toString());
apiConverter.setOutputPath(output.toString());
apiConverter.setDownsampling(Downsampling.AREA);

assertThrows(UnsupportedOperationException.class, () -> {
apiConverter.call();
});
}

/**
* Test that nested storage works equivalently.
*
Expand Down

0 comments on commit 63bae15

Please sign in to comment.