diff options
author | metamuffin <metamuffin@disroot.org> | 2022-12-07 20:38:00 +0100 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2022-12-07 20:38:00 +0100 |
commit | 9d7986bbfd44b69a623fa29528b5d13000b91c77 (patch) | |
tree | 8da95f328243a96acec6c3ea6ebddc71bb63f05c /evc/src/view.rs | |
parent | 7be0d5039db7e8660bced13698178bf1d6758109 (diff) | |
download | video-codec-experiments-9d7986bbfd44b69a623fa29528b5d13000b91c77.tar video-codec-experiments-9d7986bbfd44b69a623fa29528b5d13000b91c77.tar.bz2 video-codec-experiments-9d7986bbfd44b69a623fa29528b5d13000b91c77.tar.zst |
advanced translate
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; |