Skip to content

Commit

Permalink
Fix FFSAR_NUM, FFSAR_DEN, FFSAR
Browse files Browse the repository at this point in the history
  • Loading branch information
Asd-g committed Apr 14, 2021
1 parent fc56927 commit bddff87
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 17 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.

Expand Down
43 changes: 30 additions & 13 deletions src/AVISynthAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <stdexcept>
#include <malloc.h>
#include <sstream>
#include <valarray>

#include "AVISynthAPI.h"
#include "color_convert.h"
Expand All @@ -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)
{
Expand Down Expand Up @@ -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<int> sar;
sar.reserve(2);
std::stringstream str(ar);
std::vector<int> 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<double>(den));

const double sar = ar[0] / static_cast<double>(ar[1]) / (static_cast<double>(vi.width) / vi.height);
double decimal_part = sar - static_cast<int>(sar);

std::valarray<double> vec_1{ double(static_cast<int>(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<int>(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<int>(vec_1[0]));
env->SetVar(env->Sprintf("%s", "FFSAR_DEN"), static_cast<int>(vec_1[1]));

if (vec_1[0] > 0 && vec_1[1] > 0)
env->SetVar(env->Sprintf("%s", "FFSAR"), sar);
}


Expand Down
8 changes: 4 additions & 4 deletions src/d2vsource.rc
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
#include <ntdef.h>

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
Expand All @@ -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"
Expand Down

0 comments on commit bddff87

Please sign in to comment.