-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bbc3ee4
commit de593fd
Showing
35 changed files
with
1,163 additions
and
297 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ jobs: | |
- uses: dart-lang/[email protected] | ||
- uses: actions/setup-node@v4 | ||
- uses: browser-actions/setup-chrome@v1 | ||
- uses: mfinelli/setup-imagemagick@v5 | ||
- run: dart pub get | ||
- run: dart format --output none --set-exit-if-changed . | ||
- run: dart analyze | ||
|
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
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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
part of '../buffer.dart'; | ||
|
||
/// The result of a pixel comparison test. | ||
final class ComparisonResult<T> { | ||
/// Compares two pixel buffers [a] and [b] and returns the result. | ||
factory ComparisonResult._compare( | ||
Buffer<T> a, | ||
Buffer<T> b, { | ||
double epsilon = 1e-10, | ||
}) { | ||
// If the dimension are different, the buffers are considered different. | ||
if (a.width != b.width || a.height != b.height) { | ||
return ComparisonResult._(1.0); | ||
} | ||
|
||
// Ensure the pixel formats are the same. | ||
b = b.mapConvert(a.format); | ||
|
||
// Calculate the difference between the two buffers. | ||
final aIterator = a.data.iterator; | ||
final bIterator = b.data.iterator; | ||
var pixelDiffCount = 0; | ||
while (aIterator.moveNext() && bIterator.moveNext()) { | ||
final diffPixel = a.format.compare(aIterator.current, bIterator.current); | ||
if (diffPixel > epsilon) { | ||
pixelDiffCount += 1; | ||
} | ||
} | ||
|
||
return ComparisonResult._(pixelDiffCount / a.length); | ||
} | ||
|
||
const ComparisonResult._(this.difference); | ||
|
||
/// The calculated percentage of pixel difference between two pixel buffers. | ||
final double difference; | ||
|
||
/// Whether the two pixel buffers were considered identical. | ||
/// | ||
/// Equivalent to `difference == 0.0`. | ||
bool get isIdentical => difference == 0.0; | ||
|
||
/// Whether the two pixel buffers were considered different. | ||
/// | ||
/// Equivalent to `difference != 0.0`. | ||
bool get isDifferent => difference != 0.0; | ||
|
||
@override | ||
String toString() => 'ComparisonResult <difference: $difference>'; | ||
} |
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
Oops, something went wrong.