diff --git a/Cargo.lock b/Cargo.lock index 71b88b3..85dd1a5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -548,7 +548,7 @@ dependencies = [ [[package]] name = "windows-capture" -version = "1.0.41" +version = "1.0.42" dependencies = [ "image", "log", @@ -560,7 +560,7 @@ dependencies = [ [[package]] name = "windows-capture-python" -version = "1.0.41" +version = "1.0.42" dependencies = [ "pyo3", "windows", diff --git a/Cargo.toml b/Cargo.toml index 62d609e..2f7bb72 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "windows-capture" -version = "1.0.41" +version = "1.0.42" authors = ["NiiightmareXD"] edition = "2021" description = "Fastest Windows Screen Capture Library For Rust 🔥" diff --git a/README.md b/README.md index 5a58ccf..0944692 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ Add this library to your `Cargo.toml`: ```toml [dependencies] -windows-capture = "1.0.41" +windows-capture = "1.0.42" ``` or run this command diff --git a/src/frame.rs b/src/frame.rs index c68f7ba..4b1524f 100644 --- a/src/frame.rs +++ b/src/frame.rs @@ -6,7 +6,8 @@ use rayon::iter::{IntoParallelIterator, ParallelIterator}; use windows::Win32::Graphics::{ Direct3D11::{ ID3D11Device, ID3D11DeviceContext, ID3D11Texture2D, D3D11_BOX, D3D11_CPU_ACCESS_READ, - D3D11_MAPPED_SUBRESOURCE, D3D11_MAP_READ, D3D11_TEXTURE2D_DESC, D3D11_USAGE_STAGING, + D3D11_CPU_ACCESS_WRITE, D3D11_MAPPED_SUBRESOURCE, D3D11_MAP_READ_WRITE, + D3D11_TEXTURE2D_DESC, D3D11_USAGE_STAGING, }, Dxgi::Common::{DXGI_FORMAT_B8G8R8A8_UNORM, DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_SAMPLE_DESC}, }; @@ -85,7 +86,7 @@ impl<'a> Frame<'a> { }, Usage: D3D11_USAGE_STAGING, BindFlags: 0, - CPUAccessFlags: D3D11_CPU_ACCESS_READ.0 as u32, + CPUAccessFlags: D3D11_CPU_ACCESS_READ.0 as u32 | D3D11_CPU_ACCESS_WRITE.0 as u32, MiscFlags: 0, }; @@ -105,14 +106,19 @@ impl<'a> Frame<'a> { // Map The Texture To Enable CPU Access let mut mapped_resource = D3D11_MAPPED_SUBRESOURCE::default(); unsafe { - self.context - .Map(&texture, 0, D3D11_MAP_READ, 0, Some(&mut mapped_resource))?; + self.context.Map( + &texture, + 0, + D3D11_MAP_READ_WRITE, + 0, + Some(&mut mapped_resource), + )?; }; // Get The Mapped Resource Data Slice let mapped_frame_data = unsafe { - slice::from_raw_parts( - mapped_resource.pData as *const u8, + slice::from_raw_parts_mut( + mapped_resource.pData.cast(), (self.height * mapped_resource.RowPitch) as usize, ) }; @@ -163,7 +169,7 @@ impl<'a> Frame<'a> { }, Usage: D3D11_USAGE_STAGING, BindFlags: 0, - CPUAccessFlags: D3D11_CPU_ACCESS_READ.0 as u32, + CPUAccessFlags: D3D11_CPU_ACCESS_READ.0 as u32 | D3D11_CPU_ACCESS_WRITE.0 as u32, MiscFlags: 0, }; @@ -202,14 +208,19 @@ impl<'a> Frame<'a> { // Map The Texture To Enable CPU Access let mut mapped_resource = D3D11_MAPPED_SUBRESOURCE::default(); unsafe { - self.context - .Map(&texture, 0, D3D11_MAP_READ, 0, Some(&mut mapped_resource))?; + self.context.Map( + &texture, + 0, + D3D11_MAP_READ_WRITE, + 0, + Some(&mut mapped_resource), + )?; }; // Get The Mapped Resource Data Slice let mapped_frame_data = unsafe { - slice::from_raw_parts( - mapped_resource.pData as *const u8, + slice::from_raw_parts_mut( + mapped_resource.pData.cast(), (texture_height * mapped_resource.RowPitch) as usize, ) }; @@ -243,7 +254,7 @@ impl<'a> Frame<'a> { /// Frame Buffer Struct Used To Get Raw Pixel Data pub struct FrameBuffer<'a> { - raw_buffer: &'a [u8], + raw_buffer: &'a mut [u8], buffer: &'a mut Vec, width: u32, height: u32, @@ -256,7 +267,7 @@ impl<'a> FrameBuffer<'a> { /// Create A New Frame Buffer #[must_use] pub fn new( - raw_buffer: &'a [u8], + raw_buffer: &'a mut [u8], buffer: &'a mut Vec, width: u32, height: u32, @@ -307,13 +318,15 @@ impl<'a> FrameBuffer<'a> { /// Get The Raw Pixel Data Might Have Padding #[must_use] - pub const fn as_raw_buffer(&self) -> &'a [u8] { + pub fn as_raw_buffer(&'a mut self) -> &'a mut [u8] { self.raw_buffer } /// Get The Raw Pixel Data Without Padding #[allow(clippy::type_complexity)] - pub fn as_raw_nopadding_buffer(&'a mut self) -> Result<&'a [u8], Box> { + pub fn as_raw_nopadding_buffer( + &'a mut self, + ) -> Result<&'a mut [u8], Box> { if !self.has_padding() { return Ok(self.raw_buffer); } @@ -339,7 +352,7 @@ impl<'a> FrameBuffer<'a> { } }); - Ok(&self.buffer[0..frame_size]) + Ok(&mut self.buffer[0..frame_size]) } /// Save The Frame Buffer As An Image To The Specified Path diff --git a/src/lib.rs b/src/lib.rs index 8a8effc..f8a75ba 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -22,7 +22,7 @@ //! //! ```toml //! [dependencies] -//! windows-capture = "1.0.41" +//! windows-capture = "1.0.42" //! ``` //! or run this command //! diff --git a/windows-capture-python/Cargo.lock b/windows-capture-python/Cargo.lock index 2770193..d205620 100644 --- a/windows-capture-python/Cargo.lock +++ b/windows-capture-python/Cargo.lock @@ -131,7 +131,7 @@ dependencies = [ [[package]] name = "flate2" -version = "1.0.41" +version = "1.0.42" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "46303f565772937ffe1d394a4fac6f411c6013172fadde9dcdb1e147a086940e" dependencies = [ diff --git a/windows-capture-python/Cargo.toml b/windows-capture-python/Cargo.toml index 0c46ada..782be72 100644 --- a/windows-capture-python/Cargo.toml +++ b/windows-capture-python/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "windows-capture-python" -version = "1.0.41" +version = "1.0.42" authors = ["NiiightmareXD"] edition = "2021" description = "Fastest Windows Screen Capture Library For Python 🔥" diff --git a/windows-capture-python/pyproject.toml b/windows-capture-python/pyproject.toml index 3313fa6..9f0f36d 100644 --- a/windows-capture-python/pyproject.toml +++ b/windows-capture-python/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "maturin" [project] name = "windows-capture" -version = "1.0.41" +version = "1.0.42" description = "Fastest Windows Screen Capture Library For Python 🔥" readme = "README.md" requires-python = ">=3.9" diff --git a/windows-capture-python/src/lib.rs b/windows-capture-python/src/lib.rs index b71bf65..c208e0b 100644 --- a/windows-capture-python/src/lib.rs +++ b/windows-capture-python/src/lib.rs @@ -216,7 +216,7 @@ impl NativeWindowsCapture { } if window_name.is_none() && monitor_index.is_none() { - monitor_index = Some(0); + monitor_index = Some(1); } Ok(Self { @@ -399,7 +399,7 @@ impl WindowsCaptureHandler for InnerNativeWindowsCapture { ) -> Result<(), Box<(dyn Error + Send + Sync)>> { let width = frame.width(); let height = frame.height(); - let buffer = frame.buffer()?; + let mut buffer = frame.buffer()?; let buffer = buffer.as_raw_buffer(); Python::with_gil(|py| -> PyResult<()> {