Skip to content

Commit 3c99e87

Browse files
committed
Final version!?
1 parent 92d6017 commit 3c99e87

File tree

3 files changed

+309
-72
lines changed

3 files changed

+309
-72
lines changed

FQCorrelation.cpp

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ typedef struct
6262
float* inBuf;
6363
fftwf_complex* outBuf;
6464
fftwf_complex* Bfreq;
65-
}CorrData;
65+
}F2QCorrData;
6666
//------------------------------------------------------------------
6767

6868
void xCorrelate(fftwf_complex* Afreq, fftwf_complex* Bfreq, int frqwidth, int hbest, bool center);
@@ -72,7 +72,7 @@ typedef struct
7272
void xTransferToDst(finc * dp, int dpitch,
7373
int dwd, int dht, float * buf, int bestwd, int bestht, finc max);
7474
template <typename finc>
75-
int xFullProcess(CorrData *d,
75+
int xFullProcess(F2QCorrData *d,
7676
finc * dp, const finc * ap, const finc * bp, int abpitch,
7777
int pwd, int pht, int dpitch, finc max);
7878
template <typename finc>
@@ -85,9 +85,9 @@ typedef struct
8585
*************************************************/
8686
//Here is the acutal constructor code used
8787

88-
static void VS_CC corrInit(VSMap *in, VSMap *out, void **instanceData, VSNode *node, VSCore *core, const VSAPI *vsapi)
88+
static void VS_CC f2qcorrInit(VSMap *in, VSMap *out, void **instanceData, VSNode *node, VSCore *core, const VSAPI *vsapi)
8989
{
90-
CorrData *d = (CorrData *)* instanceData;
90+
F2QCorrData *d = (F2QCorrData *)* instanceData;
9191
//vsapi->setVideoInfo(d->vi, 1, node);
9292
const int fht = ((d->avi->height + 3) >> 2) << 2;
9393
const int fwd = ((d->avi->width + 3) >> 2) << 2;
@@ -203,7 +203,7 @@ int xNormGamma(float * buf, int size)
203203
// normalize. Avoid divide by zero.
204204
if (maximum > minimum)
205205
{
206-
float mult = 1.0 / (maximum - minimum); // mult is faster than div
206+
float mult = 1.0f / (maximum - minimum); // mult is faster than div
207207

208208
for (int n = 0; n < size; n++)
209209
{
@@ -232,7 +232,7 @@ void xTransferToDst(finc * dp, int dpitch,
232232
{
233233
for (int w = 0; w < dwd; w++)
234234
{
235-
dp[w] = buf[w] * max; // converts normalized data to actual values
235+
dp[w] = (finc)(buf[w] * max); // converts normalized data to actual values
236236
}
237237
dp += dpitch;
238238
buf += bestwd;
@@ -252,7 +252,7 @@ void drawOrigin(float* inBuf, int wbest, int hbest, finc val)
252252
}
253253
//--------------------------------------------------------------------------------------------
254254
template <typename finc>
255-
int xFullProcess(CorrData* d, // forward fft of the two input frames
255+
int xFullProcess(F2QCorrData* d, // forward fft of the two input frames
256256
finc * dp, // output frame
257257
const finc * ap, const finc * bp, int abpitch, // input A and B frames, pitch of frames
258258
int pwd, int pht, int dpitch, finc max) // frame dimensions and max pixel value
@@ -285,10 +285,10 @@ int xFullProcess(CorrData* d, // forward fft of the two input frames
285285
}
286286

287287
//---------------------------------------------------------------------------------------------
288-
static const VSFrameRef *VS_CC corrGetFrame(int n, int activationReason, void **instanceData,
288+
static const VSFrameRef *VS_CC f2qcorrGetFrame(int n, int activationReason, void **instanceData,
289289
void **frameData, VSFrameContext *frameCtx, VSCore *core, const VSAPI *vsapi)
290290
{
291-
CorrData *d = (CorrData *)* instanceData;
291+
F2QCorrData *d = (F2QCorrData *)* instanceData;
292292

293293
if (activationReason == arInitial) {
294294
// Request the source frames on the first call
@@ -453,9 +453,9 @@ static const VSFrameRef *VS_CC corrGetFrame(int n, int activationReason, void **
453453
}
454454

455455
// Free all allocated data on filter destruction
456-
static void VS_CC corrFree(void *instanceData, VSCore *core, const VSAPI *vsapi)
456+
static void VS_CC f2qcorrFree(void *instanceData, VSCore *core, const VSAPI *vsapi)
457457
{
458-
CorrData *d = (CorrData *)instanceData;
458+
F2QCorrData *d = (F2QCorrData *)instanceData;
459459
vsapi->freeNode(d->node[0]);
460460
vsapi->freeNode(d->node[1]);
461461
d-> fftwf_free(d->inBuf);
@@ -469,10 +469,10 @@ static void VS_CC corrFree(void *instanceData, VSCore *core, const VSAPI *vsapi)
469469
}
470470

471471
// This function is responsible for validating arguments and creating a new filter
472-
static void VS_CC corrCreate(const VSMap *in, VSMap *out, void *userData, VSCore *core, const VSAPI *vsapi)
472+
static void VS_CC f2qcorrCreate(const VSMap *in, VSMap *out, void *userData, VSCore *core, const VSAPI *vsapi)
473473
{
474-
CorrData d;
475-
CorrData *data;
474+
F2QCorrData d;
475+
F2QCorrData *data;
476476
int err;
477477
int temp;
478478
// Get a clip reference from the input arguments. This must be freed later.
@@ -485,14 +485,14 @@ static void VS_CC corrCreate(const VSMap *in, VSMap *out, void *userData, VSCore
485485

486486
if (!isSameFormat(d.avi, bvi) || d.avi->numFrames != bvi->numFrames )
487487
{
488-
vsapi->setError(out, "Corr: both clips must be of same format, length and frame dimensions ");
488+
vsapi->setError(out, "F2QCorr: both clips must be of same format, length and frame dimensions ");
489489
vsapi->freeNode(d.node[0]);
490490
vsapi->freeNode(d.node[1]);
491491
return;
492492
}
493493
if (d.avi->format->colorFamily == cmCompat)
494494
{
495-
vsapi->setError(out, "Corr: compat format is not accepted. Only Planar format clips can be input ");
495+
vsapi->setError(out, "F2QCorr: compat format is not accepted. Only Planar format clips can be input ");
496496
vsapi->freeNode(d.node[0]);
497497
vsapi->freeNode(d.node[1]);
498498
return;
@@ -502,7 +502,7 @@ static void VS_CC corrCreate(const VSMap *in, VSMap *out, void *userData, VSCore
502502
if (!isConstantFormat(d.avi) || d.avi->width == 0 || d.avi->height == 0
503503
|| d.avi->width != bvi->width || d.avi->height != bvi->height)
504504
{
505-
vsapi->setError(out, "Corr: only constant format and const frame dimensions input supported");
505+
vsapi->setError(out, "F2QCorr: only constant format and const frame dimensions input supported");
506506
vsapi->freeNode(d.node[0]);
507507
vsapi->freeNode(d.node[1]);
508508
return;
@@ -517,31 +517,31 @@ static void VS_CC corrCreate(const VSMap *in, VSMap *out, void *userData, VSCore
517517
// strict checking because of what we wrote in the argument string, the only
518518
// reason this could fail is when the value wasn't set by the user.
519519
// And when it's not set we want it to default to enabled.
520-
temp = !!vsapi->propGetInt(in, "txt", 0, &err);
520+
temp = !!int64ToIntS(vsapi->propGetInt(in, "txt", 0, &err));
521521
if (err || temp == 0)
522522
d.txt = false;
523523
else
524524
d.txt = true;
525525
if (d.txt)
526526
{
527-
temp = vsapi->propGetInt(in, "cx", 0, &err);
527+
temp = int64ToIntS(vsapi->propGetInt(in, "cx", 0, &err));
528528
if (err)
529529
d.cx = 20;
530530
else if (abs(temp) < 2 && abs(temp) > d.avi->width / 8)
531531
{
532-
vsapi->setError(out, "fqCorr: absolute values of cx must be between 2 and 1/8 frame wwidth");
532+
vsapi->setError(out, "F2QCorr: absolute values of cx must be between 2 and 1/8 frame wwidth");
533533
vsapi->freeNode(d.node[0]);
534534
vsapi->freeNode(d.node[1]);
535535
return;
536536
}
537537
else
538538
d.cx = abs(temp);
539-
temp = vsapi->propGetInt(in, "cy", 0, &err);
539+
temp = int64ToIntS(vsapi->propGetInt(in, "cy", 0, &err));
540540
if (err)
541541
d.cy = d.cx <= d.avi->height / 8 ? d.cx : d.avi->height / 8;
542542
else if (abs(temp) < 2 && abs(temp) > d.avi->height / 8)
543543
{
544-
vsapi->setError(out, "fqCorr: absolute values of cy must be between 2 and 1/8 frame height");
544+
vsapi->setError(out, "F2QCorr: absolute values of cy must be between 2 and 1/8 frame height");
545545
vsapi->freeNode(d.node[0]);
546546
vsapi->freeNode(d.node[1]);
547547
return;
@@ -554,7 +554,7 @@ static void VS_CC corrCreate(const VSMap *in, VSMap *out, void *userData, VSCore
554554
d.sf = 0;
555555
else if (d.sf < 0 || d.sf >= d.avi->numFrames - 1)
556556
{
557-
vsapi->setError(out, "fqCorr: sf must be within clip");
557+
vsapi->setError(out, "F2QCorr: sf must be within clip");
558558
vsapi->freeNode(d.node[0]);
559559
vsapi->freeNode(d.node[1]);
560560
return;
@@ -564,7 +564,7 @@ static void VS_CC corrCreate(const VSMap *in, VSMap *out, void *userData, VSCore
564564
d.ef = d.avi->numFrames - 1;
565565
else if (d.ef < d.sf || d.ef >= d.avi->numFrames)
566566
{
567-
vsapi->setError(out, "fqCorr: ef must not be less than sf and must be within clip");
567+
vsapi->setError(out, "F2QCorr: ef must not be less than sf and must be within clip");
568568
vsapi->freeNode(d.node[0]);
569569
vsapi->freeNode(d.node[1]);
570570
return;
@@ -576,7 +576,7 @@ static void VS_CC corrCreate(const VSMap *in, VSMap *out, void *userData, VSCore
576576
d.every = temp;
577577
else if (d.every < temp || d.every >= d.ef - d.sf)
578578
{
579-
vsapi->setError(out, "fqCorr: every should not result in either zero or over 1000 records");
579+
vsapi->setError(out, "F2QCorr: every should not result in either zero or over 1000 records");
580580
vsapi->freeNode(d.node[0]);
581581
vsapi->freeNode(d.node[1]);
582582
return;
@@ -585,7 +585,7 @@ static void VS_CC corrCreate(const VSMap *in, VSMap *out, void *userData, VSCore
585585
const char * fn = vsapi->propGetData(in, "filename", 0, &err);
586586
if (err)
587587
{
588-
vsapi->setError(out, "fqCorr: valid File name with full path must be specified");
588+
vsapi->setError(out, "F2QCorr: valid File name with full path must be specified");
589589
vsapi->freeNode(d.node[0]);
590590
vsapi->freeNode(d.node[1]);
591591
return;
@@ -597,10 +597,10 @@ static void VS_CC corrCreate(const VSMap *in, VSMap *out, void *userData, VSCore
597597

598598
// I usually keep the filter data struct on the stack and don't allocate it
599599
// until all the input validation is done.
600-
data = (CorrData *)malloc(sizeof(d));
600+
data = (F2QCorrData *)malloc(sizeof(d));
601601
*data = d;
602602

603-
vsapi->createFilter(in, out, "fqCorr", corrInit, corrGetFrame, corrFree, fmParallelRequests, 0, data, core);
603+
vsapi->createFilter(in, out, "F2QCorr", f2qcorrInit, f2qcorrGetFrame, f2qcorrFree, fmParallelRequests, 0, data, core);
604604
}
605605

606606
//registerFunc("fqCorr", "clip:clip;bclip:clip;cx:int:opt;cy:int:opt;

0 commit comments

Comments
 (0)