Skip to content

Commit

Permalink
4.4.0 (#207)
Browse files Browse the repository at this point in the history
4.4.0: added #205 ability to change rectangle color.

Co-authored-by: Aaron's Sandbox <woosyume@gmail.com>
  • Loading branch information
romankh3 and woosyume authored Mar 28, 2021
1 parent 1d87642 commit 188adc0
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 7 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -69,12 +72,12 @@ Can be found in [RELEASE_NOTES](RELEASE_NOTES.md).
<dependency>
<groupId>com.github.romankh3</groupId>
<artifactId>image-comparison</artifactId>
<version>4.3.1</version>
<version>4.4.0</version>
</dependency>
```
#### 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
Expand Down
3 changes: 3 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -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.

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.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
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.3.1</version>
<version>4.4.0</version>
<packaging>jar</packaging>

<name>Image Comparison</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -392,7 +402,7 @@ private BufferedImage drawRectangles(List<Rectangle> rectangles) {
*/
private void drawExcludedRectangles(Graphics2D graphics) {
if (drawExcludedRectangles) {
graphics.setColor(Color.GREEN);
graphics.setColor(this.excludedRectangleColor);
draw(graphics, excludedAreas.getExcluded());

if (fillExcludedRectangles) {
Expand All @@ -409,7 +419,7 @@ private void drawExcludedRectangles(Graphics2D graphics) {
*/
private void drawRectanglesOfDifferences(List<Rectangle> rectangles, Graphics2D graphics) {
List<Rectangle> rectanglesForDraw;
graphics.setColor(Color.RED);
graphics.setColor(this.differenceRectangleColor);

if (maximalRectangleCount > 0 && maximalRectangleCount < rectangles.size()) {
rectanglesForDraw = rectangles.stream()
Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()));
Expand All @@ -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")
Expand Down

0 comments on commit 188adc0

Please sign in to comment.