From 70e782612da076d7ac882db2b099e446792571d4 Mon Sep 17 00:00:00 2001 From: kageru Date: Wed, 25 Mar 2020 11:07:21 +0100 Subject: [PATCH] Add error message for invalid float input MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A few people encountered these. Looks like a few other filters don’t clip their limited range output properly. --- Cargo.toml | 2 +- src/mask.rs | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index dcd3b8d..e10dba8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "adaptivegrain-rs" -version = "0.2.0" +version = "0.2.1" authors = ["kageru"] edition = "2018" diff --git a/src/mask.rs b/src/mask.rs index bc3226a..7c48bfe 100644 --- a/src/mask.rs +++ b/src/mask.rs @@ -174,9 +174,25 @@ impl<'core> Filter<'core> for Mask<'core> { } } SampleType::Float => { + if let Err(e) = verify_input_range(&src_frame.props()) { + bail!(e); + } filter_for_float(&mut frame, src_frame, average, self.luma_scaling); } } Ok(frame.into()) } } + +fn verify_input_range<'a>(props: &vapoursynth::map::MapRef<'a, 'a>) -> Result<(), String> { + let max = props.get::("PlaneStatsMax").unwrap_or(1.0); + let min = props.get::("PlaneStatsMin").unwrap_or(0.0); + if min < 0.0 || max > 1.0 { + return Err(format!( + "{}: found invalid input. Some pixels are outside of the valid range. + You probably used a filter that operates on limited range without clipping properly, e.g. edgefixer, before converting to float. + This can be fixed by clipping all pixels to (0, 1) with Expr or converting to an integer format.", PLUGIN_NAME + )); + } + Ok(()) +}