ScaleToNearestFactorPreprocessor extends ScalePreprocessor { @Override public void process() { if (widthFactor1 < THRESHOLD || heightFactor1 < THRESHOLD || widthFactor2 < THRESHOLD || heightFactor2 < THRESHOLD) { LOGGER.info("Scaling image with factors [{}], [{}]", widthFactor1, heightFactor1); super.process(); } else { LOGGER.info("All scale factors [{}], [{}], [{}], [{}] are above threshold [{}]", widthFactor1, heightFactor1, widthFactor2, heightFactor2, THRESHOLD); result1 = img1; result2 = img2; } } ScaleToNearestFactorPreprocessor(final BufferedImage img1, final BufferedImage img2, int targetSize); @Override void process();  }
@Test public void executeTest_ltSize_gtSize() { BufferedImage img1 = BufferedImageHelper.createSolidImage(new Color(0, 0, 0), 400, 200); BufferedImage img2 = BufferedImageHelper.createSolidImage(new Color(0, 0, 0), 100, 50); ScaleToNearestFactorPreprocessor pp = new ScaleToNearestFactorPreprocessor(img1, img2, 100); pp.process(); Assert.assertEquals(200, pp.getResult1().getWidth()); Assert.assertEquals(100, pp.getResult1().getHeight()); Assert.assertEquals(100, pp.getResult2().getWidth()); Assert.assertEquals(50, pp.getResult2().getHeight()); }
@Test public void executeTest_ltSize_gtSize_floor() { BufferedImage img1 = BufferedImageHelper.createSolidImage(new Color(0, 0, 0), 400, 200); BufferedImage img2 = BufferedImageHelper.createSolidImage(new Color(0, 0, 0), 100, 50); ScaleToNearestFactorPreprocessor pp = new ScaleToNearestFactorPreprocessor(img1, img2, 120); pp.process(); Assert.assertEquals(200, pp.getResult1().getWidth()); Assert.assertEquals(100, pp.getResult1().getHeight()); Assert.assertEquals(100, pp.getResult2().getWidth()); Assert.assertEquals(50, pp.getResult2().getHeight()); }
@Test public void executeTest_ltSize_ltSize_ceil_floor() { BufferedImage img1 = BufferedImageHelper.createSolidImage(new Color(0, 0, 0), 400, 200); BufferedImage img2 = BufferedImageHelper.createSolidImage(new Color(0, 0, 0), 360, 300); ScaleToNearestFactorPreprocessor pp = new ScaleToNearestFactorPreprocessor(img1, img2, 90); pp.process(); Assert.assertEquals(200, pp.getResult1().getWidth()); Assert.assertEquals(100, pp.getResult1().getHeight()); Assert.assertEquals(120, pp.getResult2().getWidth()); Assert.assertEquals(100, pp.getResult2().getHeight()); }
@Test public void executeTest_equalSize() { BufferedImage img1 = BufferedImageHelper.createSolidImage(new Color(0, 0, 0)); BufferedImage img2 = BufferedImageHelper.createSolidImage(new Color(0, 0, 0)); ScaleToNearestFactorPreprocessor pp = new ScaleToNearestFactorPreprocessor(img1, img2, 500); pp.process(); Assert.assertEquals(img1, pp.getResult1()); Assert.assertEquals(img2, pp.getResult2()); }
@Test public void executeTest_ltSize() { BufferedImage img1 = BufferedImageHelper.createSolidImage(new Color(0, 0, 0)); BufferedImage img2 = BufferedImageHelper.createSolidImage(new Color(0, 0, 0)); ScaleToNearestFactorPreprocessor pp = new ScaleToNearestFactorPreprocessor(img1, img2, BufferedImageHelper.DEFAULT_WIDTH / 2); pp.process(); Assert.assertEquals(BufferedImageHelper.DEFAULT_WIDTH / 2, pp.getResult1().getWidth()); Assert.assertEquals(BufferedImageHelper.DEFAULT_HEIGHT / 2, pp.getResult1().getHeight()); Assert.assertEquals(BufferedImageHelper.DEFAULT_WIDTH / 2, pp.getResult2().getWidth()); Assert.assertEquals(BufferedImageHelper.DEFAULT_HEIGHT / 2, pp.getResult2().getHeight()); }
@Test public void executeTest_equalSize_gtSize() { BufferedImage img1 = BufferedImageHelper.createSolidImage(new Color(0, 0, 0), 400, 200); BufferedImage img2 = BufferedImageHelper.createSolidImage(new Color(0, 0, 0), 100, 50); ScaleToNearestFactorPreprocessor pp = new ScaleToNearestFactorPreprocessor(img1, img2, 200); pp.process(); Assert.assertEquals(400, pp.getResult1().getWidth()); Assert.assertEquals(200, pp.getResult1().getHeight()); Assert.assertEquals(100, pp.getResult2().getWidth()); Assert.assertEquals(50, pp.getResult2().getHeight()); }