From 611f566c68fe21373c7cd603cc463a3c34e1d7e0 Mon Sep 17 00:00:00 2001 From: WolframRhodium Date: Thu, 9 Sep 2021 11:11:14 +0800 Subject: [PATCH] Fix invalid array param-type str in AVS+ --- cpu_source/source_avs.cpp | 22 ++++++++-------------- source/source_avs.cpp | 19 +++++++------------ 2 files changed, 15 insertions(+), 26 deletions(-) diff --git a/cpu_source/source_avs.cpp b/cpu_source/source_avs.cpp index 2846179..c63da00 100644 --- a/cpu_source/source_avs.cpp +++ b/cpu_source/source_avs.cpp @@ -110,7 +110,7 @@ PVideoFrame __stdcall BM3DFilter::GetFrame(int n, IScriptEnvironment* env) { PVideoFrame dst = env->NewVideoFrameP(vi, const_cast(&src_frame)); const auto cast_fp = [](auto * p) { - if constexpr (std::is_same_v, decltype(p)>) + if constexpr (std::is_const_v>) return reinterpret_cast(p); else return reinterpret_cast(p); @@ -148,7 +148,7 @@ PVideoFrame __stdcall BM3DFilter::GetFrame(int n, IScriptEnvironment* env) { 32, AVS_POOLED_ALLOC ); - return reinterpret_cast(p); + return cast_fp(p); } else { return nullptr; } @@ -233,7 +233,7 @@ PVideoFrame __stdcall BM3DFilter::GetFrame(int n, IScriptEnvironment* env) { }(); std::array dstps { - reinterpret_cast(dst->GetWritePtr(planes_id[plane])) + cast_fp(dst->GetWritePtr(planes_id[plane])) }; const int width = src_frame->GetRowSize(planes_id[plane]) / sizeof(float); @@ -246,7 +246,7 @@ PVideoFrame __stdcall BM3DFilter::GetFrame(int n, IScriptEnvironment* env) { sizeof(float) * stride * height * 2 * num_planes(chroma), 32, AVS_POOLED_ALLOC); - return reinterpret_cast(p); + return cast_fp(p); } else { return nullptr; } @@ -362,9 +362,9 @@ BM3DFilter::BM3DFilter(AVSValue args, IScriptEnvironment* env) auto array_loader = [](const AVSValue & arg, const auto default_value) { using T = std::remove_const_t; std::array ret; - if (!arg.Defined()) { + if (!arg.Defined() || arg.ArraySize() == 0) { ret.fill(default_value); - } else if (arg.IsArray()) { + } else { int length = std::min(arg.ArraySize(), 3); for (int i = 0; i < length; ++i) { if constexpr (std::is_same_v) { @@ -376,12 +376,6 @@ BM3DFilter::BM3DFilter(AVSValue args, IScriptEnvironment* env) for (int i = length; i < 3; ++i) { ret[i] = ret[i - 1]; } - } else { - if constexpr (std::is_same_v) { - ret.fill(static_cast(arg.AsFloat(default_value))); - } else if (std::is_same_v) { - ret.fill(arg.AsInt(default_value)); - } } return ret; }; @@ -460,8 +454,8 @@ const char* __stdcall AvisynthPluginInit3( env->AddFunction("BM3D_CPU", "c[ref]c" - "[sigma]f[block_step]i[bm_range]" - "i[radius]i[ps_num]i[ps_range]i[chroma]b" + "[sigma]f+[block_step]i+[bm_range]i+" + "[radius]i[ps_num]i+[ps_range]i+[chroma]b" , BM3DFilter::Create, nullptr); return "BM3D algorithm (AVX2 version)"; diff --git a/source/source_avs.cpp b/source/source_avs.cpp index 2450ab3..d21a12f 100755 --- a/source/source_avs.cpp +++ b/source/source_avs.cpp @@ -396,11 +396,12 @@ BM3DFilter::BM3DFilter(AVSValue args, IScriptEnvironment* env) } } - auto array_loader = [](const AVSValue & arg, T default_value) { + auto array_loader = [](const AVSValue & arg, const auto default_value) { + using T = std::remove_const_t; std::array ret; - if (!arg.Defined()) { + if (!arg.Defined() || arg.ArraySize() == 0) { ret.fill(default_value); - } else if (arg.IsArray()) { + } else { int length = std::min(arg.ArraySize(), 3); for (int i = 0; i < length; ++i) { if constexpr (std::is_same_v) { @@ -412,12 +413,6 @@ BM3DFilter::BM3DFilter(AVSValue args, IScriptEnvironment* env) for (int i = length; i < 3; ++i) { ret[i] = ret[i - 1]; } - } else { - if constexpr (std::is_same_v) { - ret.fill(static_cast(arg.AsFloat(default_value))); - } else if (std::is_same_v) { - ret.fill(arg.AsInt(default_value)); - } } return ret; }; @@ -607,9 +602,9 @@ const char* __stdcall AvisynthPluginInit3( env->AddFunction("BM3D_CUDA", "c[ref]c" - "[sigma]f[block_step]i[bm_range]" - "i[radius]i[ps_num]i[ps_range]" - "i[chroma]b[device_id]i[fast]b[extractor_exp]i" + "[sigma]f+[block_step]i+[bm_range]i+" + "[radius]i[ps_num]i+[ps_range]i+" + "[chroma]b[device_id]i[fast]b[extractor_exp]i" , BM3DFilter::Create, nullptr); return "BM3D algorithm";