mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-03 06:31:42 +01:00
fix(algo): keep the 7x7 patch when the sampling area is not the Rectangular one
#14191 measured Rectangular, and Auto where it keeps that same area. Auto where its content-based choice differs from Rectangular is marked not measured and keeps today's radius. fill_cow now takes the 11x11 patch only when the source mask is every pixel outside the hole.
This commit is contained in:
1 parent
73dc8e2f82
commit
c8bef7880c
2 files changed
+54
-3
No files matched your search
@@ -249,8 +249,8 @@ pub fn fill_owned(
|
||||
/// 20 px stripes: the default 7x7 patch fits inside one stripe or inside one band gap, so it
|
||||
/// carries no phase information and the completion decides from colour alone and runs one region
|
||||
/// into the other. An 11x11 patch covers a feature and the one next to it, which is what keeps
|
||||
/// their phase through the hole. Every other option set is marked "not measured" in #14191 and
|
||||
/// keeps [`CompleteParams`]' default radius.
|
||||
/// their phase through the hole. Every other option set, and a sampling area other than the
|
||||
/// Rectangular one, is marked "not measured" in #14191 and keeps [`CompleteParams`]' default radius.
|
||||
const MEASURED_STRUCTURE_PATCH_RADIUS: usize = 5;
|
||||
|
||||
/// Whether `opts` holds the option set #14191 measured on its test document: Default colour
|
||||
@@ -259,6 +259,13 @@ fn structure_measured(opts: &FillOptions) -> bool {
|
||||
opts.color_adaptation == color_level("default") && opts.rotations.is_empty() && !opts.scale && !opts.mirror
|
||||
}
|
||||
|
||||
/// Whether `source` is the Rectangular sampling area of the buffer: every pixel outside the hole.
|
||||
/// #14191 measured Rectangular, and Auto where it keeps that same area; Auto where its
|
||||
/// content-based choice differs (or any other area) is not measured.
|
||||
fn rectangular_area(hole: &[bool], source: &[bool]) -> bool {
|
||||
hole.iter().zip(source).all(|(h, s)| *h || *s)
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
fn fill_cow(
|
||||
w: usize,
|
||||
@@ -277,7 +284,7 @@ fn fill_cow(
|
||||
return Ok(img.into_owned());
|
||||
}
|
||||
let mut params = CompleteParams { seed: opts.seed, adapt: opts.color_adaptation, ..Default::default() };
|
||||
if structure_measured(opts) {
|
||||
if structure_measured(opts) && rectangular_area(hole, source) {
|
||||
params.patch_radius = MEASURED_STRUCTURE_PATCH_RADIUS;
|
||||
}
|
||||
let gap = 2 * params.patch_radius + 2;
|
||||
|
||||
@@ -304,3 +304,47 @@ fn unmeasured_geometric_adaptation_keeps_todays_fill() {
|
||||
check_unmeasured(what, &opts, &want);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn measured_auto_area_is_the_rectangular_one() {
|
||||
// What the measured Auto and Rectangular fills above rest on: on this document Auto keeps the
|
||||
// whole window, as in the reference application.
|
||||
let (img, hole, ww) = window_buffers();
|
||||
assert_eq!(auto_sampling(ww, 400, 3, &img, &hole), hole.iter().map(|h| !h).collect::<Vec<bool>>());
|
||||
}
|
||||
|
||||
/// #14191 marks Auto on a document where its content-based choice differs from Rectangular as not
|
||||
/// measured, so that fill keeps today's 7x7 patch even with the measured options. The document: the
|
||||
/// measured one with a white column 40 px wide at x 440 to 480 in the window, which Auto leaves
|
||||
/// out. Today's fill is the completion with [`CompleteParams`]' default radius on the same roles.
|
||||
#[test]
|
||||
fn auto_fill_whose_area_differs_from_rectangular_keeps_todays_patch_radius() {
|
||||
let (mut img, hole, ww) = window_buffers();
|
||||
let column = |i: usize| (440..480).contains(&(window().x0 as usize + i % ww));
|
||||
for (i, px) in img.chunks_mut(3).enumerate() {
|
||||
if column(i) {
|
||||
px.copy_from_slice(&[250.0 / 255.0; 3]);
|
||||
}
|
||||
}
|
||||
let source = auto_sampling(ww, 400, 3, &img, &hole);
|
||||
let rectangular: Vec<bool> = hole.iter().map(|h| !h).collect();
|
||||
assert_ne!(source, rectangular, "Auto must choose an area other than the Rectangular one here");
|
||||
let opts = FillOptions::default();
|
||||
let out = fill(ww, 400, 3, &img, &hole, &source, &opts);
|
||||
let roles: Vec<Px> = (0..ww * 400)
|
||||
.map(|i| {
|
||||
if hole[i] {
|
||||
Px::Hole
|
||||
} else if source[i] {
|
||||
Px::Source
|
||||
} else {
|
||||
Px::Known
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
let params = CompleteParams { seed: opts.seed, adapt: opts.color_adaptation, ..Default::default() };
|
||||
assert_eq!(params.patch_radius, 3, "today's radius");
|
||||
let today = complete_masked(ww, 400, 3, &img, &roles, ¶ms, &Interrupt::NONE).unwrap().unwrap();
|
||||
let moved = out.iter().zip(&today).filter(|(a, b)| a != b).count();
|
||||
assert_eq!(moved, 0, "{moved} channel values differ from today's radius-3 fill");
|
||||
}
|
||||
Reference in new issue
Block a user