Take the transform of the ImageFrame into account when blending (#1072)

* Take the transform of the ImageFrame into account when blending

The implementation computes the axis-aligned bounding box after we transform
the corners of the source image, and then iterates through that box
and computes the inverse of the affine transform of the source image.
The samples are taken based on the u/v coordinates, so that the differences
in size/aspect ratio between the images don't matter.

This makes for a much simpler implementation, and gives us the flexibility
to add different filtering methods in the future, for example.

Signed-off-by: Ică Alexandru-Gabriel <alexandru@seyhanlee.com>

* Name the parameters for the blend node properly

This avoids confusion between which one of the images is the `source`
image and which one is the `destination`.

Signed-off-by: Ică Alexandru-Gabriel <alexandru@seyhanlee.com>

* Remove rendundant computation for u/v coordinates

Signed-off-by: Ică Alexandru-Gabriel <alexandru@seyhanlee.com>

* Rewrite the sampling/clamping logic

* Add image frame transform node

* Move transform node to transform module

* Fix a few issues with our transformation logic

* Fix math + do cleanup

---------

Signed-off-by: Ică Alexandru-Gabriel <alexandru@seyhanlee.com>
Co-authored-by: Dennis Kobert <dennis@kobert.dev>
This commit is contained in:
Alexandru Ică 2023-03-15 12:48:13 +02:00 committed by Keavon Chambers
parent fb6ca73808
commit 0a775fe9be
7 changed files with 146 additions and 26 deletions

View file

@ -330,6 +330,7 @@ mod image {
use core::hash::{Hash, Hasher};
use dyn_any::{DynAny, StaticType};
use glam::DAffine2;
use glam::DVec2;
#[derive(Clone, Debug, PartialEq, DynAny, Default, specta::Type, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
@ -425,6 +426,17 @@ mod image {
transform: DAffine2::ZERO,
}
}
pub fn get_mut(&mut self, x: usize, y: usize) -> &mut Color {
&mut self.image.data[y * (self.image.width as usize) + x]
}
pub fn sample(&self, x: f64, y: f64) -> Color {
let x = x.clamp(0.0, self.image.width as f64 - 1.0) as usize;
let y = y.clamp(0.0, self.image.height as f64 - 1.0) as usize;
self.image.data[y * (self.image.width as usize) + x]
}
}
impl Hash for ImageFrame {