diff options
Diffstat (limited to 'evc/src/view.rs')
-rw-r--r-- | evc/src/view.rs | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/evc/src/view.rs b/evc/src/view.rs index 3843128..5868680 100644 --- a/evc/src/view.rs +++ b/evc/src/view.rs @@ -1,9 +1,11 @@ use crate::{ frame::Frame, helpers::{pixel::Pixel, vector::Vec2}, + refsampler::Sampler, }; use std::ops::{Index, IndexMut}; +#[derive(Debug, Clone)] pub struct View<T> { pub frame: T, pub offset: Vec2<isize>, @@ -140,6 +142,22 @@ impl<T: Index<Vec2<isize>, Output = Pixel>> View<&T> { } acc as f64 } + pub fn diff_sampler(va: &Self, vb: &Sampler<'_>) -> f64 { + assert_eq!(va.size, vb.view.size); + let mut acc = 0; + for x in 0..va.size.x { + for y in 0..va.size.y { + let a = va[(x, y)]; + let b = vb.sample(Vec2 { + x: x as f32, + y: y as f32, + }); + acc += Pixel::distance(a, b); + } + } + acc as f64 + } + pub fn pixels(&self) -> Vec<Pixel> { let mut v = vec![]; for x in 0..self.size.x { @@ -158,6 +176,14 @@ impl View<&mut Frame> { } } } + pub fn copy_from_sampler(&mut self, other: &Sampler) { + for x in 0..self.size.x { + for y in 0..self.size.y { + self[(x, y)] = other.sample((x, y).into()); + } + } + } + pub fn set_pixels(&mut self, pixels: &Vec<Pixel>) { for x in 0..self.size.x { for y in 0..self.size.y { @@ -166,6 +192,11 @@ impl View<&mut Frame> { } } } +impl View<&Frame> { + pub fn sample(&self, p: Vec2<f32>) -> Pixel { + self.frame.sample(p + self.offset.into()) + } +} impl<T: Index<Vec2<isize>, Output = Pixel>> Index<Vec2<isize>> for View<&T> { type Output = Pixel; |