Remove experiments
This commit is contained in:
parent
c67dda5371
commit
13ac41ed97
|
@ -6,11 +6,8 @@ edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
failure = "0.1"
|
failure = "0.1"
|
||||||
#faster = { git = "https://github.com/AdamNiederer/faster.git" }
|
|
||||||
lazy_static = "1.3.0"
|
lazy_static = "1.3.0"
|
||||||
num = "0.2"
|
num = "0.2"
|
||||||
rand = "0.6"
|
|
||||||
rand_xorshift = "0.1"
|
|
||||||
vapoursynth = "0.2"
|
vapoursynth = "0.2"
|
||||||
vapoursynth-sys = "0.2"
|
vapoursynth-sys = "0.2"
|
||||||
|
|
||||||
|
|
66
src/grain.rs
66
src/grain.rs
|
@ -1,66 +0,0 @@
|
||||||
use failure::Error;
|
|
||||||
use num::Integer;
|
|
||||||
use rand::distributions::Uniform;
|
|
||||||
use rand::Rng;
|
|
||||||
use rand_xorshift::XorShiftRng;
|
|
||||||
use vapoursynth::api::API;
|
|
||||||
use vapoursynth::core::CoreRef;
|
|
||||||
use vapoursynth::frame::{FrameRef, FrameRefMut};
|
|
||||||
use vapoursynth::node::Node;
|
|
||||||
use vapoursynth::plugins::{Filter, FrameContext};
|
|
||||||
use vapoursynth::video_info::VideoInfo;
|
|
||||||
|
|
||||||
pub struct Grain<'core> {
|
|
||||||
pub source: Node<'core>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn clip<T: Integer>(input: T, lower: T, upper: T) -> T {
|
|
||||||
input.min(upper).max(lower)
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'core> Filter<'core> for Grain<'core> {
|
|
||||||
fn video_info(&self, _api: API, _core: CoreRef<'core>) -> Vec<VideoInfo<'core>> {
|
|
||||||
vec![self.source.info()]
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_frame_initial(
|
|
||||||
&self,
|
|
||||||
_api: API,
|
|
||||||
_core: CoreRef<'core>,
|
|
||||||
context: FrameContext,
|
|
||||||
n: usize,
|
|
||||||
) -> Result<Option<FrameRef<'core>>, Error> {
|
|
||||||
self.source.request_frame_filter(context, n);
|
|
||||||
Ok(None)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_frame(
|
|
||||||
&self,
|
|
||||||
_api: API,
|
|
||||||
core: CoreRef<'core>,
|
|
||||||
context: FrameContext,
|
|
||||||
n: usize,
|
|
||||||
) -> Result<FrameRef<'core>, Error> {
|
|
||||||
let frame = self.source.get_frame_filter(context, n).ok_or_else(|| {
|
|
||||||
format_err!("Could not retrieve source frame. This shouldn’t happen.")
|
|
||||||
})?;
|
|
||||||
let var = 20i16;
|
|
||||||
// these have to be defined explicitly for lifetime reasons
|
|
||||||
//let mut rng = thread_rng();
|
|
||||||
let distribution = Uniform::new_inclusive(-var, var);
|
|
||||||
let mut rng: XorShiftRng = rand::SeedableRng::seed_from_u64(653334623);
|
|
||||||
let mut spread = rng.sample_iter(&distribution);
|
|
||||||
|
|
||||||
let mut frame = FrameRefMut::copy_of(core, &frame);
|
|
||||||
for plane in 0..frame.format().plane_count() {
|
|
||||||
for row in 0..frame.height(plane) {
|
|
||||||
for mut_pixel in frame.plane_row_mut::<u8>(plane, row) {
|
|
||||||
let pixel = *mut_pixel as i16 + spread.next().unwrap();
|
|
||||||
*mut_pixel = clip(pixel, 0, 255) as u8;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Ok(frame.into())
|
|
||||||
}
|
|
||||||
}
|
|
96
src/lib.rs
96
src/lib.rs
|
@ -5,101 +5,23 @@ extern crate lazy_static;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate vapoursynth;
|
extern crate vapoursynth;
|
||||||
|
|
||||||
mod grain;
|
|
||||||
mod mask;
|
mod mask;
|
||||||
|
|
||||||
use self::grain::Grain;
|
|
||||||
use self::mask::Mask;
|
use self::mask::Mask;
|
||||||
use failure::Error;
|
use failure::Error;
|
||||||
use vapoursynth::api::API;
|
use vapoursynth::api::API;
|
||||||
use vapoursynth::core::CoreRef;
|
use vapoursynth::core::CoreRef;
|
||||||
use vapoursynth::format::SampleType;
|
use vapoursynth::format::SampleType;
|
||||||
use vapoursynth::frame::{FrameRef, FrameRefMut};
|
|
||||||
use vapoursynth::map::Map;
|
use vapoursynth::map::Map;
|
||||||
use vapoursynth::node::Node;
|
use vapoursynth::node::Node;
|
||||||
use vapoursynth::plugins::{Filter, FilterArgument, FrameContext, Metadata};
|
use vapoursynth::plugins::{Filter, FilterArgument, Metadata };
|
||||||
use vapoursynth::video_info::{Property, VideoInfo};
|
use vapoursynth::video_info::Property;
|
||||||
|
|
||||||
pub const PLUGIN_NAME: &str = "adaptivegrain";
|
pub const PLUGIN_NAME: &str = "adaptivegrain";
|
||||||
pub const PLUGIN_IDENTIFIER: &str = "moe.kageru.adaptivegrain";
|
pub const PLUGIN_IDENTIFIER: &str = "moe.kageru.adaptivegrain";
|
||||||
|
|
||||||
struct AdaptiveGrain<'core> {
|
|
||||||
source: Node<'core>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'core> Filter<'core> for AdaptiveGrain<'core> {
|
|
||||||
fn video_info(&self, _api: API, _core: CoreRef<'core>) -> Vec<VideoInfo<'core>> {
|
|
||||||
vec![self.source.info()]
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_frame_initial(
|
|
||||||
&self,
|
|
||||||
_api: API,
|
|
||||||
_core: CoreRef<'core>,
|
|
||||||
context: FrameContext,
|
|
||||||
n: usize,
|
|
||||||
) -> Result<Option<FrameRef<'core>>, Error> {
|
|
||||||
self.source.request_frame_filter(context, n);
|
|
||||||
Ok(None)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_frame(
|
|
||||||
&self,
|
|
||||||
_api: API,
|
|
||||||
core: CoreRef<'core>,
|
|
||||||
context: FrameContext,
|
|
||||||
n: usize,
|
|
||||||
) -> Result<FrameRef<'core>, Error> {
|
|
||||||
let frame = self.source.get_frame_filter(context, n).ok_or_else(|| {
|
|
||||||
format_err!("Could not retrieve source frame. This shouldn’t happen.")
|
|
||||||
})?;
|
|
||||||
let average = match frame.props().get::<f64>("PlaneStatsAverage") {
|
|
||||||
Ok(average) => (average * 256.0) as u8,
|
|
||||||
Err(_) => panic!(
|
|
||||||
PLUGIN_NAME.to_owned()
|
|
||||||
+ ": You need to run std.PlaneStats on the clip before calling this function."
|
|
||||||
),
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut frame = FrameRefMut::copy_of(core, &frame);
|
|
||||||
for plane in 0..frame.format().plane_count() {
|
|
||||||
for row in 0..frame.height(plane) {
|
|
||||||
for pixel in frame.plane_row_mut::<u8>(plane, row) {
|
|
||||||
*pixel = average;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Ok(frame.into())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
make_filter_function! {
|
|
||||||
AdaptiveGrainFunction, "AdaptiveGrain"
|
|
||||||
|
|
||||||
fn create_adaptivegrain<'core>(
|
|
||||||
_api: API,
|
|
||||||
_core: CoreRef<'core>,
|
|
||||||
clip: Node<'core>,
|
|
||||||
) -> Result<Option<Box<dyn Filter<'core> + 'core>>, Error> {
|
|
||||||
Ok(Some(Box::new(AdaptiveGrain { source: clip })))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
make_filter_function! {
|
|
||||||
GrainFunction, "Grain"
|
|
||||||
|
|
||||||
fn create_grain<'core>(
|
|
||||||
_api: API,
|
|
||||||
_core: CoreRef<'core>,
|
|
||||||
clip: Node<'core>,
|
|
||||||
) -> Result<Option<Box<dyn Filter<'core> + 'core>>, Error> {
|
|
||||||
Ok(Some(Box::new(Grain { source: clip })))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
make_filter_function! {
|
make_filter_function! {
|
||||||
MaskFunction, "Mask"
|
MaskFunction, "Mask"
|
||||||
|
|
||||||
fn create_mask<'core>(
|
fn create_mask<'core>(
|
||||||
_api: API,
|
_api: API,
|
||||||
_core: CoreRef<'core>,
|
_core: CoreRef<'core>,
|
||||||
|
@ -131,17 +53,5 @@ export_vapoursynth_plugin! {
|
||||||
name: "Adaptive grain",
|
name: "Adaptive grain",
|
||||||
read_only: false,
|
read_only: false,
|
||||||
},
|
},
|
||||||
[
|
[ MaskFunction::new() ]
|
||||||
//AdaptiveGrainFunction::new(),
|
|
||||||
//GrainFunction::new(),
|
|
||||||
MaskFunction::new()
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
#[test]
|
|
||||||
fn it_works() {
|
|
||||||
assert_eq!(2 + 2, 4);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user