Skip to content

Commit

Permalink
Add image flipping support (SludgePhD#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
Aemulation committed Oct 8, 2024
1 parent f32ffaf commit 75c42c4
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions src/uvc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ use crate::Device;

use self::raw::{XuControlQuery, XuQuery};

const HFLIP_UNIT_SELECTOR: u8 = 0x0c;
const VFLIP_UNIT_SELECTOR: u8 = 0x0d;
const UVC_EXTENSION_UNIT: u8 = 0x03;

/// `UVCH` meta capture format.
#[derive(Clone, Copy, Debug)]
pub struct UvcMetadata {
Expand Down Expand Up @@ -80,6 +84,46 @@ impl<'a> UvcExt<'a> {
device: self.device,
}
}

pub fn horizontal_flip(&mut self) -> io::Result<()> {
self.set_control(
UVC_EXTENSION_UNIT,
HFLIP_UNIT_SELECTOR,
XuQuery::SET_CUR,
&mut [1, 0],
)
}

pub fn vertical_flip(&mut self) -> io::Result<()> {
self.set_control(
UVC_EXTENSION_UNIT,
VFLIP_UNIT_SELECTOR,
XuQuery::SET_CUR,
&mut [1, 0],
)
}

fn set_control<const SIZE: usize>(
&self,
unit: u8,
selector: u8,
query: XuQuery,
data: &mut [u8; SIZE],
) -> io::Result<()> {
let mut query = XuControlQuery {
unit,
selector,
query,
size: SIZE as u16,
data: data.as_mut_ptr(),
};

unsafe {
raw::ctrl_query(self.device.file.as_raw_fd(), &mut query)?;
}

Ok(())
}
}

pub struct ExtensionUnit<'a> {
Expand Down

0 comments on commit 75c42c4

Please sign in to comment.