From 9280062c6049fb78575fed2b53d20739f00ce7f8 Mon Sep 17 00:00:00 2001 From: Skylar Moore Date: Sat, 4 Jun 2016 23:36:10 -0700 Subject: [PATCH] r2 --- src/MVAnalyze.cpp | 6 +++--- src/MVBlockFPS.cpp | 24 +++++++++++++----------- src/MVCompensate.cpp | 6 +++++- src/MVFlowFPS.cpp | 24 +++++++++++++----------- src/MVRecalculate.cpp | 6 +++--- 5 files changed, 37 insertions(+), 29 deletions(-) diff --git a/src/MVAnalyze.cpp b/src/MVAnalyze.cpp index 4668988..5841ee8 100644 --- a/src/MVAnalyze.cpp +++ b/src/MVAnalyze.cpp @@ -119,7 +119,7 @@ static const VSFrameRef *VS_CC mvanalyzeGetFrame(int32_t n, int32_t activationRe return nullptr; } if (d->tffexists) - srctff = d->tff && (n % 2 == 0); + srctff = !!(static_cast(d->tff) ^ (n % 2)); for (int32_t plane = 0; plane < d->supervi->format->numPlanes; plane++) { pSrc[plane] = vsapi->getReadPtr(src, plane); nSrcPitch[plane] = vsapi->getStride(src, plane); @@ -148,7 +148,7 @@ static const VSFrameRef *VS_CC mvanalyzeGetFrame(int32_t n, int32_t activationRe return nullptr; } if (d->tffexists) - reftff = d->tff && (nref % 2 == 0); + reftff = !!(static_cast(d->tff) ^ (nref % 2)); int32_t fieldShift = 0; if (d->fields && d->analysisData.nPel > 1 && (d->analysisData.nDeltaFrame % 2)) fieldShift = (srctff && !reftff) ? d->analysisData.nPel / 2 : ((reftff && !srctff) ? -(d->analysisData.nPel / 2) : 0); @@ -257,7 +257,7 @@ static void VS_CC mvanalyzeCreate(const VSMap *in, VSMap *out, void *userData, V d.tryMany = !!vsapi->propGetInt(in, "trymany", 0, &err); d.fields = !!vsapi->propGetInt(in, "fields", 0, &err); d.tff = !!vsapi->propGetInt(in, "tff", 0, &err); - d.tffexists = err; + d.tffexists = !err; if (d.search < 0 || d.search > 7) { vsapi->setError(out, "Analyze: search must be between 0 and 7 (inclusive)."); return; diff --git a/src/MVBlockFPS.cpp b/src/MVBlockFPS.cpp index 024cd8e..011c902 100644 --- a/src/MVBlockFPS.cpp +++ b/src/MVBlockFPS.cpp @@ -12,6 +12,7 @@ struct MVBlockFPSData { VSNodeRef *node; VSVideoInfo vi; + const VSVideoInfo *oldvi; const VSVideoInfo *supervi; VSNodeRef *super; VSNodeRef *mvbw; @@ -242,23 +243,23 @@ static const VSFrameRef *VS_CC mvblockfpsGetFrame(int32_t n, int32_t activationR if (off > 1) time256 = time256 / off; if (time256 == 0) { - vsapi->requestFrameFilter(d->vi.numFrames ? VSMIN(nleft, d->vi.numFrames - 1) : nleft, d->node, frameCtx); + vsapi->requestFrameFilter(d->vi.numFrames ? VSMIN(nleft, d->oldvi->numFrames - 1) : nleft, d->node, frameCtx); return 0; } else if (time256 == 256) { - vsapi->requestFrameFilter(d->vi.numFrames ? VSMIN(nright, d->vi.numFrames - 1) : nright, d->node, frameCtx); + vsapi->requestFrameFilter(d->vi.numFrames ? VSMIN(nright, d->oldvi->numFrames - 1) : nright, d->node, frameCtx); return 0; } - if ((nleft < d->vi.numFrames && nright < d->vi.numFrames) || !d->vi.numFrames) { + if ((nleft < d->oldvi->numFrames && nright < d->vi.numFrames) || !d->oldvi->numFrames) { vsapi->requestFrameFilter(nright, d->mvfw, frameCtx); vsapi->requestFrameFilter(nleft, d->mvbw, frameCtx); vsapi->requestFrameFilter(nleft, d->super, frameCtx); vsapi->requestFrameFilter(nright, d->super, frameCtx); } - vsapi->requestFrameFilter(d->vi.numFrames ? VSMIN(nleft, d->vi.numFrames - 1) : nleft, d->node, frameCtx); + vsapi->requestFrameFilter(d->vi.numFrames ? VSMIN(nleft, d->oldvi->numFrames - 1) : nleft, d->node, frameCtx); if (d->blend) - vsapi->requestFrameFilter(d->vi.numFrames ? VSMIN(nright, d->vi.numFrames - 1) : nright, d->node, frameCtx); + vsapi->requestFrameFilter(d->vi.numFrames ? VSMIN(nright, d->oldvi->numFrames - 1) : nright, d->node, frameCtx); } else if (activationReason == arAllFramesReady) { @@ -269,14 +270,14 @@ static const VSFrameRef *VS_CC mvblockfpsGetFrame(int32_t n, int32_t activationR time256 = time256 / off; int32_t nright = nleft + off; if (time256 == 0) - return vsapi->getFrameFilter(d->vi.numFrames ? VSMIN(nleft, d->vi.numFrames - 1) : nleft, d->node, frameCtx); + return vsapi->getFrameFilter(d->vi.numFrames ? VSMIN(nleft, d->oldvi->numFrames - 1) : nleft, d->node, frameCtx); else if (time256 == 256) - return vsapi->getFrameFilter(d->vi.numFrames ? VSMIN(nright, d->vi.numFrames - 1) : nright, d->node, frameCtx); + return vsapi->getFrameFilter(d->vi.numFrames ? VSMIN(nright, d->oldvi->numFrames - 1) : nright, d->node, frameCtx); MVClipBalls ballsF(d->mvClipF, vsapi); MVClipBalls ballsB(d->mvClipB, vsapi); bool isUsableF = false; bool isUsableB = false; - if ((nleft < d->vi.numFrames && nright < d->vi.numFrames) || !d->vi.numFrames) { + if ((nleft < d->oldvi->numFrames && nright < d->oldvi->numFrames) || !d->vi.numFrames) { const VSFrameRef *mvF = vsapi->getFrameFilter(nright, d->mvfw, frameCtx); ballsF.Update(mvF); isUsableF = ballsF.IsUsable(); @@ -511,12 +512,12 @@ static const VSFrameRef *VS_CC mvblockfpsGetFrame(int32_t n, int32_t activationR return dst; } else { - const VSFrameRef *src = vsapi->getFrameFilter(d->vi.numFrames ? VSMIN(nleft, d->vi.numFrames - 1) : nleft, d->node, frameCtx); + const VSFrameRef *src = vsapi->getFrameFilter(d->vi.numFrames ? VSMIN(nleft, d->oldvi->numFrames - 1) : nleft, d->node, frameCtx); if (blend) { uint8_t *pDst[3]; const uint8_t *pRef[3], *pSrc[3]; int32_t nDstPitches[3], nRefPitches[3], nSrcPitches[3]; - const VSFrameRef *ref = vsapi->getFrameFilter(d->vi.numFrames ? VSMIN(nright, d->vi.numFrames - 1) : nright, d->node, frameCtx); + const VSFrameRef *ref = vsapi->getFrameFilter(d->vi.numFrames ? VSMIN(nright, d->oldvi->numFrames - 1) : nright, d->node, frameCtx); VSFrameRef *dst = vsapi->newVideoFrame(d->vi.format, d->vi.width, d->vi.height, src, core); for (int32_t i = 0; i < d->vi.format->numPlanes; i++) { pDst[i] = vsapi->getWritePtr(dst, i); @@ -733,7 +734,8 @@ static void VS_CC mvblockfpsCreate(const VSMap *in, VSMap *out, void *userData, return; } d.node = vsapi->propGetNode(in, "clip", 0, 0); - d.vi = *vsapi->getVideoInfo(d.node); + d.oldvi = vsapi->getVideoInfo(d.node); + d.vi = *d.oldvi; if (d.vi.fpsNum == 0 || d.vi.fpsDen == 0) { vsapi->setError(out, "BlockFPS: The input clip must have a frame rate. Invoke AssumeFPS if necessary."); vsapi->freeNode(d.super); diff --git a/src/MVCompensate.cpp b/src/MVCompensate.cpp index 80b57d1..5b2b2a6 100644 --- a/src/MVCompensate.cpp +++ b/src/MVCompensate.cpp @@ -145,6 +145,8 @@ static const VSFrameRef *VS_CC mvcompensateGetFrame(int32_t n, int32_t activatio vsapi->freeFrame(ref); return nullptr; } + if (d->tffexists) + paritySrc = !!(static_cast(d->tff) ^ (n % 2)); props = vsapi->getFramePropsRO(ref); bool parityRef = !!vsapi->propGetInt(props, "_Field", 0, &err); if (err && !d->tffexists) { @@ -156,6 +158,8 @@ static const VSFrameRef *VS_CC mvcompensateGetFrame(int32_t n, int32_t activatio vsapi->freeFrame(ref); return nullptr; } + if (d->tffexists) + parityRef = !!(static_cast(d->tff) ^ (nref % 2)); fieldShift = (paritySrc && !parityRef) ? nPel / 2 : ((parityRef && !paritySrc) ? -(nPel / 2) : 0); } if (nOverlapX == 0 && nOverlapY == 0) { @@ -412,7 +416,7 @@ static void VS_CC mvcompensateCreate(const VSMap *in, VSMap *out, void *userData if (err) d.nSCD2 = MV_DEFAULT_SCD2; d.tff = !!vsapi->propGetInt(in, "tff", 0, &err); - d.tffexists = err; + d.tffexists = !err; d.super = vsapi->propGetNode(in, "super", 0, nullptr); char errorMsg[1024]; const VSFrameRef *evil = vsapi->getFrame(0, d.super, errorMsg, 1024); diff --git a/src/MVFlowFPS.cpp b/src/MVFlowFPS.cpp index 3901750..308b2b1 100644 --- a/src/MVFlowFPS.cpp +++ b/src/MVFlowFPS.cpp @@ -11,6 +11,7 @@ struct MVFlowFPSData { VSNodeRef *node; VSVideoInfo vi; + const VSVideoInfo *oldvi; VSNodeRef *finest; VSNodeRef *super; VSNodeRef *mvbw; @@ -101,15 +102,15 @@ static const VSFrameRef *VS_CC mvflowfpsGetFrame(int32_t n, int32_t activationRe time256 = time256 / off; if (time256 == 0) { - vsapi->requestFrameFilter(d->vi.numFrames ? VSMIN(nleft, d->vi.numFrames - 1) : nleft, d->node, frameCtx); + vsapi->requestFrameFilter(d->vi.numFrames ? VSMIN(nleft, d->oldvi->numFrames - 1) : nleft, d->node, frameCtx); return 0; } else if (time256 == 256) { - vsapi->requestFrameFilter(d->vi.numFrames ? VSMIN(nright, d->vi.numFrames - 1) : nright, d->node, frameCtx); + vsapi->requestFrameFilter(d->vi.numFrames ? VSMIN(nright, d->oldvi->numFrames - 1) : nright, d->node, frameCtx); return 0; } - if ((nleft < d->vi.numFrames && nright < d->vi.numFrames) || !d->vi.numFrames) { // for the good estimation case + if ((nleft < d->oldvi->numFrames && nright < d->oldvi->numFrames) || !d->vi.numFrames) { // for the good estimation case if (d->maskmode == 2) vsapi->requestFrameFilter(nleft, d->mvfw, frameCtx); // requests nleft - off, nleft vsapi->requestFrameFilter(nright, d->mvfw, frameCtx); // requests nleft, nleft + off @@ -121,10 +122,10 @@ static const VSFrameRef *VS_CC mvflowfpsGetFrame(int32_t n, int32_t activationRe vsapi->requestFrameFilter(nright, d->finest, frameCtx); } - vsapi->requestFrameFilter(d->vi.numFrames ? VSMIN(nleft, d->vi.numFrames - 1) : nleft, d->node, frameCtx); + vsapi->requestFrameFilter(d->vi.numFrames ? VSMIN(nleft, d->oldvi->numFrames - 1) : nleft, d->node, frameCtx); if (d->blend) - vsapi->requestFrameFilter(d->vi.numFrames ? VSMIN(nright, d->vi.numFrames - 1) : nright, d->node, frameCtx); + vsapi->requestFrameFilter(d->vi.numFrames ? VSMIN(nright, d->oldvi->numFrames - 1) : nright, d->node, frameCtx); } else if (activationReason == arAllFramesReady) { @@ -140,10 +141,10 @@ static const VSFrameRef *VS_CC mvflowfpsGetFrame(int32_t n, int32_t activationRe int32_t nright = nleft + off; if (time256 == 0) { - return vsapi->getFrameFilter(d->vi.numFrames ? VSMIN(nleft, d->vi.numFrames - 1) : nleft, d->node, frameCtx); // simply left + return vsapi->getFrameFilter(d->vi.numFrames ? VSMIN(nleft, d->oldvi->numFrames - 1) : nleft, d->node, frameCtx); // simply left } else if (time256 == 256) { - return vsapi->getFrameFilter(d->vi.numFrames ? VSMIN(nright, d->vi.numFrames - 1) : nright, d->node, frameCtx); // simply right + return vsapi->getFrameFilter(d->vi.numFrames ? VSMIN(nright, d->oldvi->numFrames - 1) : nright, d->node, frameCtx); // simply right } MVClipBalls ballsF(d->mvClipF, vsapi); @@ -152,7 +153,7 @@ static const VSFrameRef *VS_CC mvflowfpsGetFrame(int32_t n, int32_t activationRe bool isUsableF = false; bool isUsableB = false; - if ((nleft < d->vi.numFrames && nright < d->vi.numFrames) || !d->vi.numFrames) { + if ((nleft < d->oldvi->numFrames && nright < d->oldvi->numFrames) || !d->vi.numFrames) { const VSFrameRef *mvF = vsapi->getFrameFilter(nright, d->mvfw, frameCtx); ballsF.Update(mvF);// forward from current to next isUsableF = ballsF.IsUsable(); @@ -449,14 +450,14 @@ static const VSFrameRef *VS_CC mvflowfpsGetFrame(int32_t n, int32_t activationRe return dst; } else { // poor estimation - const VSFrameRef *src = vsapi->getFrameFilter(d->vi.numFrames ? VSMIN(nleft, d->vi.numFrames - 1) : nleft, d->node, frameCtx); + const VSFrameRef *src = vsapi->getFrameFilter(d->vi.numFrames ? VSMIN(nleft, d->oldvi->numFrames - 1) : nleft, d->node, frameCtx); if (blend) {//let's blend src with ref frames like ConvertFPS uint8_t *pDst[3]; const uint8_t *pRef[3], *pSrc[3]; int32_t nDstPitches[3], nRefPitches[3], nSrcPitches[3]; - const VSFrameRef *ref = vsapi->getFrameFilter(d->vi.numFrames ? VSMIN(nright, d->vi.numFrames - 1) : nright, d->node, frameCtx); + const VSFrameRef *ref = vsapi->getFrameFilter(d->vi.numFrames ? VSMIN(nright, d->oldvi->numFrames - 1) : nright, d->node, frameCtx); VSFrameRef *dst = vsapi->newVideoFrame(d->vi.format, d->vi.width, d->vi.height, src, core); @@ -784,7 +785,8 @@ static void VS_CC mvflowfpsCreate(const VSMap *in, VSMap *out, void *userData, V } d.node = vsapi->propGetNode(in, "clip", 0, 0); - d.vi = *vsapi->getVideoInfo(d.node); + d.oldvi = vsapi->getVideoInfo(d.node); + d.vi = *d.oldvi; if (d.vi.fpsNum == 0 || d.vi.fpsDen == 0) { diff --git a/src/MVRecalculate.cpp b/src/MVRecalculate.cpp index eee7520..558f079 100644 --- a/src/MVRecalculate.cpp +++ b/src/MVRecalculate.cpp @@ -91,7 +91,7 @@ static const VSFrameRef *VS_CC mvrecalculateGetFrame(int32_t n, int32_t activati return nullptr; } if (d->tffexists) - srctff = d->tff && (n % 2 == 0); + srctff = !!(static_cast(d->tff) ^ (n % 2)); for (int32_t plane = 0; plane < d->supervi->format->numPlanes; plane++) { pSrc[plane] = vsapi->getReadPtr(src, plane); nSrcPitch[plane] = vsapi->getStride(src, plane); @@ -124,7 +124,7 @@ static const VSFrameRef *VS_CC mvrecalculateGetFrame(int32_t n, int32_t activati return nullptr; } if (d->tffexists) - reftff = d->tff && (nref % 2 == 0); + reftff = !!(static_cast(d->tff) ^ (nref % 2)); int32_t fieldShift = 0; if (d->fields && d->analysisData.nPel > 1 && (d->analysisData.nDeltaFrame % 2)) { fieldShift = (srctff && !reftff) ? d->analysisData.nPel / 2 : ((reftff && !srctff) ? -(d->analysisData.nPel / 2) : 0); @@ -215,7 +215,7 @@ static void VS_CC mvrecalculateCreate(const VSMap *in, VSMap *out, void *userDat d.meander = 1; d.fields = !!vsapi->propGetInt(in, "fields", 0, &err); d.tff = !!vsapi->propGetInt(in, "tff", 0, &err); - d.tffexists = err; + d.tffexists = !err; if (d.search < 0 || d.search > 7) { vsapi->setError(out, "Recalculate: search must be between 0 and 7 (inclusive)."); return;