From 76b158a6be46384d3daf22c93059133fe6660746 Mon Sep 17 00:00:00 2001 From: OKA Motofumi Date: Tue, 2 Aug 2016 00:29:46 +0900 Subject: [PATCH] add avs2.6 support. also, add version resource. --- .gitignore | 1 + readme.md | 11 +---- src/DCTFilter.cpp | 84 +++++++++++++++++++++++---------------- src/DCTFilter.rc | Bin 0 -> 4938 bytes vs2015/DCTFilter.vcxproj | 3 ++ 5 files changed, 56 insertions(+), 43 deletions(-) create mode 100644 src/DCTFilter.rc diff --git a/.gitignore b/.gitignore index 6b3cad5..99eef51 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ archives/* *.opendb *.filters *.user +*.aps *.dll *.exe diff --git a/readme.md b/readme.md index d2aaaa8..87bb475 100644 --- a/readme.md +++ b/readme.md @@ -1,14 +1,13 @@ ##DCTFilter -### DCT / iDCT filter for Avisynth+ This plugin is a rewrite of DctFilter for avisynth. ### Version: - 0.2.0 + 0.3.0 ### Requirement: - Windows Vista sp2 or later - SSE2 capable CPU - - Avisynth+MT r2085 or later + - Avisynth 2.60 / Avisynth+MT r2085 or later - Microsoft VisualC++ Redistributable Package 2015. ### Usage: @@ -64,9 +63,3 @@ PERFORMANCE OF THIS SOFTWARE. ### Source code: https://github.com/chikuzen/DCTFilter - - - - - - diff --git a/src/DCTFilter.cpp b/src/DCTFilter.cpp index 1dce46f..cfd22a2 100644 --- a/src/DCTFilter.cpp +++ b/src/DCTFilter.cpp @@ -21,11 +21,17 @@ PERFORMANCE OF THIS SOFTWARE. #include #include +#include +#define WIN32_LEAN_AND_MEAN +#define NOMINMAX +#define NOGDI +#define VC_EXTRALEAN +#include #include -#include -#include -#define DCT_FILTER_VERSION "0.1.0" + + +#define DCT_FILTER_VERSION "0.3.0" typedef IScriptEnvironment ise_t; @@ -44,12 +50,14 @@ class DCTFilter : public GenericVideoFilter { int numPlanes; int planes[3]; int chroma; + bool isPlus; float* factors; dct_idct_func_t mainProc; public: - DCTFilter(PClip child, double* factor, int diag_count, int chroma, int opt); + DCTFilter(PClip child, double* factor, int diag_count, int chroma, int opt, + bool is_plus); PVideoFrame __stdcall GetFrame(int n, ise_t* env); ~DCTFilter(); int __stdcall SetCacheHints(int hints, int) @@ -59,8 +67,9 @@ class DCTFilter : public GenericVideoFilter { }; -DCTFilter::DCTFilter(PClip c, double* f, int diag_count, int ch, int opt) - : GenericVideoFilter(c), chroma(ch) +DCTFilter::DCTFilter(PClip c, double* f, int diag_count, int ch, int opt, + bool ip) + : GenericVideoFilter(c), chroma(ch), isPlus(ip) { if (!vi.IsPlanar()) { throw std::runtime_error("input is not planar format."); @@ -80,16 +89,27 @@ DCTFilter::DCTFilter(PClip c, double* f, int diag_count, int ch, int opt) numPlanes = 1; } + if (vi.IsYUV()) { + planes[0] = PLANAR_Y; + planes[1] = PLANAR_U; + planes[2] = PLANAR_V; + } else { + planes[0] = PLANAR_G; + planes[1] = PLANAR_B; + planes[2] = PLANAR_R; + } + if (chroma == 1) { - int w = vi.width >> vi.GetPlaneWidthSubsampling(PLANAR_U); - int h = vi.height >> vi.GetPlaneHeightSubsampling(PLANAR_U); + int w = vi.width >> vi.GetPlaneWidthSubsampling(planes[1]); + int h = vi.height >> vi.GetPlaneHeightSubsampling(planes[1]); if ((w | h) & 7) { throw std::runtime_error( "second plane's width and height must be mod 8."); } } - factors = reinterpret_cast(avs_malloc(64 * sizeof(float), 32)); + size_t size = (64 + (isPlus ? 0 : 128)) * sizeof(float); + factors = reinterpret_cast(_aligned_malloc(size, 32)); if (!factors) { throw std::runtime_error("failed to create table of factors."); } @@ -108,16 +128,6 @@ DCTFilter::DCTFilter(PClip c, double* f, int diag_count, int ch, int opt) } } - if (vi.IsYUV()) { - planes[0] = PLANAR_Y; - planes[1] = PLANAR_U; - planes[2] = PLANAR_V; - } else { - planes[0] = PLANAR_G; - planes[1] = PLANAR_B; - planes[2] = PLANAR_R; - } - if (opt == 0 || !has_sse2()) { opt = 0; } else if (opt == 1 || !has_sse41()) { @@ -128,28 +138,31 @@ DCTFilter::DCTFilter(PClip c, double* f, int diag_count, int ch, int opt) opt = 3; } - mainProc = get_main_proc(vi.ComponentSize(), opt); + mainProc = get_main_proc(vi.BytesFromPixels(1), opt); } DCTFilter::~DCTFilter() { - avs_free(factors); + _aligned_free(factors); factors = nullptr; } PVideoFrame __stdcall DCTFilter::GetFrame(int n, ise_t* env) { - auto env2 = static_cast(env); - auto src = child->GetFrame(n, env); auto dst = env->NewVideoFrame(vi, 32); - auto buff = reinterpret_cast( - env2->Allocate(128 * sizeof(float), 32, AVS_POOLED_ALLOC)); - if (!buff) { - env->ThrowError("DCTFilter: failed to allocate temporal buffer."); + float* buff; + if (!isPlus) { + buff = factors + 64; + } else { + buff = reinterpret_cast(static_cast( + env)->Allocate(128 * sizeof(float), 32, AVS_POOLED_ALLOC)); + if (!buff) { + env->ThrowError("DCTFilter: failed to allocate temporal buffer."); + } } for (int p = 0; p < numPlanes; ++p) { @@ -159,7 +172,7 @@ PVideoFrame __stdcall DCTFilter::GetFrame(int n, ise_t* env) src->GetPitch(plane), dst->GetPitch(plane), src->GetRowSize(plane), src->GetHeight(plane), buff, factors, //vi.BitsPerComponent()); - vi.ComponentSize() * 8); + vi.BytesFromPixels(1) * 8); } if (chroma == 0) { @@ -173,7 +186,9 @@ PVideoFrame __stdcall DCTFilter::GetFrame(int n, ise_t* env) src->GetReadPtr(planes[2]), spitch, rowsize, height); } - env2->Free(buff); + if (isPlus) { + static_cast(env)->Free(buff); + } return dst; } @@ -192,11 +207,12 @@ static AVSValue __cdecl create(AVSValue args, void*, ise_t* env) try { return new DCTFilter( - args[0].AsClip(), f, 0, args[9].AsInt(1), args[10].AsInt(-1)); + args[0].AsClip(), f, 0, args[9].AsInt(1), args[10].AsInt(-1), + env->FunctionExists("SetFilterMTMode")); } catch (std::runtime_error& e) { env->ThrowError("DCTFilter: %s", e.what()); } - return AVSValue(); + return 0; } @@ -210,11 +226,11 @@ static AVSValue __cdecl create_d(AVSValue args, void*, ise_t* env) try { return new DCTFilter( args[0].AsClip(), nullptr, diag_count, args[2].AsInt(1), - args[3].AsInt(-1)); + args[3].AsInt(-1), env->FunctionExists("SetFilterMTMode")); } catch (std::runtime_error& e) { env->ThrowError("DCTFilterD: %s", e.what()); } - return AVSValue(); + return 0; } @@ -229,5 +245,5 @@ AvisynthPluginInit3(ise_t* env, const AVS_Linkage* const vectors) env->AddFunction("DCTFilter", "cffffffff[chroma]i[opt]i", create, nullptr); env->AddFunction("DCTFilterD", "ci[chroma]i[opt]i", create_d, nullptr); - return "a rewite of DctFilter for Avisynth+ ver." DCT_FILTER_VERSION; + return "a rewite of DctFilter ver." DCT_FILTER_VERSION; } \ No newline at end of file diff --git a/src/DCTFilter.rc b/src/DCTFilter.rc new file mode 100644 index 0000000000000000000000000000000000000000..54aecbf73139b129590315ef9e50be2eeeb9b4f3 GIT binary patch literal 4938 zcmdUz>uwT36oAif6W?K^e>B!o+Qy_mDYvLxnsSLICZx7NN!q1ZXw<|f@F9FVUqk)Q z34wXU^>JUs=hDk(vzUNYFCDf$CZGi^of;`+_5^58yi2Z zsZVM&6s!jptq&dnvlwm5@f8q#w?w0QypfE2W*>qn-T@pk*7jbu-L>2vIy^S+cVA2A z7e9OZgCF0GJQp3kNZ9A`Y}Z^yH1cek6J1Wb1~)Hda#>O)E8;~}QM%uF%u37_G%oPc zuDm5T*TGN=R&D00kO}jwX*TpT3a3%4nN722N%mQ70(lmJQSU7S(`K%!EXAh zO6C2`_Xa)Pxe||IzplNu9M(#PG!5K+{Wau7 z31VKU+H{CaJ;zJLc+*x~b-q>eGPQ%&e9;v@?>w&zT$S}WjKSyj<(Q`Zq2*}E2U?31 ziT47Yw+@D{Ylvn&qzkatXdxPtsrjggQ*{;SDV9HxPrO}L@vy#6r|6-gHFRbsV-Y!{w*=>} z8GCwU*i-czr;pw;LUesa>rYp*XzF0JW*V_Fq<*@zx07U9)1`?=jhEt(yUQ_6`&Bkb zrmH*PH!GQX1GUKznq7_EL)&WQ8 zl#|!kPH$Uz`Wkf9ntkf7J1n}1G>s{D^+dffdSBG9f35jByhd2;fjW0W?n>tnZlp(? z_V#`;KY_i6EYHMau7e)o%x>Gna6HmlP`hL|#_WdP)uR!n8THi0T29mteBO4l&Ly3X zT;`qM;=ESwG+noP-R+Z9b@c7;e;t)ks`Xp?J=EKAw{5bzJ`8Lw KT<;H+>iP$#3r-{e literal 0 HcmV?d00001 diff --git a/vs2015/DCTFilter.vcxproj b/vs2015/DCTFilter.vcxproj index 3fcbfb4..eead22c 100644 --- a/vs2015/DCTFilter.vcxproj +++ b/vs2015/DCTFilter.vcxproj @@ -135,6 +135,9 @@ + + +