@@ -731,6 +731,8 @@ static OfxStatus paramDefine(OfxParamSetHandle paramSet,
731731 mlt_properties param_props = mlt_properties_new ();
732732 mlt_properties_set_properties (pt , "p" , param_props );
733733 mlt_properties_close (param_props );
734+ // Back-reference to the paramSet so paramGetValueImpl can navigate to image_effect.
735+ mlt_properties_set_data (pt , "_ps" , params , 0 , NULL , NULL );
734736 mlt_properties_set_properties (params , name , pt );
735737 mlt_properties_close (pt );
736738
@@ -1039,6 +1041,53 @@ static OfxStatus paramGetValueImpl(OfxParamHandle paramHandle, va_list ap)
10391041 if (status != kOfxStatOK ) {
10401042 * X = 0.0 ;
10411043 * Y = 0.0 ;
1044+ } else {
1045+ // If the default was declared in normalised coordinates, convert to canonical.
1046+ // kOfxParamPropDefaultCoordinateSystem may be set on the effect descriptor
1047+ // (via getPropertySet) rather than on the individual param descriptor.
1048+ mlt_properties paramset = mlt_properties_get_data (param , "_ps" , NULL );
1049+ mlt_properties plugin_props = paramset
1050+ ? mlt_properties_get_properties (paramset ,
1051+ "plugin_props" )
1052+ : NULL ;
1053+ mlt_properties ie = plugin_props
1054+ ? (mlt_properties ) mlt_properties_get_data (plugin_props ,
1055+ "_ie" ,
1056+ NULL )
1057+ : NULL ;
1058+ char * coord_sys = kOfxParamCoordinatesCanonical ;
1059+ OfxStatus cs_on_param = propGetString ((OfxPropertySetHandle ) param_props ,
1060+ kOfxParamPropDefaultCoordinateSystem ,
1061+ 0 ,
1062+ & coord_sys );
1063+ if (cs_on_param != kOfxStatOK ) {
1064+ coord_sys = kOfxParamCoordinatesCanonical ;
1065+ if (ie ) {
1066+ mlt_properties effect_props = mlt_properties_get_properties (ie , "props" );
1067+ if (effect_props )
1068+ propGetString ((OfxPropertySetHandle ) effect_props ,
1069+ kOfxParamPropDefaultCoordinateSystem ,
1070+ 0 ,
1071+ & coord_sys );
1072+ }
1073+ }
1074+ if (strcmp (coord_sys , kOfxParamCoordinatesNormalised ) == 0 ) {
1075+ if (ie ) {
1076+ double ext_w = 0.0 , ext_h = 0.0 ;
1077+ propGetDouble ((OfxPropertySetHandle ) ie ,
1078+ kOfxImageEffectPropProjectExtent ,
1079+ 0 ,
1080+ & ext_w );
1081+ propGetDouble ((OfxPropertySetHandle ) ie ,
1082+ kOfxImageEffectPropProjectExtent ,
1083+ 1 ,
1084+ & ext_h );
1085+ if (ext_w > 0.0 )
1086+ * X *= ext_w ;
1087+ if (ext_h > 0.0 )
1088+ * Y *= ext_h ;
1089+ }
1090+ }
10421091 }
10431092 }
10441093 } else if (strcmp (param_type , kOfxParamTypeInteger2D ) == 0 ) {
@@ -2370,6 +2419,14 @@ void mltofx_init_host_properties(OfxPropertySetHandle host_properties)
23702419 propSetInt (host_properties , kOfxParamHostPropPageRowColumnCount , 0 , 0 );
23712420 propSetInt (host_properties , kOfxParamHostPropPageRowColumnCount , 1 , 0 );
23722421 propSetInt (host_properties , kOfxParamHostPropSupportsParametricAnimation , 0 , 0 );
2422+ // Declare support for normalised default coordinate systems on Double2D/Double params.
2423+ // When present, plugins call setDefaultCoordinateSystem(eCoordinatesNormalised) on param
2424+ // descriptors whose defaults are expressed in normalized [0,1] coordinates, which our
2425+ // metadata loop then reads as normalized_coordinates="yes".
2426+ propSetString (host_properties ,
2427+ kOfxParamPropDefaultCoordinateSystem ,
2428+ 0 ,
2429+ kOfxParamCoordinatesNormalised );
23732430}
23742431
23752432void mltofx_create_instance (OfxPlugin * plugin , mlt_properties image_effect )
@@ -2912,6 +2969,9 @@ void *mltofx_fetch_params(OfxPlugin *plugin, mlt_properties params, mlt_properti
29122969 mlt_properties_set_properties (image_effect , "params" , iparams );
29132970 mlt_properties_set_properties (iparams , "plugin_props" , props );
29142971 mlt_properties_set_properties (image_effect , "mltofx_params" , params );
2972+ // Back-reference to image_effect stored on plugin_props so paramGetValueImpl
2973+ // can access project extent without disturbing the param iteration loop.
2974+ mlt_properties_set_data (props , "_ie" , image_effect , 0 , NULL , NULL );
29152975
29162976 propSetString ((OfxPropertySetHandle ) props ,
29172977 kOfxImageEffectPropContext ,
@@ -3067,18 +3127,19 @@ void *mltofx_fetch_params(OfxPlugin *plugin, mlt_properties params, mlt_properti
30673127 || strcmp (param_type , kOfxParamTypeRGB ) == 0 ) {
30683128 mlt_properties_set (p , "type" , "color" );
30693129 mlt_properties_set (p , "widget" , "color" );
3070- } else if (strcmp (param_type , kOfxParamTypeDouble2D )
3071- == 0 ) { // can be rendered as 2 double number input fields
3072- mlt_properties_set (p , "type" , "float" );
3130+ } else if (strcmp (param_type , kOfxParamTypeDouble2D ) == 0 ) {
3131+ mlt_properties_set (p , "type" , "rect" );
30733132
30743133 char * type = kOfxParamDoubleTypeXY ;
30753134 char * coordinate_system = kOfxParamCoordinatesCanonical ;
30763135 propGetString ((OfxPropertySetHandle ) ppp , kOfxParamPropDoubleType , 0 , & type );
3077- propGetString ((OfxPropertySetHandle ) ppp ,
3078- kOfxParamPropDefaultCoordinateSystem ,
3079- 0 ,
3080- & coordinate_system );
3081-
3136+ OfxStatus status = propGetString ((OfxPropertySetHandle ) ppp ,
3137+ kOfxParamPropDefaultCoordinateSystem ,
3138+ 0 ,
3139+ & coordinate_system );
3140+ if (status != kOfxStatOK ) {
3141+ coordinate_system = kOfxParamCoordinatesCanonical ;
3142+ }
30823143 if (strcmp (type , kOfxParamDoubleTypeXYAbsolute ) == 0 ) {
30833144 mlt_properties_set (p , "widget" , "point" );
30843145 } else if (strcmp (type , kOfxParamDoubleTypeXY ) == 0 ) {
@@ -3091,8 +3152,11 @@ void *mltofx_fetch_params(OfxPlugin *plugin, mlt_properties params, mlt_properti
30913152 mlt_properties_set (p , "normalized_coordinates" , "yes" );
30923153 }
30933154 } else if (strcmp (param_type , kOfxParamTypeInteger2D ) == 0 ) {
3094- // can be rendered as 2 integer number input fields
3095- mlt_properties_set (p , "type" , "integer" );
3155+ mlt_properties_set (p , "type" , "rect" );
3156+ } else if (strcmp (param_type , kOfxParamTypeDouble3D ) == 0 ) {
3157+ mlt_properties_set (p , "type" , "rect" );
3158+ } else if (strcmp (param_type , kOfxParamTypeInteger3D ) == 0 ) {
3159+ mlt_properties_set (p , "type" , "rect" );
30963160 }
30973161
30983162 int layout_hint = 0 ;
@@ -3155,26 +3219,50 @@ void *mltofx_fetch_params(OfxPlugin *plugin, mlt_properties params, mlt_properti
31553219 propGetDouble ((OfxPropertySetHandle ) ppp , p_name , 0 , & default_value );
31563220 mlt_properties_set_double (p , "default" , default_value );
31573221 } else if (strcmp (param_type , kOfxParamTypeDouble2D ) == 0 ) {
3158- double default_value1 = 0.0 , default_value2 = 0.0 ;
3159-
3160- propGetDouble ((OfxPropertySetHandle ) ppp , p_name , 0 , & default_value1 );
3161- propGetDouble ((OfxPropertySetHandle ) ppp , p_name , 1 , & default_value2 );
3162-
3163- // for some reason with DBL_MIN DBL_MAX it segfault
3164- if (!isnormal (default_value1 ) || default_value1 <= FLT_MIN
3165- || default_value1 >= FLT_MAX )
3166- default_value1 = 0.0 ;
3167- if (!isnormal (default_value2 ) || default_value2 <= FLT_MIN
3168- || default_value2 >= FLT_MAX )
3169- default_value2 = 0.0 ;
3170-
3171- char default_value [90 ] = "" ;
3172- snprintf (default_value ,
3173- sizeof (default_value ),
3174- "%.4f %.4f" ,
3175- default_value1 ,
3176- default_value2 );
3177- mlt_properties_set (p , "default" , default_value );
3222+ double x = 0.0 , y = 0.0 ;
3223+
3224+ propGetDouble ((OfxPropertySetHandle ) ppp , p_name , 0 , & x );
3225+ propGetDouble ((OfxPropertySetHandle ) ppp , p_name , 1 , & y );
3226+
3227+ // Validate and sanitize values
3228+ if (!isnormal (x ) || x <= FLT_MIN || x >= FLT_MAX )
3229+ x = 0.0 ;
3230+ if (!isnormal (y ) || y <= FLT_MIN || y >= FLT_MAX )
3231+ y = 0.0 ;
3232+
3233+ mlt_rect r = {x , y , 0 , 0 , 1 };
3234+ mlt_properties_set_rect (p , "default" , r );
3235+
3236+ } else if (strcmp (param_type , kOfxParamTypeInteger2D ) == 0 ) {
3237+ int ix = 0 , iy = 0 ;
3238+ propGetInt ((OfxPropertySetHandle ) ppp , p_name , 0 , & ix );
3239+ propGetInt ((OfxPropertySetHandle ) ppp , p_name , 1 , & iy );
3240+ mlt_rect r = {ix , iy , 0 , 0 , 1 };
3241+ mlt_properties_set_rect (p , "default" , r );
3242+
3243+ } else if (strcmp (param_type , kOfxParamTypeDouble3D ) == 0 ) {
3244+ double x3 = 0.0 , y3 = 0.0 , z3 = 0.0 ;
3245+ propGetDouble ((OfxPropertySetHandle ) ppp , p_name , 0 , & x3 );
3246+ propGetDouble ((OfxPropertySetHandle ) ppp , p_name , 1 , & y3 );
3247+ propGetDouble ((OfxPropertySetHandle ) ppp , p_name , 2 , & z3 );
3248+ if (!isnormal (x3 ) || x3 <= FLT_MIN || x3 >= FLT_MAX )
3249+ x3 = 0.0 ;
3250+ if (!isnormal (y3 ) || y3 <= FLT_MIN || y3 >= FLT_MAX )
3251+ y3 = 0.0 ;
3252+ if (!isnormal (z3 ) || z3 <= FLT_MIN || z3 >= FLT_MAX )
3253+ z3 = 0.0 ;
3254+ // rect.w holds the third dimension
3255+ mlt_rect r = {x3 , y3 , z3 , 0 , 1 };
3256+ mlt_properties_set_rect (p , "default" , r );
3257+
3258+ } else if (strcmp (param_type , kOfxParamTypeInteger3D ) == 0 ) {
3259+ int ix = 0 , iy = 0 , iz = 0 ;
3260+ propGetInt ((OfxPropertySetHandle ) ppp , p_name , 0 , & ix );
3261+ propGetInt ((OfxPropertySetHandle ) ppp , p_name , 1 , & iy );
3262+ propGetInt ((OfxPropertySetHandle ) ppp , p_name , 2 , & iz );
3263+ // rect.w holds the third dimension
3264+ mlt_rect r = {ix , iy , iz , 0 , 1 };
3265+ mlt_properties_set_rect (p , "default" , r );
31783266
31793267 } else if (strcmp (param_type , kOfxParamTypeString ) == 0 ) {
31803268 char * default_value = "" ;
@@ -3251,6 +3339,16 @@ void *mltofx_fetch_params(OfxPlugin *plugin, mlt_properties params, mlt_properti
32513339 double minimum_value = 0.0 ;
32523340 propGetDouble ((OfxPropertySetHandle ) ppp , p_name , 0 , & minimum_value );
32533341 mlt_properties_set_double (p , "minimum" , minimum_value );
3342+ } else if (strcmp (param_type , kOfxParamTypeDouble2D ) == 0 ) {
3343+ min_set = 1 ;
3344+ double minimum_value = 0.0 ;
3345+ propGetDouble ((OfxPropertySetHandle ) ppp , p_name , 0 , & minimum_value );
3346+ mlt_properties_set_double (p , "minimum" , minimum_value );
3347+ } else if (strcmp (param_type , kOfxParamTypeInteger2D ) == 0 ) {
3348+ min_set = 1 ;
3349+ int minimum_value = 0 ;
3350+ propGetInt ((OfxPropertySetHandle ) ppp , p_name , 0 , & minimum_value );
3351+ mlt_properties_set_int (p , "minimum" , minimum_value );
32543352 } else if (strcmp (param_type , kOfxParamTypeString ) == 0 ) {
32553353 char * minimum_value = "" ;
32563354 propGetString ((OfxPropertySetHandle ) ppp , p_name , 0 , & minimum_value );
@@ -3269,6 +3367,16 @@ void *mltofx_fetch_params(OfxPlugin *plugin, mlt_properties params, mlt_properti
32693367 double maximum_value = 0.0 ;
32703368 propGetDouble ((OfxPropertySetHandle ) ppp , p_name , 0 , & maximum_value );
32713369 mlt_properties_set_double (p , "maximum" , maximum_value );
3370+ } else if (strcmp (param_type , kOfxParamTypeDouble2D ) == 0 ) {
3371+ max_set = 1 ;
3372+ double maximum_value = 0.0 ;
3373+ propGetDouble ((OfxPropertySetHandle ) ppp , p_name , 0 , & maximum_value );
3374+ mlt_properties_set_double (p , "maximum" , maximum_value );
3375+ } else if (strcmp (param_type , kOfxParamTypeInteger2D ) == 0 ) {
3376+ max_set = 1 ;
3377+ int maximum_value = 0 ;
3378+ propGetInt ((OfxPropertySetHandle ) ppp , p_name , 0 , & maximum_value );
3379+ mlt_properties_set_int (p , "maximum" , maximum_value );
32723380 } else if (strcmp (param_type , kOfxParamTypeString ) == 0 ) {
32733381 char * maximum_value = "" ;
32743382 propGetString ((OfxPropertySetHandle ) ppp , p_name , 0 , & maximum_value );
@@ -3353,6 +3461,22 @@ void mltofx_param_set_value(mlt_properties params, char *key, mltofx_property_ty
33533461 propSetInt ((OfxPropertySetHandle ) param_props , "MltOfxParamValue" , 1 , y );
33543462 } break ;
33553463
3464+ case mltofx_prop_double3d : {
3465+ mlt_rect value = va_arg (ap , mlt_rect );
3466+ propSetDouble ((OfxPropertySetHandle ) param_props , "MltOfxParamValue" , 0 , value .x );
3467+ propSetDouble ((OfxPropertySetHandle ) param_props , "MltOfxParamValue" , 1 , value .y );
3468+ propSetDouble ((OfxPropertySetHandle ) param_props , "MltOfxParamValue" , 2 , value .w );
3469+ } break ;
3470+
3471+ case mltofx_prop_int3d : {
3472+ int x = va_arg (ap , int );
3473+ int y = va_arg (ap , int );
3474+ int z = va_arg (ap , int );
3475+ propSetInt ((OfxPropertySetHandle ) param_props , "MltOfxParamValue" , 0 , x );
3476+ propSetInt ((OfxPropertySetHandle ) param_props , "MltOfxParamValue" , 1 , y );
3477+ propSetInt ((OfxPropertySetHandle ) param_props , "MltOfxParamValue" , 2 , z );
3478+ } break ;
3479+
33563480 default :
33573481 break ;
33583482 }
0 commit comments