diff options
author | metamuffin <metamuffin@disroot.org> | 2023-03-07 17:15:49 +0100 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2023-03-07 17:15:49 +0100 |
commit | 414990bb53f5c9e2028d42db46fa641fa606cd86 (patch) | |
tree | 67424a3b7aec5e0219ecffec0fa7b0849858c8d2 /lvc/src/impls.rs | |
parent | 2167abcf72d978b4ac2f08fa7cbbddaada01f165 (diff) | |
download | video-codec-experiments-414990bb53f5c9e2028d42db46fa641fa606cd86.tar video-codec-experiments-414990bb53f5c9e2028d42db46fa641fa606cd86.tar.bz2 video-codec-experiments-414990bb53f5c9e2028d42db46fa641fa606cd86.tar.zst |
works
Diffstat (limited to 'lvc/src/impls.rs')
-rw-r--r-- | lvc/src/impls.rs | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/lvc/src/impls.rs b/lvc/src/impls.rs index 01eb1c6..0801361 100644 --- a/lvc/src/impls.rs +++ b/lvc/src/impls.rs @@ -1,6 +1,37 @@ -use crate::{Frame, Pixel, View, P2}; +use crate::{Frame, Pixel, Ref, View, P2}; use std::ops::{Add, Index, IndexMut, Sub}; +impl Frame { + pub fn export(&self, view: View) -> Vec<Pixel> { + let mut o = vec![]; + for y in view.a.y..view.b.y { + for x in view.a.x..view.b.x { + o.push(self[P2 { x, y }]) + } + } + o + } + pub fn import(&mut self, view: View, mut source: &[Pixel]) { + for y in view.a.y..view.b.y { + for x in view.a.x..view.b.x { + self[P2 { x, y }] = source[0]; + source = &source[1..]; + } + } + } + pub fn new(size: P2) -> Self { + Self { + pixels: vec![Pixel::default(); size.area()], + size, + } + } +} +impl Ref { + pub fn apply<F: Fn(&mut Self)>(mut self, f: F) -> Self { + f(&mut self); + self + } +} impl Add for Pixel { type Output = Pixel; #[inline] |