Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for BGR888 image format #82

Merged
merged 2 commits into from
Jan 20, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fix: don't coerce images to rgba
  • Loading branch information
vivienm committed Jan 8, 2024
commit 31cdddbf051a18290d4ab4fbfba7c9b7aeea9f6e
29 changes: 15 additions & 14 deletions libwayshot/src/image_util.rs
Original file line number Diff line number Diff line change
@@ -1,40 +1,41 @@
use image::{DynamicImage, RgbaImage};
use image::{DynamicImage, GenericImageView};
use wayland_client::protocol::wl_output::Transform;

pub(crate) fn rotate_image_buffer(
image: DynamicImage,
transform: Transform,
width: u32,
height: u32,
) -> RgbaImage {
let final_buffer = match transform {
Transform::_90 => image::imageops::rotate90(&image),
Transform::_180 => image::imageops::rotate180(&image),
Transform::_270 => image::imageops::rotate270(&image),
Transform::Flipped => image::imageops::flip_horizontal(&image),
) -> DynamicImage {
let final_image = match transform {
Transform::_90 => image::imageops::rotate90(&image).into(),
Transform::_180 => image::imageops::rotate180(&image).into(),
Transform::_270 => image::imageops::rotate270(&image).into(),
Transform::Flipped => image::imageops::flip_horizontal(&image).into(),
Transform::Flipped90 => {
let flipped_buffer = image::imageops::flip_horizontal(&image);
image::imageops::rotate90(&flipped_buffer)
image::imageops::rotate90(&flipped_buffer).into()
}
Transform::Flipped180 => {
let flipped_buffer = image::imageops::flip_horizontal(&image);
image::imageops::rotate180(&flipped_buffer)
image::imageops::rotate180(&flipped_buffer).into()
}
Transform::Flipped270 => {
let flipped_buffer = image::imageops::flip_horizontal(&image);
image::imageops::rotate270(&flipped_buffer)
image::imageops::rotate270(&flipped_buffer).into()
}
_ => image.into_rgba8(),
_ => image,
};

if final_buffer.dimensions() == (width, height) {
return final_buffer;
if final_image.dimensions() == (width, height) {
return final_image;
}

image::imageops::resize(
&final_buffer,
&final_image,
width,
height,
image::imageops::FilterType::Gaussian,
)
.into()
}
13 changes: 6 additions & 7 deletions libwayshot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use std::{
thread,
};

use image::{imageops::overlay, DynamicImage, RgbaImage};
use image::{imageops::overlay, DynamicImage};
use memmap2::MmapMut;
use wayland_client::{
globals::{registry_queue_init, GlobalList},
Expand Down Expand Up @@ -444,7 +444,7 @@ impl WayshotConnection {
&self,
capture_region: CaptureRegion,
cursor_overlay: bool,
) -> Result<RgbaImage> {
) -> Result<DynamicImage> {
let (frame_copies, (width, height)) =
self.create_frame_copy(capture_region, cursor_overlay)?;

Expand Down Expand Up @@ -500,23 +500,22 @@ impl WayshotConnection {
&self,
output_info: &OutputInfo,
cursor_overlay: bool,
) -> Result<RgbaImage> {
) -> Result<DynamicImage> {
let frame_copy = self.capture_output_frame(
cursor_overlay,
&output_info.wl_output,
output_info.transform,
None,
)?;
let image = DynamicImage::try_from(frame_copy)?;
Ok(image.into_rgba8())
frame_copy.try_into()
}

/// Take a screenshot from all of the specified outputs.
pub fn screenshot_outputs(
&self,
outputs: &Vec<OutputInfo>,
cursor_overlay: bool,
) -> Result<RgbaImage> {
) -> Result<DynamicImage> {
if outputs.is_empty() {
return Err(Error::NoOutputs);
}
Expand Down Expand Up @@ -551,7 +550,7 @@ impl WayshotConnection {
}

/// Take a screenshot from all accessible outputs.
pub fn screenshot_all(&self, cursor_overlay: bool) -> Result<RgbaImage> {
pub fn screenshot_all(&self, cursor_overlay: bool) -> Result<DynamicImage> {
self.screenshot_outputs(self.get_all_outputs(), cursor_overlay)
}
}
Loading