forked from rkalla/imgscalr
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Riyad Kalla
committed
Nov 10, 2011
1 parent
a41dadd
commit 1f5a126
Showing
8 changed files
with
146 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package org.imgscalr; | ||
|
||
import java.awt.image.BufferedImage; | ||
import java.io.FileOutputStream; | ||
import java.io.IOException; | ||
|
||
import javax.imageio.ImageIO; | ||
|
||
import org.junit.AfterClass; | ||
import org.junit.Assert; | ||
import org.junit.BeforeClass; | ||
|
||
public abstract class AbstractScalrTest { | ||
protected static BufferedImage src; | ||
|
||
@BeforeClass | ||
public static void setup() throws IOException { | ||
src = load("time-square.png"); | ||
} | ||
|
||
@AfterClass | ||
public static void tearDown() { | ||
src.flush(); | ||
} | ||
|
||
protected static BufferedImage load(String name) { | ||
BufferedImage i = null; | ||
|
||
try { | ||
i = ImageIO.read(AbstractScalrTest.class.getResource(name)); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
return i; | ||
} | ||
|
||
protected static void save(BufferedImage image, String name) { | ||
try { | ||
ImageIO.write(image, "PNG", new FileOutputStream(name)); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
protected static void assertEquals(BufferedImage orig, BufferedImage tmp) | ||
throws AssertionError { | ||
// Ensure neither image is null. | ||
Assert.assertNotNull(orig); | ||
Assert.assertNotNull(tmp); | ||
|
||
// Ensure dimensions are equal. | ||
Assert.assertEquals(orig.getWidth(), tmp.getWidth()); | ||
Assert.assertEquals(orig.getHeight(), tmp.getHeight()); | ||
|
||
int w = orig.getWidth(); | ||
int h = orig.getHeight(); | ||
|
||
// Ensure every pixel RGB is the same. | ||
for (int i = 0; i < w; i++) { | ||
for (int j = 0; j < h; j++) { | ||
Assert.assertEquals(orig.getRGB(i, j), tmp.getRGB(i, j)); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package org.imgscalr; | ||
|
||
import static org.imgscalr.Scalr.OP_ANTIALIAS; | ||
import static org.imgscalr.Scalr.OP_BRIGHTER; | ||
import static org.imgscalr.Scalr.OP_DARKER; | ||
import static org.imgscalr.Scalr.OP_GRAYSCALE; | ||
import static org.imgscalr.Scalr.apply; | ||
|
||
import java.awt.image.BufferedImageOp; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
public class ScalrApplyTest extends AbstractScalrTest { | ||
@Test | ||
public void testApplyEX() { | ||
try { | ||
apply(src, (BufferedImageOp[]) null); | ||
Assert.assertTrue(false); | ||
} catch (Exception e) { | ||
Assert.assertTrue(true); | ||
} | ||
} | ||
|
||
@Test | ||
public void testApply1() { | ||
assertEquals(load("time-square-apply-1.png"), apply(src, OP_ANTIALIAS)); | ||
} | ||
|
||
@Test | ||
public void testApply4() { | ||
assertEquals( | ||
load("time-square-apply-4.png"), | ||
apply(src, Scalr.OP_ANTIALIAS, OP_BRIGHTER, OP_DARKER, | ||
OP_GRAYSCALE)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package org.imgscalr; | ||
|
||
import static org.imgscalr.Scalr.crop; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
public class ScalrCropTest extends AbstractScalrTest { | ||
@Test | ||
public void testCropEX() { | ||
try { | ||
crop(src, 3200, 2400); | ||
Assert.assertTrue(false); | ||
} catch (Exception e) { | ||
Assert.assertTrue(true); | ||
} | ||
|
||
try { | ||
crop(src, -8, -10, 100, 100); | ||
Assert.assertTrue(false); | ||
} catch (Exception e) { | ||
Assert.assertTrue(true); | ||
} | ||
|
||
try { | ||
crop(src, -100, -200, -4, -4); | ||
Assert.assertTrue(false); | ||
} catch (Exception e) { | ||
Assert.assertTrue(true); | ||
} | ||
} | ||
|
||
@Test | ||
public void testCropWH() { | ||
assertEquals(load("time-square-crop-wh.png"), crop(src, 320, 240)); | ||
} | ||
|
||
@Test | ||
public void testCropXYWH() { | ||
assertEquals(load("time-square-crop-xywh.png"), | ||
crop(src, 100, 100, 320, 240)); | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.