Skip to content

Commit 390212f

Browse files
committed
Implement 2d and 3d types as mlt_rect
Testing with the size parameter for CropOFX
1 parent 77b90b7 commit 390212f

3 files changed

Lines changed: 178 additions & 40 deletions

File tree

src/modules/openfx/filter_openfx.c

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -223,19 +223,31 @@ static void update_plugin_params(mlt_properties properties,
223223
if (!mlt_properties_exists(properties, param_name))
224224
continue;
225225
char *type = mlt_properties_get(param, "type");
226-
char *widget = mlt_properties_get(param, "widget");
227226
if (!type)
228227
continue;
229-
if (widget && (strcmp(widget, "point") == 0 || strcmp(widget, "size") == 0)
230-
&& strcmp(type, "float") == 0) {
228+
if (strcmp(type, "rect") == 0) {
231229
mlt_rect value = mlt_properties_anim_get_rect(properties, param_name, position, length);
232-
mltofx_param_set_value(image_effect_params, param_name, mltofx_prop_double2d, value);
233-
} else if (widget && (strcmp(widget, "point") == 0 || strcmp(widget, "size") == 0)
234-
&& strcmp(type, "integer") == 0) {
235-
mlt_rect value = mlt_properties_anim_get_rect(properties, param_name, position, length);
236-
int x = (int) value.x;
237-
int y = (int) value.y;
238-
mltofx_param_set_value(image_effect_params, param_name, mltofx_prop_int2d, x, y);
230+
// Look up the native OFX param type to select the correct setter
231+
mlt_properties ofx_param = mlt_properties_get_properties(image_effect_params,
232+
param_name);
233+
const char *ofx_type = ofx_param ? mlt_properties_get(ofx_param, "t") : NULL;
234+
if (ofx_type && strcmp(ofx_type, kOfxParamTypeInteger2D) == 0)
235+
mltofx_param_set_value(image_effect_params,
236+
param_name,
237+
mltofx_prop_int2d,
238+
(int) value.x,
239+
(int) value.y);
240+
else if (ofx_type && strcmp(ofx_type, kOfxParamTypeDouble3D) == 0)
241+
mltofx_param_set_value(image_effect_params, param_name, mltofx_prop_double3d, value);
242+
else if (ofx_type && strcmp(ofx_type, kOfxParamTypeInteger3D) == 0)
243+
mltofx_param_set_value(image_effect_params,
244+
param_name,
245+
mltofx_prop_int3d,
246+
(int) value.x,
247+
(int) value.y,
248+
(int) value.w);
249+
else
250+
mltofx_param_set_value(image_effect_params, param_name, mltofx_prop_double2d, value);
239251
} else if (strcmp(type, "float") == 0) {
240252
double value = mlt_properties_anim_get_double(properties, param_name, position, length);
241253
mltofx_param_set_value(image_effect_params, param_name, mltofx_prop_double, value);

src/modules/openfx/mlt_openfx.c

Lines changed: 154 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -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

23752432
void 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
}

src/modules/openfx/mlt_openfx.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ typedef enum {
4141
mltofx_prop_color = 32,
4242
mltofx_prop_double2d = 64,
4343
mltofx_prop_int2d = 128,
44+
mltofx_prop_double3d = 256,
45+
mltofx_prop_int3d = 512,
4446
} mltofx_property_type;
4547

4648
typedef enum {

0 commit comments

Comments
 (0)