diff --git a/src/test/java/com/thebuzzmedia/imgscalr/ComparisonGenerator.java b/src/test/java/com/thebuzzmedia/imgscalr/ComparisonGenerator.java deleted file mode 100644 index f85bb8c..0000000 --- a/src/test/java/com/thebuzzmedia/imgscalr/ComparisonGenerator.java +++ /dev/null @@ -1,148 +0,0 @@ -/** - * Copyright 2010 The Buzz Media, LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.thebuzzmedia.imgscalr; - -import java.io.File; -import java.io.IOException; - -import javax.imageio.ImageIO; - -import org.junit.Test; - -import com.thebuzzmedia.imgscalr.Scalr.Method; - -/** - * Easy class used to generate comparison images using the different landscape - * and portrait examples found in /src/test/resources for easy eye-ball - * comparisons of different scaling methods. - *
- * Images generated from this class are in the format: (image - * name)-(size)-(method).(extension) - *
- * An example would be: screenshot-240-SPEED.png - *
- * What is so nice about this format is that the images of the same size of - * varying qualities all list right next to each other in a directory listing - * (all 240px images are next to each other, all 480px are next to each other - * and so on) making quick visual comparisons of the photos easier. - *
- * NOTE: The reason the method portion of the file names are qualified with 'a', - * 'b' or 'c' is just to make them alphabetically align nicely in a directory - * file listing. - * - * @author Riyad Kalla (software@thebuzzmedia.com) - */ -public class ComparisonGenerator { - public static final int[] SIZES = new int[] { 240, 320, 480, 640, 800, - 1024, 1280, 1600, 1920, 2400, 3200 }; - - public static int genCount = 0; - - /** - * Method used to fire off calls to - * {@link #generateComparisonsForImage(String)} which generates 3 different - * scaled versions (SPEED, BALANCED and QUALITY) of the specified image for - * each size defined in {@link #SIZES}. - *
- * Simply add more calls to {@link #generateComparisonsForImage(String)} - * with a file path pointing at the image you want to generate comparisons - * for. - * - * @throws IOException - * If anything goes wrong with reading or writing the image - * files. - */ - @Test - public void generateComparisons() throws IOException { - long totalTimeStart = System.currentTimeMillis(); - genCount = 0; - - generateComparisonsForImage("bin/L-screenshot.png"); - generateComparisonsForImage("bin/L-time-square.jpg"); - generateComparisonsForImage("bin/P-bicycle-race.jpg"); - - /* - * Huge (5616x3744, 5.5MB) example image from a Canon 5D Mark II used - * for memory profile and a worst-case scenario for performance testing. - * http - * ://www.dpreview.com/galleries/reviewsamples/photos/111116/sample-20 - * ?inalbum=canon-eos-5d-mark-ii-review-samples - */ - // generateComparisonsForImage("bin/L-huge-newspaper-dock.jpg"); - - /* - * Huge (5616x3744, 4.7MB) example image from a Canon 5D Mark II used - * for memory profile and a worst-case scenario for performance testing. - * http - * ://www.dpreview.com/galleries/reviewsamples/photos/111103/sample-7 - * ?inalbum=canon-eos-5d-mark-ii-review-samples - */ - // generateComparisonsForImage("bin/L-huge-flower.jpg"); - - long totalRunTime = System.currentTimeMillis() - totalTimeStart; - System.out.println("\n\nGenerated " + (SIZES.length * 3 * genCount) - + " images in " + (System.currentTimeMillis() - totalTimeStart) - + " ms (" + ((double) totalRunTime / (double) 1000) - + " seconds)"); - genCount = 0; - } - - public void generateComparisonsForImage(String filename) throws IOException { - generateComparisonForMethod(filename, Method.SPEED); - generateComparisonForMethod(filename, Method.BALANCED); - generateComparisonForMethod(filename, Method.QUALITY); - genCount++; - } - - public void generateComparisonForMethod(String filename, Method method) - throws IOException { - for (int size : SIZES) { - File file = new File(filename); - String name = file.getName().substring(0, - file.getName().lastIndexOf('.')); - String extension = file.getName().substring( - file.getName().lastIndexOf('.') + 1, - file.getName().length()); - - File outputdir = new File("generated-comparisons"); - - if (!outputdir.exists()) { - outputdir.mkdir(); - } - - // We do this so the files list alphabetically - String methodName = "UNKNOWN"; - - switch (method) { - case SPEED: - methodName = "a-SPEED"; - break; - case BALANCED: - methodName = "b-BALANCED"; - break; - case QUALITY: - methodName = "c-QUALITY"; - break; - } - - File newFile = new File(outputdir, name + "-" + size + "-" - + methodName + "." + extension); - ImageIO.write(Scalr.resize(ImageIO.read(file), method, size, size), - extension, newFile); - System.out.println("Generated: " + newFile.getAbsolutePath()); - } - } -} \ No newline at end of file diff --git a/src/test/java/com/thebuzzmedia/imgscalr/ScalrTest.java b/src/test/java/com/thebuzzmedia/imgscalr/ScalrTest.java deleted file mode 100644 index 7ea0a4f..0000000 --- a/src/test/java/com/thebuzzmedia/imgscalr/ScalrTest.java +++ /dev/null @@ -1,330 +0,0 @@ -/** - * Copyright 2010 The Buzz Media, LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.thebuzzmedia.imgscalr; - -import static org.junit.Assert.*; - -import java.awt.image.BufferedImage; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.thebuzzmedia.imgscalr.Scalr.Method; - -public class ScalrTest extends AbstractTest { - private static boolean SHOW_OUTPUT = true; - - private static int LANDSCAPE_IMAGE_WIDTH = 800; - private static int LANDSCAPE_IMAGE_HEIGHT = 600; - private static int LANDSCAPE_IMAGE_TYPE = BufferedImage.TYPE_INT_RGB; - - private static int PORTRAIT_IMAGE_WIDTH = LANDSCAPE_IMAGE_HEIGHT; - private static int PORTRAIT_IMAGE_HEIGHT = LANDSCAPE_IMAGE_WIDTH; - private static int PORTRAIT_IMAGE_TYPE = BufferedImage.TYPE_INT_ARGB; - - private static int LANDSCAPE_TARGET_WIDTH = 320; - private static int LANDSCAPE_TARGET_HEIGHT = 240; - - private static int PORTRAIT_TARGET_WIDTH = LANDSCAPE_TARGET_HEIGHT; - private static int PORTRAIT_TARGET_HEIGHT = LANDSCAPE_TARGET_WIDTH; - - private BufferedImage landscapeImage; - private BufferedImage portraitImage; - - @Before - public void setup() { - landscapeImage = new BufferedImage(LANDSCAPE_IMAGE_WIDTH, - LANDSCAPE_IMAGE_HEIGHT, LANDSCAPE_IMAGE_TYPE); - portraitImage = new BufferedImage(PORTRAIT_IMAGE_WIDTH, - PORTRAIT_IMAGE_HEIGHT, PORTRAIT_IMAGE_TYPE); - } - - @After - public void after() { - landscapeImage.flush(); - portraitImage.flush(); - } - - /* - * ======================================================================== - * METHOD TESTS - * ======================================================================== - */ - - /** - * Used to test the {@link Scalr#resize(java.awt.image.BufferedImage, int)} - * method. - */ - @Test - public void testResizeBILandscape() { - BufferedImage result = Scalr.resize(landscapeImage, - LANDSCAPE_TARGET_WIDTH); - - if (SHOW_OUTPUT) - System.out.println("testResizeBILandscape: " + result.getWidth() - + "x" + result.getHeight() + " Type: " + result.getType()); - - assertNotNull(result); - assertEquals(LANDSCAPE_IMAGE_TYPE, result.getType()); - assertEquals(LANDSCAPE_TARGET_WIDTH, result.getWidth()); - assertEquals(LANDSCAPE_TARGET_HEIGHT, result.getHeight()); - } - - /** - * Used to test the {@link Scalr#resize(java.awt.image.BufferedImage, int)} - * method. - */ - @Test - public void testResizeBIPortrait() { - BufferedImage result = Scalr.resize(portraitImage, - PORTRAIT_TARGET_HEIGHT); - - if (SHOW_OUTPUT) - System.out.println("testResizeBIPortrait: " + result.getWidth() - + "x" + result.getHeight() + " Type: " + result.getType()); - - assertNotNull(result); - assertEquals(PORTRAIT_IMAGE_TYPE, result.getType()); - assertEquals(PORTRAIT_TARGET_WIDTH, result.getWidth()); - assertEquals(PORTRAIT_TARGET_HEIGHT, result.getHeight()); - } - - /** - * Used to test the - * {@link Scalr#resize(java.awt.image.BufferedImage, int, int)} method. - */ - @Test - public void testResizeBIILandscape() { - BufferedImage result = Scalr.resize(landscapeImage, - LANDSCAPE_TARGET_WIDTH, LANDSCAPE_TARGET_HEIGHT); - - if (SHOW_OUTPUT) - System.out.println("testResizeBIILandscape: " + result.getWidth() - + "x" + result.getHeight() + " Type: " + result.getType()); - - assertNotNull(result); - assertEquals(LANDSCAPE_IMAGE_TYPE, result.getType()); - assertEquals(LANDSCAPE_TARGET_WIDTH, result.getWidth()); - assertEquals(LANDSCAPE_TARGET_HEIGHT, result.getHeight()); - } - - /** - * Used to test the - * {@link Scalr#resize(java.awt.image.BufferedImage, int, int)} method. - */ - @Test - public void testResizeBIIPortrait() { - BufferedImage result = Scalr.resize(portraitImage, - PORTRAIT_TARGET_WIDTH, PORTRAIT_TARGET_HEIGHT); - - if (SHOW_OUTPUT) - System.out.println("testResizeBIIPortrait: " + result.getWidth() - + "x" + result.getHeight() + " Type: " + result.getType()); - - assertNotNull(result); - assertEquals(PORTRAIT_IMAGE_TYPE, result.getType()); - assertEquals(PORTRAIT_TARGET_WIDTH, result.getWidth()); - assertEquals(PORTRAIT_TARGET_HEIGHT, result.getHeight()); - } - - /** - * Used to test the - * {@link Scalr#resize(java.awt.image.BufferedImage, com.thebuzzmedia.imgscalr.Scalr.Method, int)} - * method. - */ - @Test - public void testResizeBMI() { - BufferedImage result = Scalr.resize(portraitImage, Method.SPEED, - PORTRAIT_TARGET_HEIGHT); - - if (SHOW_OUTPUT) - System.out.println("testResizeBMI: " + result.getWidth() + "x" - + result.getHeight() + " Type: " + result.getType()); - - assertNotNull(result); - assertEquals(PORTRAIT_IMAGE_TYPE, result.getType()); - assertEquals(PORTRAIT_TARGET_WIDTH, result.getWidth()); - assertEquals(PORTRAIT_TARGET_HEIGHT, result.getHeight()); - } - - /** - * Used to test the - * {@link Scalr#resize(java.awt.image.BufferedImage, com.thebuzzmedia.imgscalr.Scalr.Method, int, int)} - * method. - */ - @Test - public void testResizeBMII() { - BufferedImage result = Scalr.resize(portraitImage, Method.SPEED, - PORTRAIT_TARGET_WIDTH, PORTRAIT_TARGET_HEIGHT); - - if (SHOW_OUTPUT) - System.out.println("testResizeBMII: " + result.getWidth() + "x" - + result.getHeight() + " Type: " + result.getType()); - - assertNotNull(result); - assertEquals(PORTRAIT_IMAGE_TYPE, result.getType()); - assertEquals(PORTRAIT_TARGET_WIDTH, result.getWidth()); - assertEquals(PORTRAIT_TARGET_HEIGHT, result.getHeight()); - } - - /* - * ======================================================================== - * COMMON SENSE TESTS - * ======================================================================== - */ - - /** - * "Common Sense" Test: Resize a landscape image (800x600) to 200x200. The - * primary dimension is width because this is a landscape image; height - * should be ignored. - * - * Expected Result: An image sized 200x150 - */ - @Test - public void testLandscapeResizeProportional() { - BufferedImage result = Scalr.resize(landscapeImage, 200); - - if (SHOW_OUTPUT) - System.out.println("testLandscapeResizeProportional: " - + result.getWidth() + "x" + result.getHeight()); - - assertNotNull(result); - assertEquals(200, result.getWidth()); - assertEquals(150, result.getHeight()); - } - - /** - * "Common Sense" Test: Resize a landscape image (800x600) to 200x10. The - * primary dimension is width because this is a landscape image; height - * should be ignored. - * - * Expected Result: An image sized 200x150 - */ - @Test - public void testLandscapeResizeUnproportional() { - BufferedImage result = Scalr.resize(landscapeImage, 200, 10); - - if (SHOW_OUTPUT) - System.out.println("testLandscapeResizeUnproportional: " - + result.getWidth() + "x" + result.getHeight()); - - assertNotNull(result); - assertEquals(200, result.getWidth()); - assertEquals(150, result.getHeight()); - } - - /** - * "Common Sense" Test: Resize a portrait image (600x800) to 200x200. The - * primary dimension is height because this is a portrait image; width - * should be ignored. - * - * Expected Result: An image sized 150x200 - */ - @Test - public void testPortraitResizeProportional() { - BufferedImage result = Scalr.resize(portraitImage, 200); - - if (SHOW_OUTPUT) - System.out.println("testPortraitResizeProportional: " - + result.getWidth() + "x" + result.getHeight()); - - assertNotNull(result); - assertEquals(150, result.getWidth()); - assertEquals(200, result.getHeight()); - } - - /** - * "Common Sense" Test: Resize a portrait image (600x800) to 10x200. The - * primary dimension is height because this is a portrait image; width - * should be ignored. - * - * Expected Result: An image sized 150x200 - */ - @Test - public void testPortraitResizeUnproportional() { - BufferedImage result = Scalr.resize(portraitImage, 10, 200); - - if (SHOW_OUTPUT) - System.out.println("testPortraitResizeUnproportional: " - + result.getWidth() + "x" + result.getHeight()); - - assertNotNull(result); - assertEquals(150, result.getWidth()); - assertEquals(200, result.getHeight()); - } - - /** - * Resize a portrait (600x800) down to a super-tiny size that would require - * a sub-pixel result (600 down to 7.5), ensure that the fractional pixel - * value is cropped and not scaled up. - */ - @Test - public void testPortraitResizeUnproportionalTiny() { - BufferedImage result = Scalr.resize(portraitImage, 10); - - if (SHOW_OUTPUT) - System.out.println("testPortraitResizeUnproportional2: " - + result.getWidth() + "x" + result.getHeight()); - - assertNotNull(result); - assertEquals(8, result.getWidth()); - assertEquals(10, result.getHeight()); - } - - @Test - public void testModeAuto() { - BufferedImage result = Scalr.resize(landscapeImage, - Scalr.Mode.AUTOMATIC, LANDSCAPE_TARGET_WIDTH, - LANDSCAPE_TARGET_HEIGHT); - - if (SHOW_OUTPUT) - System.out.println("testModeAuto: " + result.getWidth() + "x" - + result.getHeight()); - - assertNotNull(result); - assertEquals(LANDSCAPE_TARGET_WIDTH, result.getWidth()); - assertEquals(LANDSCAPE_TARGET_HEIGHT, result.getHeight()); - } - - @Test - public void testModeHeight() { - BufferedImage result = Scalr.resize(landscapeImage, - Scalr.Mode.FIT_TO_HEIGHT, LANDSCAPE_TARGET_WIDTH); - - if (SHOW_OUTPUT) - System.out.println("testModeHeight: " + result.getWidth() + "x" - + result.getHeight()); - - assertNotNull(result); - assertEquals(427, result.getWidth()); - assertEquals(LANDSCAPE_TARGET_WIDTH, result.getHeight()); - } - - @Test - public void testModeWidth() { - BufferedImage result = Scalr.resize(portraitImage, - Scalr.Mode.FIT_TO_WIDTH, PORTRAIT_TARGET_HEIGHT); - - if (SHOW_OUTPUT) - System.out.println("testModeWidth: " + result.getWidth() + "x" - + result.getHeight()); - - assertNotNull(result); - assertEquals(PORTRAIT_TARGET_HEIGHT, result.getWidth()); - assertEquals(427, result.getHeight()); - } -} \ No newline at end of file diff --git a/src/test/resources/L-screenshot.png b/src/test/resources/L-screenshot.png deleted file mode 100644 index 11aff4b..0000000 Binary files a/src/test/resources/L-screenshot.png and /dev/null differ diff --git a/src/test/resources/L-time-square.jpg b/src/test/resources/L-time-square.jpg deleted file mode 100644 index 772c675..0000000 Binary files a/src/test/resources/L-time-square.jpg and /dev/null differ diff --git a/src/test/resources/P-bicycle-race.jpg b/src/test/resources/P-bicycle-race.jpg deleted file mode 100644 index a1e712d..0000000 Binary files a/src/test/resources/P-bicycle-race.jpg and /dev/null differ