From 70514416c2ade2abe628efbd0a629a66febdeb13 Mon Sep 17 00:00:00 2001 From: metamuffin Date: Tue, 6 Dec 2022 19:30:03 +0100 Subject: minor stuff, store translation as i8 --- evc/scripts/gen | 11 ++++++++--- evc/scripts/gen-debug | 4 ---- evc/scripts/stream | 8 +++++--- evc/scripts/stream-lq | 8 ++++---- evc/spec.md | 4 ++-- evc/src/block.rs | 6 +++--- evc/src/debug.rs | 11 +++++++---- evc/src/frame.rs | 5 +++++ evc/src/ser.rs | 12 ++++++++++++ evc/src/vec2.rs | 15 +++++++++++++++ 10 files changed, 61 insertions(+), 23 deletions(-) delete mode 100755 evc/scripts/gen-debug (limited to 'evc') diff --git a/evc/scripts/gen b/evc/scripts/gen index 9754079..8fd53dd 100755 --- a/evc/scripts/gen +++ b/evc/scripts/gen @@ -1,4 +1,9 @@ #/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 -y -framerate 30 -video_size 1920x1080 -pixel_format rgb24 -f rawvideo -i samples/decoded samples/decoded.mp4 +set w $argv[1] +set h $argv[2] +ffmpeg -i $argv[3] -to 10 -vf scale={$w}x{$h},fps=30 -f rawvideo -pixel_format rgb24 > samples/raw +LOG=info cargo run --release --bin encode -- -W {$w} -H {$h} < samples/raw > samples/encoded +LOG=info cargo run --release --bin decode -- < samples/encoded > samples/decoded +LOG=info cargo run --release --bin decode -- --debug < samples/encoded > samples/decoded-debug +ffmpeg -y -framerate 30 -video_size {$w}x{$h} -pixel_format rgb24 -f rawvideo -i samples/decoded samples/decoded.mp4 +ffmpeg -y -framerate 30 -video_size {$w}x{$h} -pixel_format rgb24 -f rawvideo -i samples/decoded-debug samples/decoded-debug.mp4 diff --git a/evc/scripts/gen-debug b/evc/scripts/gen-debug deleted file mode 100755 index 513afab..0000000 --- a/evc/scripts/gen-debug +++ /dev/null @@ -1,4 +0,0 @@ -#/bin/fish -cargo run --release --bin encode -- -W 1920 -H 1080 < samples/raw > samples/encoded -cargo run --release --bin decode -- --debug < samples/encoded > samples/decoded -ffmpeg -y -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 index 2072e21..10098b6 100755 --- a/evc/scripts/stream +++ b/evc/scripts/stream @@ -1,5 +1,7 @@ #!/bin/fish -ffmpeg -i $argv[1] -vf scale=1920x1080,fps=30,format=rgb24 -f rawvideo pipe:1 2>/dev/null | - cargo run --release --bin encode -- -W 1920 -H 1080 | +set w $argv[1] +set h $argv[2] +ffmpeg -hide_banner -i $argv[3] -vf scale={$w}x{$h},fps=30,format=rgb24 -f rawvideo pipe:1 | + cargo run --release --bin encode -- -W {$w} -H {$h} | cargo run --release --bin decode -- --debug | - ffplay -framerate 30 -video_size 1920x1080 -pixel_format rgb24 -f rawvideo pipe:0 2>/dev/null + ffplay -hide_banner -framerate 30 -video_size {$w}x{$h} -pixel_format rgb24 -f rawvideo pipe:0 diff --git a/evc/scripts/stream-lq b/evc/scripts/stream-lq index 486dbaf..300800a 100755 --- a/evc/scripts/stream-lq +++ b/evc/scripts/stream-lq @@ -1,5 +1,5 @@ #!/bin/fish -ffmpeg -i $argv[1] -vf scale=1280x720,fps=30,format=rgb24 -f rawvideo pipe:1 2>/dev/null | - cargo run --release --bin encode -- -W 1280 -H 720 | - cargo run --release --bin decode -- --debug | - ffplay -framerate 30 -video_size 1280x720 -pixel_format rgb24 -f rawvideo pipe:0 2>/dev/null +ffmpeg -i $argv[1] -vf scale=920x550,fps=30,format=rgb24 -f rawvideo pipe:1 2>/dev/null | + LOG=info cargo run --release --bin encode -- -W 920 -H 550 | + LOG=info cargo run --release --bin decode -- --debug | + ffplay -framerate 30 -video_size 920x550 -pixel_format rgb24 -f rawvideo pipe:0 2>/dev/null diff --git a/evc/spec.md b/evc/spec.md index b22fbb6..a6994e0 100644 --- a/evc/spec.md +++ b/evc/spec.md @@ -8,11 +8,11 @@ - frames (repeated [frame count]-times) - block type - block - - **I-Block** (literal contents) + - **Literal-Block** (pixels saved) - pixels: _`[[u8; 3]]`_ - **Split-Block** (delegated to 2 sub-blocks split on the longest axis) - sub-blocks: _`[block; 2]` (see above)_ - - **Reference-Block** + - **Reference-Block** (reuses previous frame in some way) - translation: _`i8, i8`_ ### Todo diff --git a/evc/src/block.rs b/evc/src/block.rs index 024adb6..929793d 100644 --- a/evc/src/block.rs +++ b/evc/src/block.rs @@ -3,7 +3,7 @@ use anyhow::bail; use crate::{ pixel::Pixel, ser::{Ser, Sink, Source}, - vec2::Vec2, + vec2::{Small, Vec2}, }; #[derive(Clone, Debug)] @@ -27,7 +27,7 @@ impl Block { } Block::Reference { translation } => { sink.put(2u8)?; - sink.put(*translation)?; + sink.put(Small(*translation))?; } } Ok(()) @@ -54,7 +54,7 @@ impl Block { [a, b] })), 2 => Block::Reference { - translation: source.get()?, + translation: source.get::>()?.0, }, x => bail!("corrupt block type ({})", x), }) diff --git a/evc/src/debug.rs b/evc/src/debug.rs index cbc598e..0858fe4 100644 --- a/evc/src/debug.rs +++ b/evc/src/debug.rs @@ -25,10 +25,13 @@ impl Frame { let (mut cx, mut cy) = (sx, sy); let mut lc = 0.0; while lc < len { - self[Vec2 { - x: cx as isize, - y: cy as isize, - }] = color; + self.set( + Vec2 { + x: cx as isize, + y: cy as isize, + }, + color, + ); lc += 0.5; cx += nx * 0.5; cy += ny * 0.5; diff --git a/evc/src/frame.rs b/evc/src/frame.rs index 81390a2..3c40a3d 100644 --- a/evc/src/frame.rs +++ b/evc/src/frame.rs @@ -49,6 +49,11 @@ impl Frame { pub fn view_area_mut<'a>(&'a mut self, offset: Vec2, size: Vec2) -> View<&'a mut Frame> { View::new(self, offset, size) } + pub fn set(&mut self, pos: Vec2, color: Pixel) { + if pos.x >= 0 && pos.y >= 0 && pos.x < self.size.x && pos.y < self.size.y { + self[pos] = color + } + } } impl Index for Frame { diff --git a/evc/src/ser.rs b/evc/src/ser.rs index 61ca684..98d6706 100644 --- a/evc/src/ser.rs +++ b/evc/src/ser.rs @@ -93,6 +93,18 @@ impl Ser for u8 { Ok(buf[0]) } } +impl Ser for i8 { + fn write(&self, sink: &mut impl Write) -> anyhow::Result<()> { + Ok(sink + .write_all(&unsafe { std::mem::transmute_copy::<_, [u8; 1]>(self) }) + .context("write i8")?) + } + fn read(source: &mut impl Read) -> anyhow::Result { + let mut buf = [0u8; 1]; + source.read_exact(&mut buf)?; + Ok(unsafe { std::mem::transmute_copy(&buf) }) + } +} impl Ser for u16 { fn write(&self, sink: &mut impl Write) -> anyhow::Result<()> { Ok(sink diff --git a/evc/src/vec2.rs b/evc/src/vec2.rs index b1dd1b4..8b01fdb 100644 --- a/evc/src/vec2.rs +++ b/evc/src/vec2.rs @@ -26,6 +26,21 @@ impl Ser for Vec2 { } } +pub struct Small(pub T); +impl Ser for Small { + fn write(&self, sink: &mut impl std::io::Write) -> anyhow::Result<()> { + sink.put((self.0.x as i8, self.0.y as i8)) + } + + fn read(source: &mut impl std::io::Read) -> anyhow::Result { + let (x, y): (i8, i8) = source.get()?; + Ok(Small(Vec2 { + x: x as isize, + y: y as isize, + })) + } +} + impl std::ops::Add for Vec2 { type Output = Vec2; #[inline] -- cgit v1.2.3-70-g09d2