Skip to content

Commit

Permalink
chore: bump version
Browse files Browse the repository at this point in the history
  • Loading branch information
Decodetalkers committed Oct 4, 2024
1 parent bcaeb87 commit ec1e3ab
Show file tree
Hide file tree
Showing 9 changed files with 158 additions and 52 deletions.
5 changes: 3 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 31 additions & 11 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,38 +1,58 @@
[workspace.package]
version = "0.4.0"
edition = "2021"
license = "MIT"
description = "impl screencopy for wayland"
authors = ["Decodertalkers <[email protected]>"]
homepage = "https://github.com/Decodetalkers/haruhishot"
documentation = "https://docs.rs/libharuhishot/"
keywords = ["wayland"]

[package]
name = "haruhishot"
version = "0.3.19"
edition = "2021"
version.workspace = true
edition.workspace = true
license.workspace = true
description = "haruhishot"
authors.workspace = true
homepage.workspace = true
keywords.workspace = true
build = "build.rs"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[workspace]
members = [".", "libharuhishot"]

[dependencies]

libharuhishot = { path = "libharuhishot", version = "0.2.5" }

#wayland-client = "=0.30.0-beta.13"

[workspace.dependencies]
image = { version = "0.25", default-features = false, features = [
"jpeg",
"png",
"pnm",
] }
wayland-client = "0.31"
tracing-subscriber = "0.3.18"
tracing = "0.1.40"

[dependencies]

libharuhishot = { path = "libharuhishot", version = "0.4.0" }

#wayland-client = "=0.30.0-beta.13"
image.workspace = true

sctk = { version = "0.18.1", package = "smithay-client-toolkit", optional = true }

# in the feature
slint = { version = "1.8.0", optional = true }

tracing-subscriber = "0.3.18"
tracing = "0.1.40"
tracing-subscriber.workspace = true
tracing.workspace = true
clap = "4.5.19"
once_cell = "1.20.1"

dialoguer = { version = "0.11.0", features = ["fuzzy-select"] }

