-
Notifications
You must be signed in to change notification settings - Fork 0
[Feature] Add scene comparison report. (Resolves #43) #56
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f2435ff
[Feature] Add scene comparison report (Resolves #43)
angelosilvestre 45a26c2
PR updates
angelosilvestre b10a612
PR updates
angelosilvestre 831e127
PR updates
angelosilvestre 0de9b9b
Separate metadata extraction
angelosilvestre 8b18cee
PR updates
angelosilvestre a911782
PR updates
angelosilvestre 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 hidden or 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 hidden or 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,83 @@ | ||
import 'dart:math'; | ||
import 'dart:ui' as ui; | ||
|
||
import 'package:flutter_test_goldens/src/goldens/pixel_comparisons.dart'; | ||
import 'package:image/image.dart'; | ||
|
||
import 'package:flutter_test_goldens/flutter_test_goldens.dart'; | ||
|
||
/// Given a [mismatch] between a golden and a screenshot, generates an image | ||
/// that shows the golden, the screenshot, and the differences between them. | ||
Future<Image> generateFailureScene(GoldenMismatch mismatch) async { | ||
final goldenWidth = mismatch.golden!.image.width; | ||
final goldenHeight = mismatch.golden!.image.height; | ||
|
||
final screenshotWidth = mismatch.screenshot!.image.width; | ||
final screenshotHeight = mismatch.screenshot!.image.height; | ||
|
||
final maxWidth = max(goldenWidth, screenshotWidth); | ||
final maxHeight = max(goldenHeight, screenshotHeight); | ||
|
||
final failureImage = Image( | ||
width: maxWidth * 2, | ||
height: maxHeight * 2, | ||
); | ||
|
||
// Copy golden to top left corner. | ||
for (int x = 0; x < goldenWidth; x += 1) { | ||
for (int y = 0; y < goldenHeight; y += 1) { | ||
final goldenPixel = mismatch.golden!.image.getPixel(x, y); | ||
failureImage.setPixel(x, y, goldenPixel); | ||
} | ||
} | ||
|
||
// Copy screenshot to top right corner. | ||
for (int x = 0; x < screenshotWidth; x += 1) { | ||
for (int y = 0; y < screenshotHeight; y += 1) { | ||
final screenshotPixel = mismatch.screenshot!.image.getPixel(x, y); | ||
failureImage.setPixel(maxWidth + x, y, screenshotPixel); | ||
} | ||
} | ||
|
||
// Paint mismatch images. | ||
final absoluteDiffColor = ColorUint32.rgb(255, 255, 0); | ||
for (int x = 0; x < maxWidth; x += 1) { | ||
for (int y = 0; y < maxHeight; y += 1) { | ||
if (x >= goldenWidth || x >= screenshotWidth || y >= goldenHeight || y >= screenshotHeight) { | ||
// This pixel doesn't exist in the golden, or it doesn't exist in the | ||
// screenshot. Therefore, we have nothing to compare. Treat this pixel | ||
// as a max severity difference. | ||
|
||
// Paint this pixel in the absolute diff image. | ||
failureImage.setPixel(x, maxHeight + y, absoluteDiffColor); | ||
|
||
// Paint this pixel in the relative severity diff image. | ||
failureImage.setPixel(maxWidth + x, maxHeight + y, absoluteDiffColor); | ||
|
||
continue; | ||
} | ||
|
||
// Check if the screenshot matches the golden. | ||
final goldenPixel = mismatch.golden!.image.getPixel(x, y); | ||
final screenshotPixel = mismatch.screenshot!.image.getPixel(x, y); | ||
final pixelsMatch = goldenPixel == screenshotPixel; | ||
if (pixelsMatch) { | ||
continue; | ||
} | ||
|
||
// Paint this pixel in the absolute diff image. | ||
failureImage.setPixel(x, maxHeight + y, absoluteDiffColor); | ||
|
||
// Paint this pixel in the relative severity diff image. | ||
final mismatchPercent = calculateColorMismatchPercent(goldenPixel, screenshotPixel); | ||
final yellowAmount = ui.lerpDouble(0.2, 1.0, mismatchPercent)!; | ||
failureImage.setPixel( | ||
goldenWidth + x, | ||
goldenHeight + y, | ||
ColorUint32.rgb((255 * yellowAmount).round(), (255 * yellowAmount).round(), 0), | ||
); | ||
} | ||
} | ||
|
||
return failureImage; | ||
} |
This file contains hidden or 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.
Uh oh!
There was an error while loading. Please reload this page.