Skip to content

Commit 75c42c4

Browse files
committed
Add image flipping support (SludgePhD#1)
1 parent f32ffaf commit 75c42c4

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

src/uvc.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ use crate::Device;
1313

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

16+
const HFLIP_UNIT_SELECTOR: u8 = 0x0c;
17+
const VFLIP_UNIT_SELECTOR: u8 = 0x0d;
18+
const UVC_EXTENSION_UNIT: u8 = 0x03;
19+
1620
/// `UVCH` meta capture format.
1721
#[derive(Clone, Copy, Debug)]
1822
pub struct UvcMetadata {
@@ -80,6 +84,46 @@ impl<'a> UvcExt<'a> {
8084
device: self.device,
8185
}
8286
}
87+
88+
pub fn horizontal_flip(&mut self) -> io::Result<()> {
89+
self.set_control(
90+
UVC_EXTENSION_UNIT,
91+
HFLIP_UNIT_SELECTOR,
92+
XuQuery::SET_CUR,
93+
&mut [1, 0],
94+
)
95+
}
96+
97+
pub fn vertical_flip(&mut self) -> io::Result<()> {
98+
self.set_control(
99+
UVC_EXTENSION_UNIT,
100+
VFLIP_UNIT_SELECTOR,
101+
XuQuery::SET_CUR,
102+
&mut [1, 0],
103+
)
104+
}
105+
106+
fn set_control<const SIZE: usize>(
107+
&self,
108+
unit: u8,
109+
selector: u8,
110+
query: XuQuery,
111+
data: &mut [u8; SIZE],
112+
) -> io::Result<()> {
113+
let mut query = XuControlQuery {
114+
unit,
115+
selector,
116+
query,
117+
size: SIZE as u16,
118+
data: data.as_mut_ptr(),
119+
};
120+
121+
unsafe {
122+
raw::ctrl_query(self.device.file.as_raw_fd(), &mut query)?;
123+
}
124+
125+
Ok(())
126+
}
83127
}
84128

85129
pub struct ExtensionUnit<'a> {

0 commit comments

Comments
 (0)