Skip to content

Commit 188adc0

Browse files
romankh3woosyume
andauthored
4.4.0 (#207)
4.4.0: added #205 ability to change rectangle color. Co-authored-by: Aaron's Sandbox <woosyume@gmail.com>
1 parent 1d87642 commit 188adc0

File tree

6 files changed

+47
-7
lines changed

6 files changed

+47
-7
lines changed

README.md

+5-2
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ All these configurations can be updated based on your needs.
5757
| `fillDifferenceRectangles` | Flag which says fill difference rectangles or not. |
5858
| `percentOpacityDifferenceRectangles` | The desired opacity of the difference rectangle fill. |
5959
| `allowingPercentOfDifferentPixels` | The percent of the allowing pixels to be different to stay MATCH for comparison. E.g. percent of the pixels, which would ignore in comparison. Value can be from 0.0 to 100.00 |
60+
| `differenceRectangleColor` | Rectangle color of image difference. By default, it's red. |
61+
| `excludedRectangleColor` | Rectangle color of excluded part. By default, it's green. |
62+
6063

6164
## Release Notes
6265

@@ -69,12 +72,12 @@ Can be found in [RELEASE_NOTES](RELEASE_NOTES.md).
6972
<dependency>
7073
<groupId>com.github.romankh3</groupId>
7174
<artifactId>image-comparison</artifactId>
72-
<version>4.3.1</version>
75+
<version>4.4.0</version>
7376
</dependency>
7477
```
7578
#### Gradle
7679
```groovy
77-
compile 'com.github.romankh3:image-comparison:4.3.1'
80+
compile 'com.github.romankh3:image-comparison:4.4.0'
7881
```
7982

8083
#### To compare two images programmatically

RELEASE_NOTES.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Release Notes
22

3+
## 4.4.0
4+
* added #205 ability to change rectangle color.
5+
36
## 4.3.1
47
* Fixed bug #201 - problem with comparing totally different pictures.
58

build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ plugins {
88
}
99

1010
group 'com.github.romankh3'
11-
version '4.3.1'
11+
version '4.4.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

+1-1
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.3.1</version>
9+
<version>4.4.0</version>
1010
<packaging>jar</packaging>
1111

1212
<name>Image Comparison</name>

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

+30-2
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,16 @@ public class ImageComparison {
138138
*/
139139
private double allowingPercentOfDifferentPixels = 0.0;
140140

141+
/**
142+
* Sets rectangle color of image difference. By default, it's red.
143+
*/
144+
private Color differenceRectangleColor = Color.RED;
145+
146+
/**
147+
* Sets rectangle color of excluded part. By default, it's green.
148+
*/
149+
private Color excludedRectangleColor = Color.GREEN;
150+
141151
/**
142152
* Create a new instance of {@link ImageComparison} that can compare the given images.
143153
*
@@ -392,7 +402,7 @@ private BufferedImage drawRectangles(List<Rectangle> rectangles) {
392402
*/
393403
private void drawExcludedRectangles(Graphics2D graphics) {
394404
if (drawExcludedRectangles) {
395-
graphics.setColor(Color.GREEN);
405+
graphics.setColor(this.excludedRectangleColor);
396406
draw(graphics, excludedAreas.getExcluded());
397407

398408
if (fillExcludedRectangles) {
@@ -409,7 +419,7 @@ private void drawExcludedRectangles(Graphics2D graphics) {
409419
*/
410420
private void drawRectanglesOfDifferences(List<Rectangle> rectangles, Graphics2D graphics) {
411421
List<Rectangle> rectanglesForDraw;
412-
graphics.setColor(Color.RED);
422+
graphics.setColor(this.differenceRectangleColor);
413423

414424
if (maximalRectangleCount > 0 && maximalRectangleCount < rectangles.size()) {
415425
rectanglesForDraw = rectangles.stream()
@@ -677,4 +687,22 @@ public ImageComparison setAllowingPercentOfDifferentPixels(double allowingPercen
677687

678688
return this;
679689
}
690+
691+
public Color getDifferenceRectangleColor() {
692+
return this.differenceRectangleColor;
693+
}
694+
695+
public ImageComparison setDifferenceRectangleColor(Color differenceRectangleColor) {
696+
this.differenceRectangleColor = differenceRectangleColor;
697+
return this;
698+
}
699+
700+
public Color getExcludedRectangleColor() {
701+
return this.excludedRectangleColor;
702+
}
703+
704+
public ImageComparison setExcludedRectangleColor(Color excludedRectangleColor) {
705+
this.excludedRectangleColor = excludedRectangleColor;
706+
return this;
707+
}
680708
}

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

+7-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
import com.github.romankh3.image.comparison.model.ImageComparisonResult;
1515
import com.github.romankh3.image.comparison.model.Rectangle;
16+
import java.awt.Color;
1617
import java.awt.image.BufferedImage;
1718
import java.io.File;
1819
import java.util.ArrayList;
@@ -464,7 +465,9 @@ public void shouldProperlyWorkGettersAndSetters() {
464465
.setThreshold(400)
465466
.setDifferenceRectangleFilling(true, 35.1)
466467
.setExcludedRectangleFilling(true, 45.1)
467-
.setAllowingPercentOfDifferentPixels(48.15);
468+
.setAllowingPercentOfDifferentPixels(48.15)
469+
.setDifferenceRectangleColor(Color.BLACK)
470+
.setExcludedRectangleColor(Color.BLUE);
468471

469472
//then
470473
assertEquals(String.valueOf(100), String.valueOf(imageComparison.getMinimalRectangleSize()));
@@ -478,6 +481,9 @@ public void shouldProperlyWorkGettersAndSetters() {
478481
assertTrue(imageComparison.isFillDifferenceRectangles());
479482
assertTrue(imageComparison.isFillExcludedRectangles());
480483
assertEquals(48.15, imageComparison.getAllowingPercentOfDifferentPixels(), 0.0);
484+
assertEquals(Color.BLACK, imageComparison.getDifferenceRectangleColor());
485+
assertEquals(Color.BLUE, imageComparison.getExcludedRectangleColor());
486+
481487
}
482488

483489
@DisplayName("Should properly compare in JPEG extension")

0 commit comments

Comments
 (0)