Skip to content

Commit

Permalink
Bild Vergleich Implementiert
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanPenndorf committed Oct 12, 2013
1 parent a890f8d commit 29da93a
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
23 changes: 22 additions & 1 deletion test/net/cyphoria/weddingapp/imagecompare/ImageComparator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
*
Expand Down Expand Up @@ -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)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

}

Expand Down
Loading
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.