aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xevc/scripts/gen4
-rwxr-xr-xevc/scripts/stream6
-rw-r--r--evc/src/bin/decode.rs8
-rw-r--r--evc/src/block.rs18
-rw-r--r--evc/src/frame.rs5
-rw-r--r--evc/src/ser.rs12
-rw-r--r--evc/src/view.rs11
7 files changed, 44 insertions, 20 deletions
diff --git a/evc/scripts/gen b/evc/scripts/gen
new file mode 100755
index 0000000..2160b9a
--- /dev/null
+++ b/evc/scripts/gen
@@ -0,0 +1,4 @@
+#/bin/fish
+cargo run --release --bin encode -- -W 1920 -H 1080 < samples/raw > samples/encoded
+cargo run --release --bin decode -- < samples/encoded > samples/decoded
+ffmpeg -framerate 30 -video_size 1920x1080 -pixel_format rgb24 -f rawvideo -i samples/decoded samples/decoded.mp4
diff --git a/evc/scripts/stream b/evc/scripts/stream
new file mode 100755
index 0000000..73dca01
--- /dev/null
+++ b/evc/scripts/stream
@@ -0,0 +1,6 @@
+#!/bin/fish
+ffmpeg -i ~/videos/eddie-woo.mp4 -to 10 -vf scale=1920x1080,fps=30,format=rgb24 -f rawvideo pipe:1 |
+ cargo run --release --bin encode -- -W 1920 -H 1080 |
+ cargo run --release --bin decode |
+ ffplay -framerate 30 -video_size 1920x1080 -pixel_format rgb24 -f rawvideo
+ \ No newline at end of file
diff --git a/evc/src/bin/decode.rs b/evc/src/bin/decode.rs
index 0a00426..af6edc6 100644
--- a/evc/src/bin/decode.rs
+++ b/evc/src/bin/decode.rs
@@ -45,13 +45,7 @@ fn main() -> anyhow::Result<()> {
fn blit_block(block: &Block, mut target: View<&mut Frame>, prev: View<&Frame>) {
match &block.inner {
- BlockInner::Literal(pixels) => {
- for x in 0..block.size.0 {
- for y in 0..block.size.1 {
- target[(x, y)] = pixels[x + y * block.size.0]
- }
- }
- }
+ BlockInner::Literal(pixels) => target.set_pixels(pixels),
BlockInner::Split(box [a, b]) => {
let [at, bt] = target.split_mut_unsafe();
let [ap, bp] = prev.split();
diff --git a/evc/src/block.rs b/evc/src/block.rs
index f58bcb3..98e3b54 100644
--- a/evc/src/block.rs
+++ b/evc/src/block.rs
@@ -1,3 +1,5 @@
+use anyhow::bail;
+
use crate::{
pixel::Pixel,
ser::{Ser, Sink, Source},
@@ -28,8 +30,9 @@ impl Block {
a.write(sink)?;
b.write(sink)?;
}
- BlockInner::Reference { translation: _ } => {
+ BlockInner::Reference { translation } => {
sink.put(2u8)?;
+ // sink.put(*translation)?;
}
}
Ok(())
@@ -39,15 +42,20 @@ impl Block {
let inner = match source.get::<u8>()? {
0 => BlockInner::Literal(source.get()?),
1 => BlockInner::Split(Box::new({
- let subsize = if size.0 > size.1 {
+ let subsize_left = if size.0 > size.1 {
(size.0 / 2, size.1)
} else {
(size.0, size.1 / 2)
};
- [Block::read(source, subsize)?, Block::read(source, subsize)?]
+ let subsize_right = (size.0 - subsize_left.0, size.1 - subsize_left.1);
+ let a = Block::read(source, subsize_left)?;
+ let b = Block::read(source, subsize_right)?;
+ [a, b]
})),
- 2 => todo!(),
- _ => panic!("file corrupt"),
+ 2 => BlockInner::Reference {
+ translation: (0, 0), //source.get()?,
+ },
+ x => bail!("corrupt block type ({})", x),
};
Ok(Self { size, inner })
diff --git a/evc/src/frame.rs b/evc/src/frame.rs
index c36abf3..16acb96 100644
--- a/evc/src/frame.rs
+++ b/evc/src/frame.rs
@@ -3,10 +3,7 @@ use crate::{
ser::{Sink, Source},
view::View,
};
-use std::{
- io,
- ops::{Index, IndexMut},
-};
+use std::ops::{Index, IndexMut};
pub struct Frame {
pub size: (usize, usize),
diff --git a/evc/src/ser.rs b/evc/src/ser.rs
index 6e1ef98..3b7814f 100644
--- a/evc/src/ser.rs
+++ b/evc/src/ser.rs
@@ -174,9 +174,9 @@ mod test {
use std::fmt::Debug;
use std::io::Cursor;
- fn test_ser<T: PartialEq + Ser + Debug + Copy>(value: T) {
+ fn test_ser<T: PartialEq + Ser + Debug + Clone>(value: T) {
let mut buf = vec![];
- Cursor::new(&mut buf).put(value).unwrap();
+ Cursor::new(&mut buf).put(value.clone()).unwrap();
assert_eq!(value, Cursor::new(&mut buf).get().unwrap());
}
@@ -199,4 +199,12 @@ mod test {
resolution: (13, 37),
});
}
+ #[test]
+ fn vec() {
+ test_ser(vec![1u16, 2, 3, 4]);
+ }
+ #[test]
+ fn array() {
+ test_ser([1u16, 2, 3, 4]);
+ }
}
diff --git a/evc/src/view.rs b/evc/src/view.rs
index 983fe67..f37e57c 100644
--- a/evc/src/view.rs
+++ b/evc/src/view.rs
@@ -25,7 +25,7 @@ impl<T> View<&mut T> {
let vert = self.size.0 > self.size.1;
[
Self {
- frame: unsafe { std::mem::transmute::<_, &mut T>(&mut self.frame) },
+ frame: unsafe { std::mem::transmute::<&mut T, &mut T>(&mut self.frame) },
offset: self.offset,
size: if vert {
(self.size.0 / 2, self.size.1)
@@ -34,7 +34,7 @@ impl<T> View<&mut T> {
},
},
Self {
- frame: unsafe { std::mem::transmute::<_, &mut T>(&mut self.frame) },
+ frame: unsafe { std::mem::transmute::<&mut T, &mut T>(&mut self.frame) },
offset: if vert {
(self.offset.0 + self.size.0 / 2, self.offset.1)
} else {
@@ -109,6 +109,13 @@ impl View<&mut Frame> {
}
}
}
+ pub fn set_pixels(&mut self, pixels: &Vec<Pixel>) {
+ for x in 0..self.size.0 {
+ for y in 0..self.size.1 {
+ self[(x, y)] = pixels[x + y * self.size.0]
+ }
+ }
+ }
}
impl<T: Index<(usize, usize), Output = Pixel>> Index<(usize, usize)> for View<&T> {