Permalink
Browse files

Bild Vergleich Implementiert

  • Loading branch information...
1 parent a890f8d commit 29da93a3ea3a5232eb6317f401c466865cc964e9 @KyleRogers committed Oct 12, 2013
@@ -5,6 +5,7 @@ import org.scalatest.matchers.{MatchResult, Matcher}
import org.springframework.core.io.Resource
import javax.imageio.ImageIO
import org.specs2.matcher.Expectable
+import java.util
/**
*
@@ -64,8 +65,28 @@ package specs2 {
object ImageComparator {
+ def haveSameSize(i1: BufferedImage, i2: BufferedImage): Boolean = {
+ i1.getWidth == i2.getWidth && i1.getHeight == i2.getHeight
+ }
+
+ def haveSameContent(i1: BufferedImage, i2: BufferedImage): Boolean = {
+ val pixel1 = new Array[Int](32*32)
+ val pixel2 = new Array[Int](32*32)
+ var areEqual = true
+
+ for(y <- Array.range(0, i1.getHeight - 31, 32)) {
+ for(x <- Array.range(0, i1.getWidth - 31, 32)) {
+ i1.getRGB(x, y, 32, 32, pixel1, 0, 32)
+ i2.getRGB(x, y, 32, 32, pixel2, 0, 32)
+ areEqual &= util.Arrays.equals(pixel1, pixel2)
+ }
+ }
+
+ areEqual
+ }
+
def imagesAreEqual(referenceImage: BufferedImage, actualImage: BufferedImage): Boolean = {
- false
+ haveSameSize(referenceImage, actualImage) && haveSameContent(referenceImage, actualImage)
}
}
@@ -12,13 +12,29 @@ import java.awt.image.BufferedImage
class ImageComparatorTest extends Specification with ImageCompareMatchers {
val bild1: BufferedImage = new ClassPathResource("images/mara_und_lukas.jpg")
+ val bild1_mit_kleinem_Fehler: BufferedImage = new ClassPathResource("images/mara_und_lukas_mit_kleinem_Fehler.jpg")
val bild2: BufferedImage = new ClassPathResource("images/blumen.png")
"ImageComparator" should {
"das identische Bild als identisch erkennen" in {
bild1 must beSameImageAs (bild1)
}
+ "komplett unterschiedliche Bilder als unterschiedlich erkennen" in {
+ bild1 must not (beSameImageAs (bild2))
+ }
+
+ "komplett unterschiedliche Bilder als unterschiedlich erkennen (Symmetrie)" in {
+ bild2 must not (beSameImageAs (bild1))
+ }
+
+ "kaum unterschiedliche Bilder als unterschiedlich erkennen" in {
+ bild1 must not (beSameImageAs (bild1_mit_kleinem_Fehler))
+ }
+
+ "kaum unterschiedliche Bilder als unterschiedlich erkennen (Symmetrie)" in {
+ bild1_mit_kleinem_Fehler must not (beSameImageAs (bild1))
+ }
}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 29da93a

Please sign in to comment.