2019-05-30 13:06:53 +02:00
#[ macro_use ]
extern crate failure ;
#[ macro_use ]
extern crate vapoursynth ;
2020-05-24 20:46:23 +02:00
pub mod mask ;
2019-06-01 08:55:47 +02:00
2019-06-02 15:31:27 +02:00
use self ::mask ::Mask ;
2019-06-01 08:55:47 +02:00
use failure ::Error ;
use vapoursynth ::api ::API ;
2019-05-30 13:06:53 +02:00
use vapoursynth ::core ::CoreRef ;
2019-06-02 15:31:27 +02:00
use vapoursynth ::format ::SampleType ;
2019-05-30 13:06:53 +02:00
use vapoursynth ::map ::Map ;
use vapoursynth ::node ::Node ;
2020-02-19 20:17:16 +01:00
use vapoursynth ::plugins ::{ Filter , FilterArgument , Metadata } ;
2019-08-12 15:01:07 +02:00
use vapoursynth ::video_info ::Property ;
2019-05-30 13:06:53 +02:00
2019-06-01 08:55:47 +02:00
pub const PLUGIN_NAME : & str = " adaptivegrain " ;
pub const PLUGIN_IDENTIFIER : & str = " moe.kageru.adaptivegrain " ;
2019-05-30 13:06:53 +02:00
2019-06-01 08:55:47 +02:00
make_filter_function! {
MaskFunction , " Mask "
fn create_mask < ' core > (
_api : API ,
_core : CoreRef < ' core > ,
clip : Node < ' core > ,
luma_scaling : Option < f64 >
2019-06-02 14:43:53 +02:00
) -> Result < Option < Box < dyn Filter < ' core > + ' core > > , Error > {
2020-02-19 20:17:16 +01:00
let luma_scaling = luma_scaling . unwrap_or ( 10.0 ) as f32 ;
2019-06-02 14:43:53 +02:00
if let Property ::Constant ( format ) = clip . info ( ) . format {
2019-06-02 22:44:52 +02:00
if ! ( format . sample_type ( ) = = SampleType ::Float & & format . bits_per_sample ( ) ! = 32 ) {
2019-06-02 14:43:53 +02:00
return Ok ( Some ( Box ::new ( Mask {
source : clip ,
luma_scaling
} ) ) ) ;
2019-06-02 22:44:52 +02:00
} else {
bail! ( " Half precision float input is not supported " ) ;
2019-06-02 14:43:53 +02:00
}
}
2019-06-02 22:44:52 +02:00
bail! ( " Variable format input is not supported " )
2019-06-01 08:55:47 +02:00
}
}
2019-05-30 13:06:53 +02:00
export_vapoursynth_plugin! {
Metadata {
identifier : PLUGIN_IDENTIFIER ,
namespace : " adg " ,
name : " Adaptive grain " ,
read_only : false ,
} ,
2019-08-12 15:01:07 +02:00
[ MaskFunction ::new ( ) ]
2019-05-30 13:06:53 +02:00
}