Skip to content

Commit e494e45

Browse files
romankh3AnthonyJungmannakondas
authored
Development (#185)
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 <AnthonyJungmann@users.noreply.github.com> Co-authored-by: Arkadiusz Kondas <arkadiusz.kondas@gmail.com>
1 parent 3a40703 commit e494e45

15 files changed

Lines changed: 259 additions & 177 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,12 @@ Can be found in [RELEASE_NOTES](RELEASE_NOTES.md).
6868
<dependency>
6969
<groupId>com.github.romankh3</groupId>
7070
<artifactId>image-comparison</artifactId>
71-
<version>4.2.1</version>
71+
<version>4.3.0</version>
7272
</dependency>
7373
```
7474
#### Gradle
7575
```groovy
76-
compile 'com.github.romankh3:image-comparison:4.2.1'
76+
compile 'com.github.romankh3:image-comparison:4.3.0'
7777
```
7878

7979
#### To compare two images programmatically

RELEASE_NOTES.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Release Notes
22

3+
## 4.3.0
4+
* Include rectangles in ImageComparisonResult.
5+
* The resolved bug with 0.0 in differencePercent
6+
* improved and added missing tests.
7+
38
## 4.2.1
49
* Fixed bug #180 - problem with ImageComparisonUtil.readFromResources method.
510

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ plugins {
88
}
99

1010
group 'com.github.romankh3'
11-
version '4.2.1'
11+
version '4.3.0'
1212
description 'Library that compares 2 images with the same sizes and shows the differences visually by drawing rectangles. ' +
1313
'Some parts of the image can be excluded from the comparison. Can be used for automation qa tests.'
1414
sourceCompatibility = 1.8

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>com.github.romankh3</groupId>
88
<artifactId>image-comparison</artifactId>
9-
<version>4.2.1</version>
9+
<version>4.3.0</version>
1010
<packaging>jar</packaging>
1111

1212
<name>Image Comparison</name>

src/main/java/com/github/romankh3/image/comparison/ImageComparison.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import java.util.*;
1313
import java.util.stream.Collectors;
1414

15+
import static com.github.romankh3.image.comparison.ImageComparisonUtil.getDifferencePercent;
1516
import static java.util.Collections.emptyList;
1617

1718
/**
@@ -183,8 +184,7 @@ public ImageComparisonResult compareImages() {
183184
// check that the images have the same size
184185
if (isImageSizesNotEqual(expected, actual)) {
185186
BufferedImage actualResized = ImageComparisonUtil.resize(actual, expected.getWidth(), expected.getHeight());
186-
differencePercent = ImageComparisonUtil.getDifferencePercent(actualResized, expected);
187-
return ImageComparisonResult.defaultSizeMisMatchResult(expected, actual, differencePercent);
187+
return ImageComparisonResult.defaultSizeMisMatchResult(expected, actual, getDifferencePercent(actualResized, expected));
188188
}
189189

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

201201
BufferedImage resultImage = drawRectangles(rectangles);
202202
saveImageForDestination(resultImage);
203-
return ImageComparisonResult.defaultMisMatchResult(expected, actual).setResult(resultImage);
203+
return ImageComparisonResult.defaultMisMatchResult(expected, actual, getDifferencePercent(actual, expected))
204+
.setResult(resultImage)
205+
.setRectangles(rectangles);
204206
}
205207

206208
/**
@@ -664,7 +666,7 @@ public double getAllowingPercentOfDifferentPixels() {
664666
}
665667

666668
public ImageComparison setAllowingPercentOfDifferentPixels(double allowingPercentOfDifferentPixels) {
667-
if(0.0 <= allowingPercentOfDifferentPixels && allowingPercentOfDifferentPixels <= 100) {
669+
if (0.0 <= allowingPercentOfDifferentPixels && allowingPercentOfDifferentPixels <= 100) {
668670
this.allowingPercentOfDifferentPixels = allowingPercentOfDifferentPixels;
669671
} else {
670672
//todo add warning here

src/main/java/com/github/romankh3/image/comparison/model/ImageComparisonResult.java

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package com.github.romankh3.image.comparison.model;
22

33
import com.github.romankh3.image.comparison.ImageComparisonUtil;
4+
45
import java.awt.image.BufferedImage;
56
import java.io.File;
7+
import java.util.List;
68

79
/**
810
* Data transfer objects which contains all the needed data for result of the comparison.
@@ -28,21 +30,27 @@ public class ImageComparisonResult {
2830
* State of the comparison.
2931
*/
3032
private ImageComparisonState imageComparisonState;
33+
3134
/**
3235
* The difference percentage between two images.
3336
*/
3437
private float differencePercent;
3538

39+
/**
40+
* Rectangles of the differences
41+
*/
42+
private List<Rectangle> rectangles;
43+
3644
/**
3745
* Create default instance of the {@link ImageComparisonResult} with {@link ImageComparisonState#SIZE_MISMATCH}.
3846
*
39-
* @param expected expected {@link BufferedImage} object.
40-
* @param actual actual {@link BufferedImage} object.
47+
* @param expected expected {@link BufferedImage} object.
48+
* @param actual actual {@link BufferedImage} object.
4149
* @param differencePercent the percent of the differences between images.
4250
* @return instance of the {@link ImageComparisonResult} object.
4351
*/
4452
public static ImageComparisonResult defaultSizeMisMatchResult(BufferedImage expected, BufferedImage actual,
45-
float differencePercent) {
53+
float differencePercent) {
4654
return new ImageComparisonResult()
4755
.setImageComparisonState(ImageComparisonState.SIZE_MISMATCH)
4856
.setDifferencePercent(differencePercent)
@@ -55,12 +63,14 @@ public static ImageComparisonResult defaultSizeMisMatchResult(BufferedImage expe
5563
* Create default instance of the {@link ImageComparisonResult} with {@link ImageComparisonState#MISMATCH}.
5664
*
5765
* @param expected expected {@link BufferedImage} object.
58-
* @param actual actual {@link BufferedImage} object.
66+
* @param actual actual {@link BufferedImage} object.
67+
* @param differencePercent the persent of the differences between images.
5968
* @return instance of the {@link ImageComparisonResult} object.
6069
*/
61-
public static ImageComparisonResult defaultMisMatchResult(BufferedImage expected, BufferedImage actual) {
70+
public static ImageComparisonResult defaultMisMatchResult(BufferedImage expected, BufferedImage actual, float differencePercent) {
6271
return new ImageComparisonResult()
6372
.setImageComparisonState(ImageComparisonState.MISMATCH)
73+
.setDifferencePercent(differencePercent)
6474
.setExpected(expected)
6575
.setActual(actual)
6676
.setResult(actual);
@@ -70,7 +80,7 @@ public static ImageComparisonResult defaultMisMatchResult(BufferedImage expected
7080
* Create default instance of the {@link ImageComparisonResult} with {@link ImageComparisonState#MATCH}.
7181
*
7282
* @param expected expected {@link BufferedImage} object.
73-
* @param actual actual {@link BufferedImage} object.
83+
* @param actual actual {@link BufferedImage} object.
7484
* @return instance of the {@link ImageComparisonResult} object.
7585
*/
7686
public static ImageComparisonResult defaultMatchResult(BufferedImage expected, BufferedImage actual) {
@@ -137,5 +147,12 @@ ImageComparisonResult setDifferencePercent(float differencePercent) {
137147
return this;
138148
}
139149

150+
public List<Rectangle> getRectangles() {
151+
return rectangles;
152+
}
140153

154+
public ImageComparisonResult setRectangles(List<Rectangle> rectangles) {
155+
this.rectangles = rectangles;
156+
return this;
157+
}
141158
}

src/test/java/com/github/romankh3/image/comparison/BaseTest.java

Lines changed: 0 additions & 28 deletions
This file was deleted.

0 commit comments

Comments
 (0)