diff options
Diffstat (limited to 'src/transform.rs')
-rw-r--r-- | src/transform.rs | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/transform.rs b/src/transform.rs index 0b65728..ccb1850 100644 --- a/src/transform.rs +++ b/src/transform.rs @@ -39,3 +39,43 @@ impl Sample for Translate { self.inner.sample(x - self.offset.0, y - self.offset.1) } } + +pub enum CompositeOperation { + Add, + Subtract, + Multiply, + Mix(f64), +} +pub struct Composite { + pub a: Box<dyn Sample>, + pub b: Box<dyn Sample>, + pub mode: CompositeOperation, +} +impl Sample for Composite { + fn sample(&mut self, x: f64, y: f64) -> Color { + let a = self.a.sample(x, y); + let b = self.b.sample(x, y); + match self.mode { + CompositeOperation::Add => Color { + r: a.r + b.r, + g: a.g + b.g, + b: a.b + b.b, + }, + CompositeOperation::Subtract => Color { + r: a.r - b.r, + g: a.g - b.g, + b: a.b - b.b, + }, + CompositeOperation::Multiply => Color { + r: a.r * b.r, + g: a.g * b.g, + b: a.b * b.b, + }, + CompositeOperation::Mix(f) => Color { + r: a.r * (1.0 - f) + b.r * f, + g: a.g * (1.0 - f) + b.g * f, + b: a.b * (1.0 - f) + b.b * f, + }, + } + } +} |