diff options
author | metamuffin <metamuffin@disroot.org> | 2025-05-05 15:09:54 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2025-05-05 15:09:54 +0200 |
commit | 306f96164784a8cbf405e72fa4364d6523366e95 (patch) | |
tree | 51717fc139871baa438aad806f4923669ae0896c /old/bv1/codec/src/frameio.rs | |
parent | 9cc089e2d6e841879e430b01d2f3d92c8820523e (diff) | |
download | video-codec-experiments-306f96164784a8cbf405e72fa4364d6523366e95.tar video-codec-experiments-306f96164784a8cbf405e72fa4364d6523366e95.tar.bz2 video-codec-experiments-306f96164784a8cbf405e72fa4364d6523366e95.tar.zst |
old dir
Diffstat (limited to 'old/bv1/codec/src/frameio.rs')
-rw-r--r-- | old/bv1/codec/src/frameio.rs | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/old/bv1/codec/src/frameio.rs b/old/bv1/codec/src/frameio.rs new file mode 100644 index 0000000..f6cbcbf --- /dev/null +++ b/old/bv1/codec/src/frameio.rs @@ -0,0 +1,35 @@ +use crate::{Frame, Pixel, PixelValue, P2}; +use std::io::{Read, Result, Write}; + +impl Frame { + pub fn read(inp: &mut impl Read, size: P2) -> Result<Frame> { + let mut f = Frame::new(size); + + for y in 0..size.y { + for x in 0..size.x { + let mut cc = [0u8; 3]; + inp.read_exact(&mut cc)?; + f[P2 { x, y }] = Pixel { + r: cc[0] as PixelValue, + g: cc[1] as PixelValue, + b: cc[2] as PixelValue, + }; + } + } + Ok(f) + } + + pub fn write(out: &mut impl Write, frame: &Frame) -> Result<()> { + for y in 0..frame.size.y { + for x in 0..frame.size.x { + let p = frame[P2 { x, y }]; + let mut cc = [0u8; 3]; + cc[0] = p.r.clamp(0, 255) as u8; + cc[1] = p.g.clamp(0, 255) as u8; + cc[2] = p.b.clamp(0, 255) as u8; + out.write_all(&mut cc)?; + } + } + Ok(()) + } +} |