Skip to content

Commit

Permalink
Fix border-image screenshot test
Browse files Browse the repository at this point in the history
The test will test that things are rendered the same with a clip. But
that gives bad error when rendering images with high ferquencies because
a small difference in the initial condition of drawing may result in
being off by a pixel.
  • Loading branch information
ogoffart committed Feb 13, 2024
1 parent b2920b1 commit b2143f6
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .reuse/dep5
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ Files: editors/vscode/static/assets/img/nodejs_logo.svg
Copyright: node.js authors
License: CC0-1.0

Files: tests/screenshots/references/software/*/*.png
Files: tests/screenshots/**/*.png
Copyright: Copyright © SixtyFPS GmbH <info@slint.dev>
License: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-1.1 OR LicenseRef-Slint-commercial

Expand Down
3 changes: 2 additions & 1 deletion tests/screenshots/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ fn main() -> std::io::Result<()> {
panic!("Cannot parse {needle} for {}", testcase.relative_path.display())
})
});
let skip_clipping = source.contains("SKIP_CLIPPING");

let mut output = BufWriter::new(std::fs::File::create(
Path::new(&std::env::var_os("OUT_DIR").unwrap()).join(format!("{}.rs", module_name)),
Expand All @@ -113,7 +114,7 @@ fn main() -> std::io::Result<()> {
{scale_factor}
window.set_size(slint::PhysicalSize::new(64, 64));
let screenshot = {reference_path};
let options = testing::TestCaseOptions {{ rotation_threshold: {rotation_threshold}f32 }};
let options = testing::TestCaseOptions {{ rotation_threshold: {rotation_threshold}f32, skip_clipping: {skip_clipping} }};
let instance = TestCase::new().unwrap();
instance.show().unwrap();
Expand Down
3 changes: 3 additions & 0 deletions tests/screenshots/cases/software/basic/border-image.slint
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

import { Slider } from "std-widgets.slint";

// ROTATION_THRESHOLD=360 - because rendering pixelized image is not accurate in rotation
// SKIP_CLIPPING - without smooth scaling, any small difference in the starting point of the drawing of scaled image may result in pixel being off

export component TestCase inherits Window {
width: 64px;
height: 64px;
Expand Down
11 changes: 9 additions & 2 deletions tests/screenshots/testing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ fn color_difference(lhs: &Rgb8Pixel, rhs: &Rgb8Pixel) -> f32 {
pub struct TestCaseOptions {
/// How much we allow the maximum pixel difference to be when operating a screen rotation
pub rotation_threshold: f32,

/// When true, we don't compare screenshots rendered with clipping
pub skip_clipping: bool,
}

fn compare_images(
Expand Down Expand Up @@ -286,8 +289,12 @@ pub fn assert_with_render_by_line(
));
}
screenshot_render_by_line(window, Some(region.cast()), &mut rendering);
if let Err(reason) = compare_images(path, &rendering, RenderingRotation::NoRotation, options) {
panic!("Partial rendering image comparison failure for line-by-line rendering for {path}: {reason}");
if !options.skip_clipping {
if let Err(reason) =
compare_images(path, &rendering, RenderingRotation::NoRotation, options)
{
panic!("Partial rendering image comparison failure for line-by-line rendering for {path}: {reason}");
}
}
}

Expand Down

0 comments on commit b2143f6

Please sign in to comment.