Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Changelog

[[Unreleased]]
- [diff is displayed if images only differ in their alpha channel](https://github.com/ehmkah/imgdiff/issues/78)

## [1.12.0]
- Upgrade project to JDK 21 from JDK 11
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,18 @@ class DiffedImageCreator {
val r1 = rgb1 shr 16 and 0xff
val g1 = rgb1 shr 8 and 0xff
val b1 = rgb1 and 0xff
val a1 = rgb1 shr 24 and 0xff
val r2 = rgb2 shr 16 and 0xff
val g2 = rgb2 shr 8 and 0xff
val b2 = rgb2 and 0xff
val a2 = rgb2 shr 24 and 0xff
diff = Math.abs(r1 - r2)
diff += Math.abs(g1 - g2)
diff += Math.abs(b1 - b2)
diff /= 3

diffPixel = diff shl 16 or (diff shl 8) or diff
if (diffPixel == 0) {
if (diffPixel == 0 && a1 == a2) {
diffPixel = backgroundColor(currentWidth, currentHeight)
} else {
diffPixel = differentValue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,17 @@ class DiffedImageCreatorTest {
assertTrue(compareImages(expected, actual))
}

@Test
fun testDifferentAlphaChannel() {
val original = readImage("/black.png")
val changed = readImage("/blackAlpha.png")

val actual = sut.getDifferenceImageWhiteAsBackground(original, changed)
val expected = readImage("/expectedAlphaDiff.png")

assertTrue(compareImages(expected, actual))
}

@Test
fun testImagesHaveNoDiff() {
val original = readImage("/identical.png")
Expand Down
Binary file added src/test/resources/black.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/test/resources/blackAlpha.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/test/resources/expectedAlphaDiff.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading