-
-
Notifications
You must be signed in to change notification settings - Fork 106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Solution for issue#190 #229
Open
scp-WFZ
wants to merge
6
commits into
romankh3:master
Choose a base branch
from
scp-WFZ:version-for-issue#190
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b61caab
Add functions for issue#190
scp-WFZ 44596b0
add tests for issue#190
scp-WFZ cb5a99e
Update pom.xml
scp-WFZ a10e054
Update ImageComparisonUtil.java
scp-WFZ 89e24bc
Add issue comment
scp-WFZ d6f4916
Merge branch 'master' into version-for-issue#190
romankh3 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,11 +16,18 @@ | |
import javax.imageio.ImageIO; | ||
import javax.swing.ImageIcon; | ||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please, remove extra lines. |
||
|
||
|
||
/** | ||
* Tools for the {@link ImageComparison} object. | ||
*/ | ||
public final class ImageComparisonUtil { | ||
|
||
public static int OFFSET = 0xff; | ||
public static int EIGHT = 8; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's the difference between |
||
public static int TENSIX = 8; | ||
|
||
/** | ||
* Make a copy of the {@link BufferedImage} object. | ||
* | ||
|
@@ -142,11 +149,13 @@ public static float getDifferencePercent(BufferedImage img1, BufferedImage img2) | |
long diff = 0; | ||
for (int y = 0; y < height; y++) { | ||
for (int x = 0; x < width; x++) { | ||
diff += pixelDiff(img1.getRGB(x, y), img2.getRGB(x, y)); | ||
if(isDiffPixel(img1.getRGB(x, y), img2.getRGB(x, y))) { | ||
diff += 1; | ||
} | ||
} | ||
} | ||
long maxDiff = 3L * 255 * width * height; | ||
|
||
//CS304 Issue link: https://github.com/romankh3/image-comparison/issues/190 | ||
long maxDiff = (long) width * height; | ||
return (float) (100.0 * diff / maxDiff); | ||
} | ||
|
||
|
@@ -166,4 +175,22 @@ public static int pixelDiff(int rgb1, int rgb2) { | |
int b2 = rgb2 & 0xff; | ||
return Math.abs(r1 - r2) + Math.abs(g1 - g2) + Math.abs(b1 - b2); | ||
} | ||
|
||
/** | ||
* Compare two pixels. | ||
* | ||
* @param rgb1 the first rgb | ||
* @param rgb2 the second rgb | ||
* @return true If they are the same RGB pixel. | ||
*/ | ||
//CS304 Issue link: https://github.com/romankh3/image-comparison/issues/190 | ||
public static boolean isDiffPixel(final int rgb1, final int rgb2) { | ||
int r1 = (rgb1 >> TENSIX) & OFFSET; | ||
int g1 = (rgb1 >> EIGHT) & OFFSET; | ||
int b1 = rgb1 & OFFSET; | ||
int r2 = (rgb2 >> TENSIX) & OFFSET; | ||
int g2 = (rgb2 >> EIGHT) & OFFSET; | ||
int b2 = rgb2 & OFFSET; | ||
return Math.abs(r1 - r2) + Math.abs(g1 - g2) + Math.abs(b1 - b2) != 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tell me please, for what reason you've added it?