Skip to content

Commit 3f0fa88

Browse files
authored
Fix checkbounds (when bounds are outside acceptable limits) (#62)
1 parent 7712f67 commit 3f0fa88

3 files changed

Lines changed: 10 additions & 8 deletions

File tree

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
<groupId>fr.igred</groupId>
1111
<artifactId>simple-omero-client</artifactId>
12-
<version>5.13.0</version>
12+
<version>5.13.1</version>
1313
<packaging>jar</packaging>
1414

1515
<name>Simple OMERO Client</name>

src/main/java/fr/igred/omero/repository/PixelsWrapper.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,20 +109,22 @@ private static void copy(byte[] bytes, Plane2D p, Coordinates start, int width,
109109

110110

111111
/**
112-
* Checks bounds
112+
* Checks bounds.
113+
* <br>If the lower bound is outside [0 - imageSize-1], the resulting value will be 0.
114+
* <br>Conversely, if the higher bound is outside [0 - imageSize-1], the resulting value will be imageSize-1.
113115
*
114116
* @param bounds Array containing the specified bounds for 1 coordinate.
115117
* @param imageSize Size of the image (in the corresponding dimension).
116118
*
117119
* @return New array with valid bounds.
118120
*/
119121
private static int[] checkBounds(int[] bounds, int imageSize) {
120-
int[] newBounds = {0, imageSize - 1};
122+
int[] b = {0, imageSize - 1};
121123
if (bounds != null && bounds.length > 1) {
122-
newBounds[0] = Math.max(newBounds[0], bounds[0]);
123-
newBounds[1] = Math.min(newBounds[1], bounds[1]);
124+
b[0] = bounds[0] >= b[0] && bounds[0] <= b[1] ? bounds[0] : b[0];
125+
b[1] = bounds[1] >= b[0] && bounds[1] <= b[1] ? bounds[1] : b[1];
124126
}
125-
return newBounds;
127+
return b;
126128
}
127129

128130

src/test/java/fr/igred/omero/repository/PixelsTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ void testGetRawDataBoundError() throws Exception {
106106
PixelsWrapper pixels = image.getPixels();
107107

108108
int[] xBounds = {511, 513};
109-
int[] yBounds = {0, 2};
110-
int[] cBounds = {0, 2};
109+
int[] yBounds = {525, 2};
110+
int[] cBounds = {-1, -1};
111111
int[] zBounds = {0, 2};
112112
int[] tBounds = {0, 2};
113113

0 commit comments

Comments
 (0)