diff options
author | metamuffin <metamuffin@disroot.org> | 2022-12-05 21:22:00 +0100 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2022-12-05 21:22:00 +0100 |
commit | 8e4ec0943973b96addbe01f4c02f91cf04d081a7 (patch) | |
tree | 0773eb5048703adae45538050ab3dffad29b01da | |
parent | 96e316ea16b7b915e02735457d5ac7495d3db305 (diff) | |
download | video-codec-experiments-8e4ec0943973b96addbe01f4c02f91cf04d081a7.tar video-codec-experiments-8e4ec0943973b96addbe01f4c02f91cf04d081a7.tar.bz2 video-codec-experiments-8e4ec0943973b96addbe01f4c02f91cf04d081a7.tar.zst |
more code
-rw-r--r-- | evc/src/bin/encode.rs | 23 | ||||
-rw-r--r-- | evc/src/block.rs | 20 | ||||
-rw-r--r-- | evc/src/frame.rs | 18 | ||||
-rw-r--r-- | evc/src/header.rs | 21 | ||||
-rw-r--r-- | evc/src/lib.rs | 2 | ||||
-rw-r--r-- | evc/src/pixel.rs | 19 |
6 files changed, 77 insertions, 26 deletions
diff --git a/evc/src/bin/encode.rs b/evc/src/bin/encode.rs index 88023b3..1090831 100644 --- a/evc/src/bin/encode.rs +++ b/evc/src/bin/encode.rs @@ -1,20 +1,29 @@ -use std::io::BufReader; - use clap::Parser; -use evc::ser::Source; +use evc::{pixel::Pixel, ser::Source}; +use std::io::{self, BufReader}; #[derive(Parser)] #[clap(about, version)] pub struct EncodeArgs { - #[arg(short, long)] + #[arg(short = 'W', long)] width: usize, - #[arg(short, long)] + #[arg(short = 'H', long)] height: usize, } -fn main() { +fn main() -> io::Result<()> { + let args = EncodeArgs::parse(); + let mut input = BufReader::new(std::io::stdin()); - + loop { + for x in 0..args.width { + for y in 0..args.height { + let pixel = input.get::<Pixel>()?; + println!("P({x}|{y}) = {pixel:?}") + } + } + } + Ok(()) } diff --git a/evc/src/block.rs b/evc/src/block.rs index 29dd4ba..8d98d55 100644 --- a/evc/src/block.rs +++ b/evc/src/block.rs @@ -1,11 +1,5 @@ -use crate::ser::{Ser, Sink, Source}; +use crate::{ser::{Ser, Sink, Source}, pixel::Pixel}; -#[derive(Copy, Clone, Debug)] -pub struct Pixel { - pub r: u8, - pub g: u8, - pub b: u8, -} #[derive(Clone, Debug)] pub struct Block { @@ -56,14 +50,4 @@ impl Block { Ok(Self { size, inner }) } -} -impl Ser for Pixel { - fn write(&self, sink: &mut impl std::io::Write) -> std::io::Result<()> { - sink.put((self.r, self.g, self.b)) - } - - fn read(source: &mut impl std::io::Read) -> std::io::Result<Self> { - let (r, g, b) = source.get()?; - Ok(Self { r, g, b }) - } -} +}
\ No newline at end of file diff --git a/evc/src/frame.rs b/evc/src/frame.rs new file mode 100644 index 0000000..8e90832 --- /dev/null +++ b/evc/src/frame.rs @@ -0,0 +1,18 @@ +use crate::pixel::Pixel; + + +pub struct Frame { + size: (usize, usize), + buffer: Vec<Vec<Pixel>>, +} + +impl Frame { + pub fn new(size: (usize, usize)) -> Self { + Self { + size, + buffer: (0..size.0) + .map(|_| (0..size.1).map(|_| Pixel::default()).collect()) + .collect(), + } + } +} diff --git a/evc/src/header.rs b/evc/src/header.rs index 2b2725c..e5f008d 100644 --- a/evc/src/header.rs +++ b/evc/src/header.rs @@ -1,4 +1,23 @@ +use crate::ser::{Ser, Sink, Source}; +#[derive(Debug, Clone)] pub struct Header { - + pub resolution: (usize, usize), + pub frame_count: usize, +} + +impl Ser for Header { + fn write(&self, sink: &mut impl std::io::Write) -> std::io::Result<()> { + sink.put([0x5eu8, 0xb1u8, 0xc3u8, 0x08u8])?; + sink.put((self.resolution, self.frame_count))?; + Ok(()) + } + + fn read(source: &mut impl std::io::Read) -> std::io::Result<Self> { + source.get::<[u8; 4]>()?; + Ok(Self { + resolution: source.get()?, + frame_count: source.get()?, + }) + } } diff --git a/evc/src/lib.rs b/evc/src/lib.rs index 3270ebb..26255d7 100644 --- a/evc/src/lib.rs +++ b/evc/src/lib.rs @@ -3,3 +3,5 @@ pub mod ser; pub mod block; pub mod header; +pub mod frame; +pub mod pixel; diff --git a/evc/src/pixel.rs b/evc/src/pixel.rs new file mode 100644 index 0000000..adeaf84 --- /dev/null +++ b/evc/src/pixel.rs @@ -0,0 +1,19 @@ +use crate::ser::{Ser, Sink, Source}; + +#[derive(Copy, Clone, Debug, Default)] +pub struct Pixel { + pub r: u8, + pub g: u8, + pub b: u8, +} + +impl Ser for Pixel { + fn write(&self, sink: &mut impl std::io::Write) -> std::io::Result<()> { + sink.put((self.r, self.g, self.b)) + } + + fn read(source: &mut impl std::io::Read) -> std::io::Result<Self> { + let (r, g, b) = source.get()?; + Ok(Self { r, g, b }) + } +} |