feat: initial commit of SteamFrame FPV Control Center

This commit is contained in:
bleackstorm committed 2026-11-05 19:18:46 +01:00
commit 4459f5ffa4
18 files changed
+8571

No files matched your search

+91
View File
@@ -0,0 +1,91 @@
/// Modes de projection VR pour l'affichage du flux Eachine Sphere Link (140° FOV)
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ProjectionMode {
/// Dôme sphérique 140° (`XR_KHR_composition_layer_equirect2` + correction optique grand-angle)
Dome140,
/// Écran incurvé cylindrique 140° (`XR_KHR_composition_layer_cylinder`)
Cylinder140,
/// Écran plat verrouillé sur la tête (`XrCompositionLayerQuad`)
FlatQuad,
}
impl ProjectionMode {
pub fn from_str(s: &str) -> Self {
match s.to_lowercase().as_str() {
"cylinder" | "cyl" => Self::Cylinder140,
"flat" | "quad" => Self::FlatQuad,
_ => Self::Dome140,
}
}
pub fn label(&self) -> &'static str {
match self {
Self::Dome140 => "DOME 140",
Self::Cylinder140 => "CYL 140",
Self::FlatQuad => "QUAD",
}
}
}
/// Table de correspondance (LUT) précalculée pour corriger la distorsion en barillet
/// de la lentille M12 140° de l'Eachine Sphere Link et la projeter sur le dôme VR.
pub struct DomeWarpLut {
pub width: u32,
pub height: u32,
pub src_byte_offsets: Vec<usize>,
pub enabled: bool,
}
impl DomeWarpLut {
pub fn new(width: u32, height: u32, fov_deg: f32, k1: f32, k2: f32) -> Self {
let enabled = k1.abs() > 1e-4 || k2.abs() > 1e-4;
let total_pixels = (width * height) as usize;
let mut src_byte_offsets = Vec::with_capacity(total_pixels);
let aspect = width as f32 / height as f32;
let half_fov_rad = (fov_deg.to_radians() * 0.5).max(0.1);
let max_tan = (half_fov_rad * 0.65).tan().max(0.1);
for y in 0..height {
let ny = ((y as f32 + 0.5) / height as f32) * 2.0 - 1.0;
for x in 0..width {
let nx = ((x as f32 + 0.5) / width as f32) * 2.0 - 1.0;
let rx = nx * aspect;
let ry = ny;
let r2 = rx * rx + ry * ry;
let r4 = r2 * r2;
let factor = (1.0 + k1 * r2 + k2 * r4) / max_tan.min(1.15);
let src_nx = (nx * factor + 1.0) * 0.5;
let src_ny = (ny * factor + 1.0) * 0.5;
let sx = (src_nx * (width as f32 - 1.0)).round().clamp(0.0, (width - 1) as f32) as u32;
let sy = (src_ny * (height as f32 - 1.0)).round().clamp(0.0, (height - 1) as f32) as u32;
let byte_offset = ((sy * width + sx) * 4) as usize;
src_byte_offsets.push(byte_offset);
}
}
Self {
width,
height,
src_byte_offsets,
enabled,
}
}
pub fn apply(&self, input_rgba: &[u8], output_rgba: &mut [u8]) {
if !self.enabled || input_rgba.len() < (self.width * self.height * 4) as usize {
output_rgba.copy_from_slice(input_rgba);
return;
}
for (dst_pixel_idx, &src_byte_idx) in self.src_byte_offsets.iter().enumerate() {
let dst_byte_idx = dst_pixel_idx * 4;
output_rgba[dst_byte_idx..dst_byte_idx + 4]
.copy_from_slice(&input_rgba[src_byte_idx..src_byte_idx + 4]);
}
}
}