Skip to content

Commit 2bc0ea3

Browse files
committed
Update RustSynth to version 0.5.1 with various improvements and optimizations
- Enhanced frame processing in `lib.rs` for better performance by modifying pixel access patterns. - Bumped version numbers in `Cargo.toml` files for `rustsynth`, `rustsynth-derive`, and `rustsynth-sys` to 0.5.1. - Removed unused `FilterType` enum from `traits.rs` to clean up the codebase. - Improved error handling and safety in `frame.rs` by using raw pointer access for property retrieval and setting. - Added constants for property keys in `frame.rs` to avoid magic strings and improve readability. - Refactored property access methods to use unsafe raw access for performance gains.
1 parent af53632 commit 2bc0ea3

10 files changed

Lines changed: 379 additions & 184 deletions

File tree

Cargo.lock

Lines changed: 243 additions & 67 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/src/lib.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,18 +63,19 @@ mod plugin {
6363

6464
// Actually do the invert operation
6565
for plane in 0..vf.num_planes {
66-
let srcp = src.get_read_ptr(plane);
67-
let dstp = dst.get_write_ptr(plane);
66+
let mut srcp = src.get_read_ptr(plane);
67+
let mut dstp = dst.get_write_ptr(plane);
6868
let stride = src.get_stride(plane) as usize;
6969
let h = src.get_height(plane) as usize;
7070
let w = src.get_width(plane) as usize;
7171

72-
for y in 0..h {
73-
for x in 0..w {
74-
unsafe {
75-
let src_pixel = *srcp.add(y * stride + x);
76-
*dstp.add(y * stride + x) = !src_pixel;
72+
unsafe {
73+
for _y in 0..h {
74+
for x in 0..w {
75+
*dstp.add(x) = !(*srcp.add(x));
7776
}
77+
srcp = srcp.add(stride);
78+
dstp = dstp.add(stride);
7879
}
7980
}
8081
}

rustsynth-derive/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "rustsynth-derive"
33
description = "Procedual macro helpers for rustsynth"
4-
version = "0.5.0"
4+
version = "0.5.1"
55
edition = "2021"
66
license = "LGPL-2.1"
77
authors = ["Anima <contact@animafps.xyz>"]
@@ -16,4 +16,4 @@ proc-macro = true
1616
syn = { version = "2.0", features = ["full"] }
1717
quote = "1.0"
1818
proc-macro2 = "1.0"
19-
rustsynth = { version = "=0.5.0", path = "../rustsynth" }
19+
rustsynth = { version = "=0.5.1", path = "../rustsynth" }

rustsynth-sys/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "rustsynth-sys"
33
description = "Low level bindings to VapourSynth"
4-
version = "0.5.0"
4+
version = "0.5.1"
55
edition = "2021"
66
license = "LGPL-2.1"
77
authors = ["Anima <contact@animafps.xyz>"]

rustsynth-sys/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@ macro_rules! version {
2929
pub const VAPOURSYNTH_API_VERSION: i32 =
3030
version!(VAPOURSYNTH_API_MAJOR as i32, VAPOURSYNTH_API_MINOR as i32);
3131
pub const VSSCRIPT_API_VERSION: i32 =
32-
version!(VSSCRIPT_API_MAJOR as i32, VSSCRIPT_API_MINOR as i32);
32+
version!(VSSCRIPT_API_MAJOR as i32, VSSCRIPT_API_MINOR as i32);

rustsynth/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "rustsynth"
3-
version = "0.5.0"
3+
version = "0.5.1"
44
edition = "2021"
55
license = "LGPL-2.1"
66
description = "Safe VapourSynth wrapper"
@@ -10,11 +10,11 @@ categories = ["multimedia::video", "api-bindings"]
1010
keywords = ["vapoursynth"]
1111

1212
[dependencies]
13-
rustsynth-sys = { version = "=0.5.0", path = "../rustsynth-sys" }
13+
rustsynth-sys = { version = "=0.5.1", path = "../rustsynth-sys" }
1414
thiserror = "1.0"
1515
bitflags = "1.3"
1616
half = { version = "2.0", optional = true }
17-
futures = "0.3.31"
17+
futures = "0.3"
1818

1919
[features]
2020
# Enable the half::f16 type to be used for frame pixel data.

rustsynth/src/filter/mod.rs

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use rustsynth_sys::{VSActivationReason, VSFilterMode};
22

33
use crate::ffi;
44
use crate::ffi::VSRequestPattern;
5-
use crate::frame::{Frame, FrameContext};
65
use crate::node::Node;
76

87
pub struct FilterDependency {
@@ -96,34 +95,6 @@ impl FilterMode {
9695
}
9796
}
9897

99-
/// A filter’s “getframe” function. It is called by the core when it needs the filter to generate a frame.
100-
/// It is possible to allocate local data, persistent during the multiple calls requesting the output frame.
101-
/// In case of error, call setFilterError and return [None].
102-
/// Depending on the [FilterMode] set for the filter, multiple output frames could be requested concurrently.
103-
/// It is never called concurrently for the same frame number.
104-
///
105-
/// # Arguments
106-
///
107-
/// * `n`: Requested frame number.
108-
/// * `activation_reason`: This function is first called with [ActivationReason::Initial]. At this point the function should request the input frames it needs and return [None]. When one or all of the requested frames are ready, this function is called again with [ActivationReason::AllFramesReady]. The function should only return a frame when called with [ActivationReason::AllFramesReady].
109-
/// If a the function is called with [ActivationReason::Error] all processing has to be aborted and any.
110-
/// * `instance_data`: The filter’s private instance data.
111-
/// * `frame_data`: Optional private data associated with output frame number `n``. It must be deallocated before the last call for the given frame ([ActivationReason::AllFramesReady] or error).
112-
pub type FilterGetFrame<'a> = fn(
113-
n: i32,
114-
activation_reason: ActivationReason,
115-
instance_data: &mut [u8],
116-
frame_data: &mut Option<&mut [u8; 4]>,
117-
frame_ctx: &FrameContext,
118-
) -> Option<Frame<'a>>;
119-
120-
// Free callback signature
121-
pub type FilterFree = fn(instance_data: &mut [u8]);
122-
123-
// TODO!
124-
// - Filter Traits
125-
// - Export macros
126-
12798
pub mod traits;
12899

129100
// Macro to automatically register filters

rustsynth/src/filter/traits.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,6 @@ use crate::{
77
map::Map,
88
};
99

10-
pub enum FilterType {
11-
Video,
12-
Audio,
13-
}
14-
1510
/// Trait that filter structs must implement
1611
pub trait Filter {
1712
const NAME: &'static str;

rustsynth/src/format.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,10 @@ impl VideoFormat {
145145
pub(crate) fn from_ptr(from: *const ffi::VSVideoFormat) -> Self {
146146
let info = unsafe { &*from };
147147

148-
let sample_type = if info.sampleType == 0 {
148+
let sample_type = if info.sampleType == ffi::VSSampleType::stInteger as i32 {
149149
SampleType::Integer
150-
} else if info.sampleType == 1 {
151-
SampleType::Float
152150
} else {
153-
panic!("Sample type not valid")
151+
SampleType::Float
154152
};
155153

156154
let color_family = match info.colorFamily {
@@ -218,11 +216,10 @@ impl AudioFormat {
218216
let from = &*from;
219217
let sample_type = if from.sampleType == 0 {
220218
SampleType::Integer
221-
} else if from.sampleType == 1 {
222-
SampleType::Float
223219
} else {
224-
panic!("Sample type not valid")
220+
SampleType::Float
225221
};
222+
226223
Self {
227224
sample_type,
228225
bits_per_sample: from.bitsPerSample,

0 commit comments

Comments
 (0)