aboutsummaryrefslogtreecommitdiff
path: root/lvc/src/impls.rs
diff options
context:
space:
mode:
Diffstat (limited to 'lvc/src/impls.rs')
-rw-r--r--lvc/src/impls.rs33
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]