66#include "libvmaf/picture.h"
77#include "libvmaf/cambi.h"
88
9- #include "VapourSynth .h"
10- #include "VSHelper .h"
9+ #include "VapourSynth4 .h"
10+ #include "VSHelper4 .h"
1111
1212typedef struct {
13- VSNodeRef * node ;
13+ VSNode * node ;
1414 VSVideoInfo vi ;
1515 CambiState s ;
1616 int bpc ;
1717 int scores ;
1818 float scaling ;
1919} CambiData ;
2020
21- static void VS_CC cambiInit (VSMap * in , VSMap * out , void * * instanceData , VSNode * node , VSCore * core , const VSAPI * vsapi ) {
22- CambiData * d = (CambiData * ) * instanceData ;
23- vsapi -> setVideoInfo (& d -> vi , 1 , node );
24- }
25-
26- static const VSFrameRef * VS_CC cambiGetFrame (int n , int activationReason , void * * instanceData , void * * frameData , VSFrameContext * frameCtx , VSCore * core , const VSAPI * vsapi ) {
27- CambiData * d = (CambiData * ) * instanceData ;
21+ static const VSFrame * VS_CC cambiGetFrame (int n , int activationReason , void * instanceData , void * * frameData , VSFrameContext * frameCtx , VSCore * core , const VSAPI * vsapi ) {
22+ CambiData * d = (CambiData * ) instanceData ;
2823
2924 if (activationReason == arInitial ) {
3025 vsapi -> requestFrameFilter (n , d -> node , frameCtx );
3126 } else if (activationReason == arAllFramesReady ) {
32- const VSFrameRef * src = vsapi -> getFrameFilter (n , d -> node , frameCtx );
27+ const VSFrame * src = vsapi -> getFrameFilter (n , d -> node , frameCtx );
3328 const unsigned int width = vsapi -> getFrameWidth (src , 0 );
3429 const unsigned int height = vsapi -> getFrameHeight (src , 0 );
35- VSFrameRef * dst = vsapi -> copyFrame (src , core );
30+ VSFrame * dst = vsapi -> copyFrame (src , core );
3631
3732 VmafPicture pic ; // shares memory with src
3833 pic .pix_fmt = VMAF_PIX_FMT_YUV400P ; // GRAY
@@ -60,12 +55,13 @@ static const VSFrameRef *VS_CC cambiGetFrame(int n, int activationReason, void *
6055 err = cambi_extract (& s , & pic , & score , d -> scores ? c_values : NULL );
6156 cambi_close (& s );
6257
63- VSMap * prop = vsapi -> getFramePropsRW (dst );
58+ VSMap * prop = vsapi -> getFramePropertiesRW (dst );
6459 if (d -> scores ) {
65- const VSFormat * grays = vsapi -> getFormatPreset (pfGrayS , core );
60+ VSVideoFormat grays ;
61+ vsapi -> getVideoFormatByID (& grays , pfGrayS , core );
6662 unsigned int w = width , h = height ;
6763 for (int i = 0 ; i < NUM_SCALES ; i ++ ) {
68- VSFrameRef * f = vsapi -> newVideoFrame (grays , w , h , src , core );
64+ VSFrame * f = vsapi -> newVideoFrame (& grays , w , h , src , core );
6965 float * dst = (float * )vsapi -> getWritePtr (f , 0 );
7066 float * src = c_values [i ];
7167 uintptr_t stride = vsapi -> getStride (f , 0 ) / sizeof * dst ;
@@ -80,14 +76,14 @@ static const VSFrameRef *VS_CC cambiGetFrame(int n, int activationReason, void *
8076 scale_dimension (& h , 1 );
8177 char name [16 ];
8278 sprintf (name , "CAMBI_SCALE%d" , i );
83- vsapi -> propSetFrame (prop , name , f , paReplace );
79+ vsapi -> mapSetFrame (prop , name , f , maReplace );
8480 vsapi -> freeFrame (f );
8581 }
8682 }
8783 vsapi -> freeFrame (src );
8884 assert (err == 0 );
8985
90- err = vsapi -> propSetFloat (prop , "CAMBI" , score , paReplace );
86+ err = vsapi -> mapSetFloat (prop , "CAMBI" , score , maReplace );
9187 assert (err == 0 );
9288
9389 return dst ;
@@ -107,17 +103,17 @@ static void VS_CC cambiFree(void *instanceData, VSCore *core, const VSAPI *vsapi
107103static void VS_CC cambiCreate (const VSMap * in , VSMap * out , void * userData , VSCore * core , const VSAPI * vsapi ) {
108104 CambiData d ;
109105
110- d .node = vsapi -> propGetNode (in , "clip" , 0 , 0 );
106+ d .node = vsapi -> mapGetNode (in , "clip" , 0 , 0 );
111107 d .vi = * vsapi -> getVideoInfo (d .node );
112108
113- if (!isConstantFormat (& d .vi ) || d .vi .format -> sampleType != stInteger ||
114- (d .vi .format -> colorFamily != cmGray && d .vi .format -> colorFamily != cmYUV ) ||
115- (d .vi .format -> bitsPerSample != 8 && d .vi .format -> bitsPerSample != 10 )) {
116- vsapi -> setError (out , "Cambi: only constant Gray/YUV format with 8/10bit integer samples supported" );
109+ if (!vsh_isConstantVideoFormat (& d .vi ) || d .vi .format . sampleType != stInteger ||
110+ (d .vi .format . colorFamily != cfGray && d .vi .format . colorFamily != cfYUV ) ||
111+ (d .vi .format . bitsPerSample != 8 && d .vi .format . bitsPerSample != 10 )) {
112+ vsapi -> mapSetError (out , "Cambi: only constant Gray/YUV format with 8/10bit integer samples supported" );
117113 vsapi -> freeNode (d .node );
118114 return ;
119115 }
120- d .bpc = d .vi .format -> bitsPerSample ;
116+ d .bpc = d .vi .format . bitsPerSample ;
121117
122118 cambi_config (& d .s );
123119#define GETARG (type , var , name , api , min , max ) \
@@ -128,34 +124,43 @@ static void VS_CC cambiCreate(const VSMap *in, VSMap *out, void *userData, VSCor
128124 if (x < min || x > max) { \
129125 char errmsg[256]; \
130126 snprintf(errmsg, sizeof errmsg, "Cambi: argument %s=%f is out of range [%f,%f] (default=%f)", #name, (double)x, (double)min, (double)max, (double)var.name); \
131- vsapi->setError (out, errmsg); \
127+ vsapi->mapSetError (out, errmsg); \
132128 vsapi->freeNode(d.node); \
133129 return; \
134130 } \
135131 var.name = x; \
136132 } while (0)
137- GETARG (int , d .s , window_size , propGetInt , 15 , 127 );
138- GETARG (double , d .s , topk , propGetFloat , 0.0001 , 1 );
139- GETARG (double , d .s , tvi_threshold , propGetFloat , 0.0001 , 1 );
133+ GETARG (int , d .s , window_size , mapGetInt , 15 , 127 );
134+ GETARG (double , d .s , topk , mapGetFloat , 0.0001 , 1 );
135+ GETARG (double , d .s , tvi_threshold , mapGetFloat , 0.0001 , 1 );
140136 d .scores = 0 ;
141- GETARG (int , d , scores , propGetInt , 0 , 1 );
137+ GETARG (int , d , scores , mapGetInt , 0 , 1 );
142138 d .scaling = 1.0f / d .s .window_size ;
143- GETARG (int , d , scaling , propGetFloat , 0 , 1 );
139+ GETARG (int , d , scaling , mapGetFloat , 0 , 1 );
144140#undef GETARG
145141
146142 int err = cambi_init (& d .s , d .vi .width , d .vi .height );
147143 if (err != 0 ) {
148- vsapi -> setError (out , "cambi_init failure" );
144+ vsapi -> mapSetError (out , "cambi_init failure" );
149145 vsapi -> freeNode (d .node );
150146 return ;
151147 }
152148
153149 CambiData * data = malloc (sizeof (d ));
154150 * data = d ;
155151
156- vsapi -> createFilter (in , out , "Cambi" , cambiInit , cambiGetFrame , cambiFree , fmParallel , 0 , data , core );
152+ VSFilterDependency deps [] = {{d .node , rpStrictSpatial }};
153+
154+ vsapi -> createVideoFilter (out , "Cambi" , & d .vi , cambiGetFrame , cambiFree , fmParallel , deps , 1 , data , core );
157155}
158156
159- void bandingInitialize (VSConfigPlugin configFunc , VSRegisterFunction registerFunc , VSPlugin * plugin ) {
160- registerFunc ("Cambi" , "clip:clip;window_size:int:opt;topk:float:opt;tvi_threshold:float:opt;scores:int:opt;scaling:float:opt;" , cambiCreate , 0 , plugin );
157+ void bandingInitialize (VSPlugin * plugin , const VSPLUGINAPI * vsapi ) {
158+ vsapi -> registerFunction (
159+ "Cambi" ,
160+ "clip:vnode;window_size:int:opt;topk:float:opt;tvi_threshold:float:opt;scores:int:opt;scaling:float:opt;" ,
161+ "clip:vnode" ,
162+ cambiCreate ,
163+ 0 ,
164+ plugin
165+ );
161166}
0 commit comments