From bddff8775456313df846b549973a98b4a78e1058 Mon Sep 17 00:00:00 2001 From: Asd-g <65298684+Asd-g@users.noreply.github.com> Date: Thu, 15 Apr 2021 00:45:30 +0300 Subject: [PATCH] Fix FFSAR_NUM, FFSAR_DEN, FFSAR --- CHANGELOG.md | 3 +++ src/AVISynthAPI.cpp | 43 ++++++++++++++++++++++++++++++------------- src/d2vsource.rc | 8 ++++---- 3 files changed, 37 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f27b266..8e08415 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +##### 1.2.3: + Fixed FFSAR_NUM, FFSAR_DEN, FFSAR. + ##### 1.2.2: Fixed values of frame properties _Quants* when info=0. diff --git a/src/AVISynthAPI.cpp b/src/AVISynthAPI.cpp index 858b03a..cbe8790 100644 --- a/src/AVISynthAPI.cpp +++ b/src/AVISynthAPI.cpp @@ -33,6 +33,7 @@ #include #include #include +#include #include "AVISynthAPI.h" #include "color_convert.h" @@ -45,7 +46,7 @@ #define _MAX_PATH PATH_MAX #endif -#define VERSION "D2VSource 1.2.2" +#define VERSION "D2VSource 1.2.3" bool PutHintingData(uint8_t *video, uint32_t hint) { @@ -266,25 +267,41 @@ D2VSource::D2VSource(const char* d2v, int idct, bool showQ, try { env->CheckVersion(8); } catch (const AvisynthError&) { has_at_least_v8 = false; } - std::string ar = d.Aspect_Ratio; - std::vector sar; - sar.reserve(2); - std::stringstream str(ar); + std::vector ar; + ar.reserve(2); + std::stringstream str(d.Aspect_Ratio); int n; char ch; while (str >> n) { if (str >> ch) - sar.push_back(n); + ar.push_back(n); else - sar.push_back(n); + ar.push_back(n); } - int num = sar[0]; - int den = sar[1]; - env->SetVar(env->Sprintf("%s", "FFSAR_NUM"), num); - env->SetVar(env->Sprintf("%s", "FFSAR_DEN"), den); - if (num > 0 && den > 0) - env->SetVar(env->Sprintf("%s", "FFSAR"), num / static_cast(den)); + + const double sar = ar[0] / static_cast(ar[1]) / (static_cast(vi.width) / vi.height); + double decimal_part = sar - static_cast(sar); + + std::valarray vec_1{ double(static_cast(sar)), 1 }, vec_2{ 1,0 }, temporary; + + while (decimal_part > 0.005) + { + const double new_number = 1 / decimal_part; + const double whole_part = static_cast(new_number); + + temporary = vec_1; + vec_1 = whole_part * vec_1 + vec_2; + vec_2 = temporary; + + decimal_part = new_number - whole_part; + } + + env->SetVar(env->Sprintf("%s", "FFSAR_NUM"), static_cast(vec_1[0])); + env->SetVar(env->Sprintf("%s", "FFSAR_DEN"), static_cast(vec_1[1])); + + if (vec_1[0] > 0 && vec_1[1] > 0) + env->SetVar(env->Sprintf("%s", "FFSAR"), sar); } diff --git a/src/d2vsource.rc b/src/d2vsource.rc index ed0b578..528c1df 100644 --- a/src/d2vsource.rc +++ b/src/d2vsource.rc @@ -2,8 +2,8 @@ #include VS_VERSION_INFO VERSIONINFO -FILEVERSION 1,2,2,0 -PRODUCTVERSION 1,2,2,0 +FILEVERSION 1,2,3,0 +PRODUCTVERSION 1,2,3,0 FILEFLAGSMASK VS_FFI_FILEFLAGSMASK FILEFLAGS 0x0L FILEOS VOS__WINDOWS32 @@ -16,11 +16,11 @@ BEGIN BEGIN VALUE "Comments", "Modified DGDecode." VALUE "FileDescription", "D2VSource for AviSynth 2.6 / AviSynth+" - VALUE "FileVersion", "1.2.2" + VALUE "FileVersion", "1.2.3" VALUE "InternalName", "D2VSource" VALUE "OriginalFilename", "D2VSource.dll" VALUE "ProductName", "D2VSource" - VALUE "ProductVersion", "1.2.2" + VALUE "ProductVersion", "1.2.3" END END BLOCK "VarFileInfo"