Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

coderabit suggestions

Richie McIlroy872ff3961e35
diff --git a/crates/frame-converter/src/d3d11.rs b/crates/frame-converter/src/d3d11.rs
index 397bbc955..694c4868a 100644
--- a/crates/frame-converter/src/d3d11.rs
+++ b/crates/frame-converter/src/d3d11.rs
@@ -498,7 +498,7 @@ impl FrameConverter for D3D11Converter {
fn pixel_to_dxgi(pixel: Pixel) -> Result<DXGI_FORMAT, ConvertError> {
match pixel {
Pixel::NV12 => Ok(DXGI_FORMAT_NV12),
- Pixel::YUYV422 | Pixel::UYVY422 => Ok(DXGI_FORMAT_YUY2),
+ Pixel::YUYV422 => Ok(DXGI_FORMAT_YUY2),
_ => Err(ConvertError::UnsupportedFormat(pixel, Pixel::NV12)),
}
}
@@ -567,7 +567,7 @@ unsafe fn copy_frame_to_mapped(frame: &frame::Video, dst: *mut u8, dst_stride: u
}
}
}
- Pixel::YUYV422 | Pixel::UYVY422 => {
+ Pixel::YUYV422 => {
let row_bytes = frame.width() as usize * 2;
for y in 0..height {
unsafe {
@@ -609,7 +609,7 @@ unsafe fn copy_mapped_to_frame(src: *const u8, src_stride: usize, frame: &mut fr
}
}
}
- Pixel::YUYV422 | Pixel::UYVY422 => {
+ Pixel::YUYV422 => {
let bytes_per_pixel = 2;
let row_bytes = frame.width() as usize * bytes_per_pixel;
for y in 0..height {
diff --git a/crates/recording/src/output_pipeline/win.rs b/crates/recording/src/output_pipeline/win.rs
index 419cc7159..6fb0bb27d 100644
--- a/crates/recording/src/output_pipeline/win.rs
+++ b/crates/recording/src/output_pipeline/win.rs
@@ -721,6 +721,22 @@ impl AudioMuxer for WindowsCameraMuxer {
}
}
+fn convert_uyvy_to_yuyv(src: &[u8], width: u32, height: u32) -> Vec<u8> {
+ let total_bytes = (width * height * 2) as usize;
+ let mut dst = vec![0u8; total_bytes];
+
+ for i in (0..src.len().min(total_bytes)).step_by(4) {
+ if i + 3 < src.len() && i + 3 < total_bytes {
+ dst[i] = src[i + 1];
+ dst[i + 1] = src[i];
+ dst[i + 2] = src[i + 3];
+ dst[i + 3] = src[i + 2];
+ }
+ }
+
+ dst
+}
+
fn upload_mf_buffer_to_texture(
device: &ID3D11Device,
frame: &NativeCameraFrame,
@@ -744,7 +760,19 @@ fn upload_mf_buffer_to_texture(
.lock()
.map_err(|_| windows::core::Error::from(windows::core::HRESULT(-1)))?;
let lock = buffer_guard.lock()?;
- let data = &*lock;
+ let original_data = &*lock;
+
+ let converted_buffer: Option<Vec<u8>>;
+ let data: &[u8] = if frame.pixel_format == cap_camera_windows::PixelFormat::UYVY422 {
+ converted_buffer = Some(convert_uyvy_to_yuyv(
+ original_data,
+ frame.width,
+ frame.height,
+ ));
+ converted_buffer.as_ref().unwrap()
+ } else {
+ original_data
+ };
let row_pitch = frame.width * bytes_per_pixel;