Add some Improvements to Mask Node (#1233)

These Improvements were proposed by nat-rix for PR #1153 but also apply to the Mask Node
This commit is contained in:
isiko
2023-05-25 11:26:16 +02:00
committed by Keavon Chambers
parent bb93d243a0
commit 99d15df1e0
2 changed files with 5 additions and 4 deletions

View File

@@ -206,13 +206,14 @@ fn mask_image<
// Transforms a point from the background image to the forground image
let bg_to_fg = image.transform() * DAffine2::from_scale(1. / image_size);
let stencil_transform_inverse = stencil.transform().inverse();
let area = bg_to_fg.transform_point2(DVec2::new(1., 1.)) - bg_to_fg.transform_point2(DVec2::ZERO);
let area = bg_to_fg.transform_vector2(DVec2::ONE);
for y in 0..image.height() {
for x in 0..image.width() {
let image_point = DVec2::new(x as f64, y as f64);
let mut mask_point = bg_to_fg.transform_point2(image_point);
let local_mask_point = stencil.transform().inverse().transform_point2(mask_point);
let local_mask_point = stencil_transform_inverse.transform_point2(mask_point);
mask_point = stencil.transform().transform_point2(local_mask_point.clamp(DVec2::ZERO, DVec2::ONE));
let image_pixel = image.get_pixel_mut(x, y).unwrap();