diff --git a/README.md b/README.md
index ae29971..9f63ae6 100644
--- a/README.md
+++ b/README.md
@@ -57,6 +57,9 @@ All these configurations can be updated based on your needs.
| `fillDifferenceRectangles` | Flag which says fill difference rectangles or not. |
| `percentOpacityDifferenceRectangles` | The desired opacity of the difference rectangle fill. |
| `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 |
+| `differenceRectangleColor` | Rectangle color of image difference. By default, it's red. |
+| `excludedRectangleColor` | Rectangle color of excluded part. By default, it's green. |
+
## Release Notes
@@ -69,12 +72,12 @@ Can be found in [RELEASE_NOTES](RELEASE_NOTES.md).
com.github.romankh3
image-comparison
- 4.3.1
+ 4.4.0
```
#### Gradle
```groovy
-compile 'com.github.romankh3:image-comparison:4.3.1'
+compile 'com.github.romankh3:image-comparison:4.4.0'
```
#### To compare two images programmatically
diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md
index 045b416..76a8d85 100644
--- a/RELEASE_NOTES.md
+++ b/RELEASE_NOTES.md
@@ -1,5 +1,8 @@
# Release Notes
+## 4.4.0
+* added #205 ability to change rectangle color.
+
## 4.3.1
* Fixed bug #201 - problem with comparing totally different pictures.
diff --git a/build.gradle b/build.gradle
index 9178e96..a49be28 100644
--- a/build.gradle
+++ b/build.gradle
@@ -8,7 +8,7 @@ plugins {
}
group 'com.github.romankh3'
-version '4.3.1'
+version '4.4.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
diff --git a/pom.xml b/pom.xml
index 429ddd6..bd4bd06 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
com.github.romankh3
image-comparison
- 4.3.1
+ 4.4.0
jar
Image Comparison
diff --git a/src/main/java/com/github/romankh3/image/comparison/ImageComparison.java b/src/main/java/com/github/romankh3/image/comparison/ImageComparison.java
index 6e1320e..728c6ef 100644
--- a/src/main/java/com/github/romankh3/image/comparison/ImageComparison.java
+++ b/src/main/java/com/github/romankh3/image/comparison/ImageComparison.java
@@ -138,6 +138,16 @@ public class ImageComparison {
*/
private double allowingPercentOfDifferentPixels = 0.0;
+ /**
+ * Sets rectangle color of image difference. By default, it's red.
+ */
+ private Color differenceRectangleColor = Color.RED;
+
+ /**
+ * Sets rectangle color of excluded part. By default, it's green.
+ */
+ private Color excludedRectangleColor = Color.GREEN;
+
/**
* Create a new instance of {@link ImageComparison} that can compare the given images.
*
@@ -392,7 +402,7 @@ private BufferedImage drawRectangles(List rectangles) {
*/
private void drawExcludedRectangles(Graphics2D graphics) {
if (drawExcludedRectangles) {
- graphics.setColor(Color.GREEN);
+ graphics.setColor(this.excludedRectangleColor);
draw(graphics, excludedAreas.getExcluded());
if (fillExcludedRectangles) {
@@ -409,7 +419,7 @@ private void drawExcludedRectangles(Graphics2D graphics) {
*/
private void drawRectanglesOfDifferences(List rectangles, Graphics2D graphics) {
List rectanglesForDraw;
- graphics.setColor(Color.RED);
+ graphics.setColor(this.differenceRectangleColor);
if (maximalRectangleCount > 0 && maximalRectangleCount < rectangles.size()) {
rectanglesForDraw = rectangles.stream()
@@ -677,4 +687,22 @@ public ImageComparison setAllowingPercentOfDifferentPixels(double allowingPercen
return this;
}
+
+ public Color getDifferenceRectangleColor() {
+ return this.differenceRectangleColor;
+ }
+
+ public ImageComparison setDifferenceRectangleColor(Color differenceRectangleColor) {
+ this.differenceRectangleColor = differenceRectangleColor;
+ return this;
+ }
+
+ public Color getExcludedRectangleColor() {
+ return this.excludedRectangleColor;
+ }
+
+ public ImageComparison setExcludedRectangleColor(Color excludedRectangleColor) {
+ this.excludedRectangleColor = excludedRectangleColor;
+ return this;
+ }
}
diff --git a/src/test/java/com/github/romankh3/image/comparison/ImageComparisonUnitTest.java b/src/test/java/com/github/romankh3/image/comparison/ImageComparisonUnitTest.java
index 44c73fe..9b02142 100644
--- a/src/test/java/com/github/romankh3/image/comparison/ImageComparisonUnitTest.java
+++ b/src/test/java/com/github/romankh3/image/comparison/ImageComparisonUnitTest.java
@@ -13,6 +13,7 @@
import com.github.romankh3.image.comparison.model.ImageComparisonResult;
import com.github.romankh3.image.comparison.model.Rectangle;
+import java.awt.Color;
import java.awt.image.BufferedImage;
import java.io.File;
import java.util.ArrayList;
@@ -464,7 +465,9 @@ public void shouldProperlyWorkGettersAndSetters() {
.setThreshold(400)
.setDifferenceRectangleFilling(true, 35.1)
.setExcludedRectangleFilling(true, 45.1)
- .setAllowingPercentOfDifferentPixels(48.15);
+ .setAllowingPercentOfDifferentPixels(48.15)
+ .setDifferenceRectangleColor(Color.BLACK)
+ .setExcludedRectangleColor(Color.BLUE);
//then
assertEquals(String.valueOf(100), String.valueOf(imageComparison.getMinimalRectangleSize()));
@@ -478,6 +481,9 @@ public void shouldProperlyWorkGettersAndSetters() {
assertTrue(imageComparison.isFillDifferenceRectangles());
assertTrue(imageComparison.isFillExcludedRectangles());
assertEquals(48.15, imageComparison.getAllowingPercentOfDifferentPixels(), 0.0);
+ assertEquals(Color.BLACK, imageComparison.getDifferenceRectangleColor());
+ assertEquals(Color.BLUE, imageComparison.getExcludedRectangleColor());
+
}
@DisplayName("Should properly compare in JPEG extension")