aboutsummaryrefslogtreecommitdiff
path: root/evc/src
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2022-12-06 19:30:03 +0100
committermetamuffin <metamuffin@disroot.org>2022-12-06 19:30:03 +0100
commit70514416c2ade2abe628efbd0a629a66febdeb13 (patch)
tree03b54f677046afe5a2e1b04768c1cb9104771462 /evc/src
parentc4e995d29209e0e0a1aafd9652971b8980fafb15 (diff)
downloadvideo-codec-experiments-70514416c2ade2abe628efbd0a629a66febdeb13.tar
video-codec-experiments-70514416c2ade2abe628efbd0a629a66febdeb13.tar.bz2
video-codec-experiments-70514416c2ade2abe628efbd0a629a66febdeb13.tar.zst
minor stuff, store translation as i8
Diffstat (limited to 'evc/src')
-rw-r--r--evc/src/block.rs6
-rw-r--r--evc/src/debug.rs11
-rw-r--r--evc/src/frame.rs5
-rw-r--r--evc/src/ser.rs12
-rw-r--r--evc/src/vec2.rs15
5 files changed, 42 insertions, 7 deletions
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::<Small<Vec2>>()?.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<Vec2> 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<Self> {
+ 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<T>(pub T);
+impl Ser for Small<Vec2> {
+ 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<Self> {
+ 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]