diff --git a/examples/live.rs b/examples/live.rs index 53ad1d9..8341a4c 100644 --- a/examples/live.rs +++ b/examples/live.rs @@ -67,7 +67,8 @@ fn main() -> anyhow::Result<()> { let mut out = v4l::Device::with_path(output)?; // To find the fourcc code, use v4l2-ctl --list-formats-out /dev/video0 // (or read the source :) - let format = v4l::Format::new(WIDTH as u32, HEIGHT as u32, fourcc); + // flip axes + let format = v4l::Format::new(HEIGHT as u32, WIDTH as u32, fourcc); Output::set_format(&out, &format)?; // Setup Capture @@ -105,13 +106,16 @@ fn main() -> anyhow::Result<()> { // swap the bytes, we are using LE, not BE, 16 bit grayscale // possibly limitation of current v4l2loopback or v4l rust wrapper or libv4l2 for i in 0..FRAME_LEN / 2 { + let x = i % WIDTH; + let y = (i / WIDTH) % HEIGHT; let mut pixel = u16::from_be_bytes([frame[i * 2], frame[i * 2 + 1]]); if greyscale { if args.temperature { pixel = pixel_to_celcius(pixel); } let pixel_swapped = pixel.to_le_bytes(); - swapped[i * 2..i * 2 + 2].copy_from_slice(&pixel_swapped); + let out_i = ((HEIGHT - 1 - y) + (WIDTH - 1 - x) * HEIGHT) * 2; + swapped[out_i..out_i + 2].copy_from_slice(&pixel_swapped); } else { pixel = pixel_to_celcius(pixel); let cutoff = args.red_cutoff.unwrap(); @@ -122,7 +126,8 @@ fn main() -> anyhow::Result<()> { }; let g = frame[i * 2]; let b = frame[i * 2 + 1]; - swapped[i * 4..i * 4 + 4].copy_from_slice(&[0, r, g, b]); + let out_i = (y + x * HEIGHT) * 2; + swapped[out_i..out_i + 4].copy_from_slice(&[0, r, g, b]); } } out.write_all(&swapped[..])?;