Skip to content

Commit

Permalink
Add nocrop and rff (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
Asd-g committed May 7, 2022
1 parent 998477d commit 8d4a976
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 36 deletions.
69 changes: 40 additions & 29 deletions src/AVISynthAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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!");

Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion src/AVISynthAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 4 additions & 1 deletion src/MPEG2Decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/MPEG2Decoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

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

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

0 comments on commit 8d4a976

Please sign in to comment.