Skip to content

Commit fe8787d

Browse files
look at pixels and not bytes
1 parent a084351 commit fe8787d

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

snapshot/src/androidMain/kotlin/com/quickbird/snapshot/Bitmap+updatePixels.kt renamed to snapshot/src/androidMain/kotlin/com/quickbird/snapshot/Bitmap+pixels.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,10 @@ internal fun Bitmap.updatePixels(update: (x: Int, y: Int, color: Color) -> Color
1010
}
1111
}
1212
}
13+
14+
internal val Bitmap.pixels
15+
get() = (0 until width).flatMap { x ->
16+
(0 until height).map { y ->
17+
getPixel(x, y).color
18+
}
19+
}

snapshot/src/androidMain/kotlin/com/quickbird/snapshot/Diffing+bitmap.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ val Diffing.Companion.intMean
3737
}
3838

3939
private infix fun Bitmap.differenceTo(other: Bitmap): Double {
40-
val thisBytes = this.asByteArray()
41-
val otherBytes = other.asByteArray()
42-
if (thisBytes == null || otherBytes == null || thisBytes.size != otherBytes.size) return 100.0
40+
val thisPixels = this.pixels
41+
val otherPixels = other.pixels
42+
if (thisPixels.size != otherPixels.size) return 100.0
4343

44-
val differentBytes = thisBytes
45-
.zip(otherBytes, Byte::equals)
44+
val differentPixelCount = thisPixels
45+
.zip(otherPixels, Color::equals)
4646
.count { !it }
4747

48-
return differentBytes.toDouble() / thisBytes.size
48+
return differentPixelCount.toDouble() / thisPixels.size
4949
}

0 commit comments

Comments
 (0)