wayland-client = { version = "0.31", optional = true }
wayland-client = { workspace = true, optional = true }
notify-rust = { version = "4.11.3", optional = true, features = ["images"] }
xkbcommon = "0.8.0"
swayipc = { version = "3.0.2", optional = true }
Expand Down
14 changes: 8 additions & 6 deletions libharuhishot/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[package]
name = "libharuhishot"
version = "0.2.5"
edition = "2021"
license = "MIT"
version.workspace = true
edition.workspace = true
license.workspace = true
description = "impl screencopy for wayland"
authors = ["Decodertalkers <[email protected]>"]
homepage = "https://github.com/Decodetalkers/haruhishot"
authors.workspace = true
homepage.workspace = true
documentation = "https://docs.rs/libharuhishot/"
keywords = ["wayland"]
readme = "README.md"
Expand All @@ -23,7 +23,7 @@ wayland-protocols = { version = "0.32.4", default-features = false, features = [
wayland-protocols-wlr = { version = "0.3.4", default-features = false, features = [
"client",
] }
wayland-client = "0.31"
wayland-client.workspace = true
#wayland-client = "=0.30.0-beta.13"

nix = { version = "0.29.0", features = ["fs", "mman"] }
Expand All @@ -34,3 +34,5 @@ memmap2 = "0.9.5"
tracing = "0.1.40"

thiserror = "1.0.64"

image.workspace = true
81 changes: 81 additions & 0 deletions libharuhishot/src/convert.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
use image::ColorType;
use wayland_client::protocol::wl_shm;

pub trait Convert {
/// Convert raw image data into output type, return said type
fn convert_inplace(&self, data: &mut [u8]) -> ColorType;
}

#[derive(Default)]
struct ConvertBGR10;

#[derive(Default)]
struct ConvertNone;

#[derive(Default)]
struct ConvertRGB8;

#[derive(Default)]
struct ConvertBGR888;

const SHIFT10BITS_1: u32 = 20;
const SHIFT10BITS_2: u32 = 10;

/// Creates format converter based of input format, return None if conversion
/// isn't possible. Conversion is happening inplace.
pub fn create_converter(format: wl_shm::Format) -> Option<Box<dyn Convert>> {
match format {
wl_shm::Format::Xbgr8888 | wl_shm::Format::Abgr8888 => Some(Box::<ConvertNone>::default()),
wl_shm::Format::Xrgb8888 | wl_shm::Format::Argb8888 => Some(Box::<ConvertRGB8>::default()),
wl_shm::Format::Xbgr2101010 | wl_shm::Format::Abgr2101010 => {
Some(Box::<ConvertBGR10>::default())
}
wl_shm::Format::Bgr888 => Some(Box::<ConvertBGR888>::default()),
_ => None,
}
}

impl Convert for ConvertNone {
fn convert_inplace(&self, _data: &mut [u8]) -> ColorType {
ColorType::Rgba8
}
}

impl Convert for ConvertRGB8 {
fn convert_inplace(&self, data: &mut [u8]) -> ColorType {
for chunk in data.chunks_exact_mut(4) {
chunk.swap(0, 2);
}
ColorType::Rgba8
}
}

/// Simple conversion from 10 to 8 bits for one channel
fn convert10_to_8(color: u32) -> u8 {
((color >> 2) & 255) as u8
}

impl Convert for ConvertBGR10 {
fn convert_inplace(&self, data: &mut [u8]) -> ColorType {
for chunk in data.chunks_exact_mut(4) {
let pixel = ((chunk[3] as u32) << 24)
| ((chunk[2] as u32) << 16)
| ((chunk[1] as u32) << 8)
| chunk[0] as u32;
let r = convert10_to_8(pixel >> SHIFT10BITS_1);
let g = convert10_to_8(pixel >> SHIFT10BITS_2);
let b = convert10_to_8(pixel);
chunk[0] = b;
chunk[1] = g;
chunk[2] = r;
chunk[3] = 255;
}
ColorType::Rgba8
}
}

impl Convert for ConvertBGR888 {
fn convert_inplace(&self, _data: &mut [u8]) -> ColorType {
ColorType::Rgb8
}
}
2 changes: 2 additions & 0 deletions libharuhishot/src/haruhierror.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ pub enum HaruhiError {
QueueError(String),
#[error("Error in write image in shm")]
ShmError(#[from] io::Error),
#[error("Not Support format")]
NotSupportFormat
}
1 change: 1 addition & 0 deletions libharuhishot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
pub mod haruhierror;
pub mod wlrcopystate;
pub mod wlrshotbasestate;
pub mod convert;

pub use wlrcopystate::{FrameFormat, FrameInfo};
pub use wlrshotbasestate::HaruhiShotState;
Expand Down
15 changes: 13 additions & 2 deletions libharuhishot/src/wlrcopystate.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use image::ColorType;
use wayland_client::protocol::wl_buffer::WlBuffer;
use wayland_client::protocol::wl_output::{self, WlOutput};
use wayland_client::protocol::wl_shm::{self, Format};
Expand All @@ -21,6 +22,7 @@ use nix::{
unistd,
};

use crate::convert;
use memmap2::MmapMut;

use crate::haruhierror::HaruhiError;
Expand Down Expand Up @@ -81,6 +83,8 @@ pub struct FrameInfo {
pub frameformat: FrameFormat,
/// frame_mmap: contain the information of an image
pub frame_mmap: MmapMut,

pub frame_color_type: ColorType,
/// transform: how the screen is layed
pub transform: wl_output::Transform,
/// realwidth: same to above
Expand Down Expand Up @@ -321,11 +325,17 @@ impl HaruhiShotState {
height,
} => manager.capture_output_region(0, output, x, y, width, height, &qh, ()),
};
let mut frameformat = None;
let mut frame_mmap = None;
let mut frameformat: Option<FrameFormat> = None;
let mut frame_mmap: Option<MmapMut> = None;
let frame_color_type;
loop {
self.block_dispatch()?;
if self.finished() {
let frame_mmap = frame_mmap.as_mut().unwrap();
let frame_format = frameformat.as_ref().unwrap();
let frame_color_type_converter = convert::create_converter(frame_format.format)
.ok_or(HaruhiError::NotSupportFormat)?;
frame_color_type = frame_color_type_converter.convert_inplace(frame_mmap);
break;
}
if self.is_pedding() {
Expand Down Expand Up @@ -381,6 +391,7 @@ impl HaruhiShotState {
let output = FrameInfo {
frameformat: frameformat.unwrap(),
frame_mmap: frame_mmap.unwrap(),
frame_color_type,
transform,
realwidth: realwidth as u32,
realheight: realheight as u32,
Expand Down
42 changes: 15 additions & 27 deletions meson.build
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
project('haruhishot', 'rust',
version: '0.3.19',
meson_version: '>= 0.60'
)
project('haruhishot', 'rust', version: '0.4.0', meson_version: '>= 0.60')

dependency('wayland-client')

cargo = find_program('cargo', version: '>= 1.66')

rustc = find_program('rustc', version: '>= 1.66')
find_program('rustc', version: '>= 1.66')

command = [ cargo , 'build']
command = [cargo, 'build']

if get_option('enable-notify')
command += ['--features', 'notify']
Expand All @@ -34,39 +31,32 @@ command += [
'&&',
'cp',
meson.global_source_root() / 'target' / targetdir / meson.project_name(),
'@OUTPUT@'
'@OUTPUT@',
]

prefix = get_option('prefix')
bindir = prefix / get_option('bindir')
datadir = prefix / get_option('datadir')
icondir = datadir / 'pixmaps'

haruhishot_target = custom_target(meson.project_name(),
custom_target(
meson.project_name(),
output: meson.project_name(),
build_by_default: true,
install: true,
install_dir: bindir,
console: true,
command: command
command: command,
)

if get_option('enable-notify')
install_data('misc/haruhi_failed.png',
install_dir: icondir
)
install_data('misc/haruhi_successed.png',
install_dir: icondir
)
install_data('misc/haruhi_failed.png', install_dir: icondir)
install_data('misc/haruhi_successed.png', install_dir: icondir)
endif

if get_option('man-pages')
manpage = get_option('mandir')
scdoc = dependency(
'scdoc',
version: '>= 1.9.7',
native: true
)
scdoc = dependency('scdoc', version: '>= 1.9.7', native: true)

if scdoc.found()
custom_target(
Expand All @@ -77,18 +67,16 @@ if get_option('man-pages')
feed: true,
capture: true,
install: true,
install_dir: prefix / manpage / 'man1'
install_dir: prefix / manpage / 'man1',
)
endif
endif

# Install desktop entry
if get_option('desktop-entry')
install_data('misc/haruhishot.desktop',
install_dir: datadir / 'applications'
)
install_data('misc/haruhishot.svg',
install_dir: datadir / 'icons' / 'hicolor' / 'scalable' / 'apps'
install_data('misc/haruhishot.desktop', install_dir: datadir / 'applications')
install_data(
'misc/haruhishot.svg',
install_dir: datadir / 'icons' / 'hicolor' / 'scalable' / 'apps',
)
endif

8 changes: 4 additions & 4 deletions src/filewriter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub fn get_color(bufferdata: FrameInfo) {
&bufferdata.frame_mmap,
bufferdata.frameformat.width,
bufferdata.frameformat.height,
image::ColorType::Rgba8.into(),
bufferdata.frame_color_type.into(),
)
.unwrap();
let image =
Expand All @@ -43,7 +43,7 @@ pub fn write_to_file(bufferdata: FrameInfo, usestdout: bool) {
&bufferdata.frame_mmap,
bufferdata.frameformat.width,
bufferdata.frameformat.height,
image::ColorType::Rgba8.into(),
bufferdata.frame_color_type.into(),
) {
#[cfg(feature = "notify")]
let _ = Notification::new()
Expand Down Expand Up @@ -96,7 +96,7 @@ pub fn write_to_file(bufferdata: FrameInfo, usestdout: bool) {
&bufferdata.frame_mmap,
bufferdata.frameformat.width,
bufferdata.frameformat.height,
image::ColorType::Rgba8.into(),
bufferdata.frame_color_type.into(),
)
.is_ok()
{
Expand Down Expand Up @@ -183,7 +183,7 @@ pub fn write_to_file_mutisource(bufferdatas: Vec<FrameInfo>, usestdout: bool) {
&buffer.frame_mmap,
buffer.frameformat.width,
buffer.frameformat.height,
image::ColorType::Rgba8.into(),
buffer.frame_color_type.into(),
)
.unwrap();
let image =
Expand Down

0 comments on commit ec1e3ab

Please sign in to comment.