#195: Fixed AIOOBE related to specific widths

This commit is contained in:
Harald Kuhr 2015-12-16 10:18:26 +01:00
parent 9e5204ddbb
commit 04a4c6e3ae
2 changed files with 15 additions and 3 deletions

View File

@ -1336,7 +1336,7 @@ public class ResampleOp implements BufferedImageOp/* TODO: RasterOp */ {
} }
//contribX.n = 0; //contribX.n = 0;
contribX.p = new Contributor[(int) (width * 2.0 + 1.0)]; contribX.p = new Contributor[(int) (width * 2.0 + 1.0 + 0.5)];
center = (double) i / xscale; center = (double) i / xscale;
int left = (int) Math.ceil(center - width);// Note: Assumes width <= .5 int left = (int) Math.ceil(center - width);// Note: Assumes width <= .5
@ -1387,7 +1387,7 @@ public class ResampleOp implements BufferedImageOp/* TODO: RasterOp */ {
else { else {
/* Expanding image */ /* Expanding image */
//contribX.n = 0; //contribX.n = 0;
contribX.p = new Contributor[(int) (fwidth * 2.0 + 1.0)]; contribX.p = new Contributor[(int) (fwidth * 2.0 + 1.0 + 0.5)];
center = (double) i / xscale; center = (double) i / xscale;
int left = (int) Math.ceil(center - fwidth); int left = (int) Math.ceil(center - fwidth);

View File

@ -306,7 +306,7 @@ public class ResampleOpTestCase {
// https://github.com/haraldk/TwelveMonkeys/issues/195 // https://github.com/haraldk/TwelveMonkeys/issues/195
@Test @Test
public void testAIOOBE() { public void testAIOOBEHeight() {
BufferedImage myImage = new BufferedImage(100, 354, BufferedImage.TYPE_INT_ARGB); BufferedImage myImage = new BufferedImage(100, 354, BufferedImage.TYPE_INT_ARGB);
for (int i = 19; i > 0; i--) { for (int i = 19; i > 0; i--) {
@ -316,6 +316,18 @@ public class ResampleOpTestCase {
} }
} }
// https://github.com/haraldk/TwelveMonkeys/issues/195
@Test
public void testAIOOBEWidth() {
BufferedImage myImage = new BufferedImage(2832, 2832, BufferedImage.TYPE_INT_ARGB);
for (int i = 145; i > 143; i--) {
ResampleOp resampler = new ResampleOp(144, i, ResampleOp.FILTER_LANCZOS);
BufferedImage resizedImage = resampler.filter(myImage, null);
assertNotNull(resizedImage);
}
}
@Ignore("Not for general unit testing") @Ignore("Not for general unit testing")
@Test @Test
public void testTime() { public void testTime() {