From 8d4a9767fa98395f6163004c3ceb4d5bc65c0604 Mon Sep 17 00:00:00 2001 From: Asd-g <65298684+Asd-g@users.noreply.github.com> Date: Sat, 7 May 2022 08:41:14 +0300 Subject: [PATCH] Add nocrop and rff (#9) --- src/AVISynthAPI.cpp | 69 +++++++++++++++++++++++++------------------- src/AVISynthAPI.h | 2 +- src/MPEG2Decoder.cpp | 5 +++- src/MPEG2Decoder.h | 2 +- src/d2vsource.rc | 8 ++--- 5 files changed, 50 insertions(+), 36 deletions(-) diff --git a/src/AVISynthAPI.cpp b/src/AVISynthAPI.cpp index c61eb2d..a91d27e 100644 --- a/src/AVISynthAPI.cpp +++ b/src/AVISynthAPI.cpp @@ -185,10 +185,13 @@ static void show_info(int n, CMPEG2Decoder& d, PVideoFrame& frame, D2VSource::D2VSource(const char* d2v, int idct, bool showQ, - int _info, int _upConv, bool _i420, int iCC, + int _info, int _upConv, bool _i420, int iCC, int _rff, IScriptEnvironment* env) : bufY(nullptr), bufU(nullptr), bufV(nullptr), decoder(nullptr) { + if (_rff < -1 || _rff > 2) + env->ThrowError("D2VSource: rff must be set to -1, 0, 1 or 2!"); + if (iCC != -1 && iCC != 0 && iCC != 1) env->ThrowError("D2VSource: iCC must be set to -1, 0, or 1!"); @@ -208,7 +211,7 @@ D2VSource::D2VSource(const char* d2v, int idct, bool showQ, env->ThrowError("D2VSource: unable to load D2V file \"%s\" ", d2v); try { - decoder = new CMPEG2Decoder(f, d2v, idct, iCC, _upConv, _info, showQ, _i420, env->GetCPUFlags()); + decoder = new CMPEG2Decoder(f, d2v, idct, iCC, _upConv, _info, showQ, _i420, _rff, env->GetCPUFlags()); } catch (std::runtime_error& e) { if (f) fclose(f); @@ -508,40 +511,46 @@ AVSValue __cdecl D2VSource::create(AVSValue args, void*, IScriptEnvironment* env // check for uninitialised strings if (strlen(d2v) >= _MAX_PATH) d2v[0] = 0; - D2VSource* dec = new D2VSource(args[0].AsString(d2v), + D2VSource* dec = new D2VSource( + args[0].AsString(d2v), args[1].AsInt(idct), args[2].AsBool(showQ), args[3].AsInt(info), args[4].AsInt(upConv), args[5].AsBool(i420), iCC, + args[8].AsInt(-1), env); - // Only bother invoking crop if we have to. - auto& d = *dec->decoder; - if (d.Clip_Top || d.Clip_Bottom || d.Clip_Left || d.Clip_Right || - // This is cheap but it works. The intent is to allow the - // display size to be different from the encoded size, while - // not requiring massive revisions to the code. So we detect the - // difference and crop it off. - d.vertical_size != d.Clip_Height || d.horizontal_size != d.Clip_Width || - d.vertical_size == 1088) - { - int vertical; - // Special case for 1088 to 1080 as directed by DGIndex. - if (d.vertical_size == 1088 && d.D2V_Height == 1080) - vertical = 1080; - else - vertical = d.vertical_size; - AVSValue CropArgs[] = { - dec, - d.Clip_Left, - d.Clip_Top, - -(d.Clip_Right + (d.Clip_Width - d.horizontal_size)), - -(d.Clip_Bottom + (d.Clip_Height - vertical)), - true - }; - return env->Invoke("crop", AVSValue(CropArgs, 6)); + if (!args[7].AsBool(false)) + { + // Only bother invoking crop if we have to. + auto& d = *dec->decoder; + if (d.Clip_Top || d.Clip_Bottom || d.Clip_Left || d.Clip_Right || + // This is cheap but it works. The intent is to allow the + // display size to be different from the encoded size, while + // not requiring massive revisions to the code. So we detect the + // difference and crop it off. + d.vertical_size != d.Clip_Height || d.horizontal_size != d.Clip_Width || + d.vertical_size == 1088) + { + int vertical; + // Special case for 1088 to 1080 as directed by DGIndex. + if (d.vertical_size == 1088 && d.D2V_Height == 1080) + vertical = 1080; + else + vertical = d.vertical_size; + AVSValue CropArgs[] = { + dec, + d.Clip_Left, + d.Clip_Top, + -(d.Clip_Right + (d.Clip_Width - d.horizontal_size)), + -(d.Clip_Bottom + (d.Clip_Height - vertical)), + true + }; + + return env->Invoke("crop", AVSValue(CropArgs, 6)); + } } return dec; @@ -561,7 +570,9 @@ AvisynthPluginInit3(IScriptEnvironment * env, const AVS_Linkage* const vectors) "[info]i" "[upConv]i" "[i420]b" - "[iCC]b"; + "[iCC]b" + "[nocrop]b" + "[rff]i"; env->AddFunction("D2VSource", msargs, D2VSource::create, nullptr); diff --git a/src/AVISynthAPI.h b/src/AVISynthAPI.h index cfaa117..518ad69 100644 --- a/src/AVISynthAPI.h +++ b/src/AVISynthAPI.h @@ -43,7 +43,7 @@ class D2VSource : public IClip { int history[5]; public: - D2VSource(const char* d2v, int idct, bool showQ, int _info, int _upConv, bool _i420, int iCC, IScriptEnvironment* env); + D2VSource(const char* d2v, int idct, bool showQ, int _info, int _upConv, bool _i420, int iCC, int _rff, IScriptEnvironment* env); ~D2VSource() {} PVideoFrame __stdcall GetFrame(int n, IScriptEnvironment* env); bool __stdcall GetParity(int n); diff --git a/src/MPEG2Decoder.cpp b/src/MPEG2Decoder.cpp index c7bacc4..d5a13a6 100644 --- a/src/MPEG2Decoder.cpp +++ b/src/MPEG2Decoder.cpp @@ -46,7 +46,7 @@ static void validate(bool cond, const char* msg) // Open function modified by Donald Graft as part of fix for dropped frames and random frame access. // change function to constructor - chikuzen. -CMPEG2Decoder::CMPEG2Decoder(FILE* d2vf, const char* path, int _idct, int icc, int upconv, int _info, bool showq, bool _i420, int _cpu_flags) : +CMPEG2Decoder::CMPEG2Decoder(FILE* d2vf, const char* path, int _idct, int icc, int upconv, int _info, bool showq, bool _i420, int _rff, int _cpu_flags) : Rdmax(nullptr), CurrentBfr(0), NextBfr(0), @@ -133,6 +133,9 @@ CMPEG2Decoder::CMPEG2Decoder(FILE* d2vf, const char* path, int _idct, int icc, i fscanf_s(d2vf, "Frame_Rate=%d (%u/%u)\n", &(VF_FrameRate), &(VF_FrameRate_Num), &(VF_FrameRate_Den)); fscanf_s(d2vf, "Location=%d,%X,%d,%X\n", &i, &j, &i, &j); + if (_rff > -1) + FO_Flag = _rff; + create_gop_and_frame_lists(d2vf, buf); fclose(d2vf); d2vf = nullptr; diff --git a/src/MPEG2Decoder.h b/src/MPEG2Decoder.h index 8819c40..4d5e028 100644 --- a/src/MPEG2Decoder.h +++ b/src/MPEG2Decoder.h @@ -325,7 +325,7 @@ class CMPEG2Decoder void destroy(); public: - CMPEG2Decoder(FILE* file, const char* path, int _idct, int icc, int upconv, int info, bool showq, bool _i420, int _cpu_flags); + CMPEG2Decoder(FILE* file, const char* path, int _idct, int icc, int upconv, int info, bool showq, bool _i420, int _rff, int _cpu_flags); ~CMPEG2Decoder() { destroy(); } void Decode(uint32_t frame, YV12PICT& dst); diff --git a/src/d2vsource.rc b/src/d2vsource.rc index 8d6dfaa..40865b9 100644 --- a/src/d2vsource.rc +++ b/src/d2vsource.rc @@ -1,8 +1,8 @@ #include VS_VERSION_INFO VERSIONINFO -FILEVERSION 1,2,5,0 -PRODUCTVERSION 1,2,5,0 +FILEVERSION 1,2,6,0 +PRODUCTVERSION 1,2,6,0 FILEFLAGSMASK VS_FFI_FILEFLAGSMASK FILEFLAGS 0x0L FILEOS VOS__WINDOWS32 @@ -15,11 +15,11 @@ BEGIN BEGIN VALUE "Comments", "Modified DGDecode." VALUE "FileDescription", "D2VSource for AviSynth 2.6 / AviSynth+" - VALUE "FileVersion", "1.2.5" + VALUE "FileVersion", "1.2.6" VALUE "InternalName", "D2VSource" VALUE "OriginalFilename", "D2VSource.dll" VALUE "ProductName", "D2VSource" - VALUE "ProductVersion", "1.2.5" + VALUE "ProductVersion", "1.2.6" END END BLOCK "VarFileInfo"