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

@ -143,7 +143,7 @@ mod tests {
} else if f <= 0.0031308f32 {
12.92_f32 * f
} else if f < 1_f32 {
1.055f32 * f.powf(1.0f_32 / 2.4_f32) - 0.055f32
1.055f32 * f.powf(1.0_f32 / 2.4_f32) - 0.055f32
} else {
1_f32
}
@ -163,7 +163,7 @@ mod tests {
}
fn srgb_u8_to_float_ref(c: u8) -> f32 {
srgb_to_float_ref(c as f32 * (1_f32 / 255.0f_32))
srgb_to_float_ref(c as f32 * (1_f32 / 255.0_f32))
}
#[test]

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();