Skip to content

Commit 57739c5

Browse files
author
cantabile
committed
React to the _FieldBased frame property
Closes #11.
1 parent 80d9788 commit 57739c5

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed

readme.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ When the input clip has more than 8 bits per sample, some parameters' allowed an
3232

3333
The opt parameter is now a boolean. If False, only C functions will be used. If True, the best functions that can run on your CPU will be selected automatically.
3434

35+
The ``_FieldBased`` frame property is now used to determine each frame's field dominance. The *field* parameter is only a fallback for frames that don't have the ``_FieldBased`` property, or where said property indicates that the frame is progressive.
36+
3537
::
3638

3739
nnedi3.nnedi3_rpow2(clip clip, int rfactor[, int width=clip.width*rfactor, int height=clip.height*rfactor, bint correct_shift=1, int nsize=0, int nns=3, int qual=1, int etype=0, int pscrn=2, bint opt=True, int fapprox=15])

src/nnedi3.cpp

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,18 +1163,31 @@ static const VSFrameRef *VS_CC nnedi3GetFrame(int n, int activationReason, void
11631163
if (activationReason == arInitial) {
11641164
vsapi->requestFrameFilter(d->field > 1 ? n / 2 : n, d->node, frameCtx);
11651165
} else if (activationReason == arAllFramesReady) {
1166+
const VSFrameRef *src = vsapi->getFrameFilter(d->field > 1 ? n / 2 : n, d->node, frameCtx);
1167+
1168+
int err;
1169+
const VSMap *src_props = vsapi->getFramePropsRO(src);
1170+
int fieldbased = int64ToIntS(vsapi->propGetInt(src_props, "_FieldBased", 0, &err));
1171+
int effective_field = d->field;
1172+
if (effective_field > 1)
1173+
effective_field -= 2;
1174+
1175+
if (fieldbased == 1)
1176+
effective_field = 0;
1177+
else if (fieldbased == 2)
1178+
effective_field = 1;
1179+
11661180
int field_n;
11671181
if (d->field > 1) {
11681182
if (n & 1) {
1169-
field_n = d->field == 3 ? 0 : 1;
1183+
field_n = (effective_field == 0);
11701184
} else {
1171-
field_n = d->field == 3 ? 1 : 0;
1185+
field_n = (effective_field == 1);
11721186
}
11731187
} else {
1174-
field_n = d->field;
1188+
field_n = effective_field;
11751189
}
11761190

1177-
const VSFrameRef *src = vsapi->getFrameFilter(d->field > 1 ? n / 2 : n, d->node, frameCtx);
11781191
VSFrameRef *dst = vsapi->newVideoFrame(d->vi.format, d->vi.width, d->vi.height, src, core);
11791192

11801193

@@ -1231,14 +1244,14 @@ static const VSFrameRef *VS_CC nnedi3GetFrame(int n, int activationReason, void
12311244
vsapi->freeFrame(src);
12321245

12331246
if (d->field > 1) {
1234-
VSMap *props = vsapi->getFramePropsRW(dst);
1247+
VSMap *dst_props = vsapi->getFramePropsRW(dst);
12351248
int err_num, err_den;
1236-
int64_t duration_num = vsapi->propGetInt(props, "_DurationNum", 0, &err_num);
1237-
int64_t duration_den = vsapi->propGetInt(props, "_DurationDen", 0, &err_den);
1249+
int64_t duration_num = vsapi->propGetInt(dst_props, "_DurationNum", 0, &err_num);
1250+
int64_t duration_den = vsapi->propGetInt(dst_props, "_DurationDen", 0, &err_den);
12381251
if (!err_num && !err_den) {
12391252
muldivRational(&duration_num, &duration_den, 1, 2); // Divide duration by 2.
1240-
vsapi->propSetInt(props, "_DurationNum", duration_num, paReplace);
1241-
vsapi->propSetInt(props, "_DurationDen", duration_den, paReplace);
1253+
vsapi->propSetInt(dst_props, "_DurationNum", duration_num, paReplace);
1254+
vsapi->propSetInt(dst_props, "_DurationDen", duration_den, paReplace);
12421255
}
12431256
}
12441257

0 commit comments

Comments
 (0)