Skip to content

Commit

Permalink
Development (#185)
Browse files Browse the repository at this point in the history
4.3.0

*   Include rectangles in ImageComparisonResult.
*   The resolved bug with 0.0 in differencePercent
*   improved and added missing tests.

Co-authored-by: Anthony Jungmann <[email protected]>
Co-authored-by: Arkadiusz Kondas <[email protected]>
  • Loading branch information
3 people authored Sep 8, 2020
1 parent 3a40703 commit e494e45
Show file tree
Hide file tree
Showing 15 changed files with 259 additions and 177 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ Can be found in [RELEASE_NOTES](RELEASE_NOTES.md).
<dependency>
<groupId>com.github.romankh3</groupId>
<artifactId>image-comparison</artifactId>
<version>4.2.1</version>
<version>4.3.0</version>
</dependency>
```
#### Gradle
```groovy
compile 'com.github.romankh3:image-comparison:4.2.1'
compile 'com.github.romankh3:image-comparison:4.3.0'
```

#### To compare two images programmatically
Expand Down
5 changes: 5 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Release Notes

## 4.3.0
* Include rectangles in ImageComparisonResult.
* The resolved bug with 0.0 in differencePercent
* improved and added missing tests.

## 4.2.1
* Fixed bug #180 - problem with ImageComparisonUtil.readFromResources method.

Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ plugins {
}

group 'com.github.romankh3'
version '4.2.1'
version '4.3.0'
description 'Library that compares 2 images with the same sizes and shows the differences visually by drawing rectangles. ' +
'Some parts of the image can be excluded from the comparison. Can be used for automation qa tests.'
sourceCompatibility = 1.8
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.github.romankh3</groupId>
<artifactId>image-comparison</artifactId>
<version>4.2.1</version>
<version>4.3.0</version>
<packaging>jar</packaging>

<name>Image Comparison</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.util.*;
import java.util.stream.Collectors;

import static com.github.romankh3.image.comparison.ImageComparisonUtil.getDifferencePercent;
import static java.util.Collections.emptyList;

/**
Expand Down Expand Up @@ -183,8 +184,7 @@ public ImageComparisonResult compareImages() {
// check that the images have the same size
if (isImageSizesNotEqual(expected, actual)) {
BufferedImage actualResized = ImageComparisonUtil.resize(actual, expected.getWidth(), expected.getHeight());
differencePercent = ImageComparisonUtil.getDifferencePercent(actualResized, expected);
return ImageComparisonResult.defaultSizeMisMatchResult(expected, actual, differencePercent);
return ImageComparisonResult.defaultSizeMisMatchResult(expected, actual, getDifferencePercent(actualResized, expected));
}

List<Rectangle> rectangles = populateRectangles();
Expand All @@ -200,7 +200,9 @@ public ImageComparisonResult compareImages() {

BufferedImage resultImage = drawRectangles(rectangles);
saveImageForDestination(resultImage);
return ImageComparisonResult.defaultMisMatchResult(expected, actual).setResult(resultImage);
return ImageComparisonResult.defaultMisMatchResult(expected, actual, getDifferencePercent(actual, expected))
.setResult(resultImage)
.setRectangles(rectangles);
}

/**
Expand Down Expand Up @@ -664,7 +666,7 @@ public double getAllowingPercentOfDifferentPixels() {
}

public ImageComparison setAllowingPercentOfDifferentPixels(double allowingPercentOfDifferentPixels) {
if(0.0 <= allowingPercentOfDifferentPixels && allowingPercentOfDifferentPixels <= 100) {
if (0.0 <= allowingPercentOfDifferentPixels && allowingPercentOfDifferentPixels <= 100) {
this.allowingPercentOfDifferentPixels = allowingPercentOfDifferentPixels;
} else {
//todo add warning here
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.github.romankh3.image.comparison.model;

import com.github.romankh3.image.comparison.ImageComparisonUtil;

import java.awt.image.BufferedImage;
import java.io.File;
import java.util.List;

/**
* Data transfer objects which contains all the needed data for result of the comparison.
Expand All @@ -28,21 +30,27 @@ public class ImageComparisonResult {
* State of the comparison.
*/
private ImageComparisonState imageComparisonState;

/**
* The difference percentage between two images.
*/
private float differencePercent;

/**
* Rectangles of the differences
*/
private List<Rectangle> rectangles;

/**
* Create default instance of the {@link ImageComparisonResult} with {@link ImageComparisonState#SIZE_MISMATCH}.
*
* @param expected expected {@link BufferedImage} object.
* @param actual actual {@link BufferedImage} object.
* @param expected expected {@link BufferedImage} object.
* @param actual actual {@link BufferedImage} object.
* @param differencePercent the percent of the differences between images.
* @return instance of the {@link ImageComparisonResult} object.
*/
public static ImageComparisonResult defaultSizeMisMatchResult(BufferedImage expected, BufferedImage actual,
float differencePercent) {
float differencePercent) {
return new ImageComparisonResult()
.setImageComparisonState(ImageComparisonState.SIZE_MISMATCH)
.setDifferencePercent(differencePercent)
Expand All @@ -55,12 +63,14 @@ public static ImageComparisonResult defaultSizeMisMatchResult(BufferedImage expe
* Create default instance of the {@link ImageComparisonResult} with {@link ImageComparisonState#MISMATCH}.
*
* @param expected expected {@link BufferedImage} object.
* @param actual actual {@link BufferedImage} object.
* @param actual actual {@link BufferedImage} object.
* @param differencePercent the persent of the differences between images.
* @return instance of the {@link ImageComparisonResult} object.
*/
public static ImageComparisonResult defaultMisMatchResult(BufferedImage expected, BufferedImage actual) {
public static ImageComparisonResult defaultMisMatchResult(BufferedImage expected, BufferedImage actual, float differencePercent) {
return new ImageComparisonResult()
.setImageComparisonState(ImageComparisonState.MISMATCH)
.setDifferencePercent(differencePercent)
.setExpected(expected)
.setActual(actual)
.setResult(actual);
Expand All @@ -70,7 +80,7 @@ public static ImageComparisonResult defaultMisMatchResult(BufferedImage expected
* Create default instance of the {@link ImageComparisonResult} with {@link ImageComparisonState#MATCH}.
*
* @param expected expected {@link BufferedImage} object.
* @param actual actual {@link BufferedImage} object.
* @param actual actual {@link BufferedImage} object.
* @return instance of the {@link ImageComparisonResult} object.
*/
public static ImageComparisonResult defaultMatchResult(BufferedImage expected, BufferedImage actual) {
Expand Down Expand Up @@ -137,5 +147,12 @@ ImageComparisonResult setDifferencePercent(float differencePercent) {
return this;
}

public List<Rectangle> getRectangles() {
return rectangles;
}

public ImageComparisonResult setRectangles(List<Rectangle> rectangles) {
this.rectangles = rectangles;
return this;
}
}
28 changes: 0 additions & 28 deletions src/test/java/com/github/romankh3/image/comparison/BaseTest.java

This file was deleted.

Loading

0 comments on commit e494e45

Please sign in to comment.