-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
ISF4AE_UtilFunc.cpp
710 lines (559 loc) · 23.5 KB
/
ISF4AE_UtilFunc.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
#include "ISF4AE.h"
#include <regex>
#include <sstream>
#include "AEFX_SuiteHelper.h"
#include "Smart_Utils.h"
#include "AEUtil.h"
#include "Debug.h"
#include "SystemUtil.h"
PF_ParamIndex getIndexForUserParam(PF_ParamIndex index, UserParamType type) {
return Param_UserOffset + index * NumUserParamType + (int)type;
}
PF_ParamIndex getIdForUserParam(PF_ParamIndex index, UserParamType type) {
return ParamID::UserOffset + index * NumUserParamType + (int)type;
}
UserParamType getUserParamTypeForISFAttr(const VVISF::ISFAttrRef input) {
switch (input->type()) {
case VVISF::ISFValType_Bool:
return UserParamType_Bool;
case VVISF::ISFValType_Long:
if (input->valArray().size() == 0) {
return UserParamType_Float;
} else {
return UserParamType_Long;
}
case VVISF::ISFValType_Float:
switch (input->unit()) {
case VVISF::ISFValUnit_Angle:
case VVISF::ISFValUnit_Direction:
return UserParamType_Angle;
default:
return UserParamType_Float;
}
case VVISF::ISFValType_Point2D:
return UserParamType_Point2D;
case VVISF::ISFValType_Color:
return UserParamType_Color;
case VVISF::ISFValType_Image:
return UserParamType_Image;
default:
return UserParamType_Unsupported;
}
}
PF_Fixed getDefaultForAngleInput(VVISF::ISFAttrRef input) {
auto unit = input->unit();
double rad = input->defaultVal().getDoubleVal();
// If both min/max aren't specified, VVISF automatically set them to 0 and 1 respectively,
// and sets the default to their median value, 0.5. But 0.5 is not a nice round number in radians,
// so tries to set 0 degrees (in AE's rotery knobs UI) in such a case.
if (rad == 0.5f) {
rad = unit == VVISF::ISFValUnit_Direction ? (PI / 2.0) : 0.0;
}
if (unit == VVISF::ISFValUnit_Direction) {
return FLOAT2FIX(-(rad * 180.0 / PI) + 90.0);
} else { // (unit == ISFValUnit_Angle)
return FLOAT2FIX(-(rad * 180.0 / PI));
}
}
/**
* Check if an ISF input should be promoted and visible in Effect Conrol Window
*/
bool isISFAttrVisibleInECW(const VVISF::ISFAttrRef input) {
auto userParamType = getUserParamTypeForISFAttr(input);
auto& name = input->name();
bool isInputImage = name == "inputImage";
bool isISF4AESpecialAttr = name.rfind("i4a_") == 0;
if (userParamType == UserParamType_Unsupported || isInputImage || isISF4AESpecialAttr) {
return false;
}
return true;
}
/**
* Compile a shader and store to pool that maps code string to OGL::Program.
* It will be called at UpdateParameterUI and PreRender.
*/
shared_ptr<SceneDesc> getCompiledSceneDesc(GlobalData* globalData, const string& fsCode, const string& vsCode) {
if (fsCode.empty()) {
return globalData->notLoadedSceneDesc;
}
string key = fsCode + "__ISF_VERTEX__" + vsCode;
// Compile a shader at here to make sure to display the latest status
auto& scenes = *globalData->scenes;
if (scenes.has(key)) {
// Use cache
return scenes.get(key);
}
// Compile new shader if not exists
auto scene = VVISF::CreateISF4AESceneRefUsing(globalData->context->newContextSharingMe());
scene->setThrowExceptions(true);
scene->setManualTime(true);
auto desc = make_shared<SceneDesc>();
try {
scene->useCode(fsCode, vsCode);
auto errDict = scene->errDict();
if (errDict.size() > 0) {
throw ISFErr(ISFErrType_ErrorCompilingGLSL, "Linking Error", "", errDict);
}
if (scene->program() == 0) {
throw ISFErr(ISFErrType_Unknown, "Unknown Error", "", map<string, string>());
}
// Check if the number of inputs does not exceed the maximum
if (scene->inputs().size() > NumUserParams) {
map<string, string> errDict;
stringstream ss;
ss << "The number of inputs (" << scene->inputs().size() << ") exceeds the maximum number of supported inputs (" << NumUserParams << ")";
errDict["ia4ErrLog"] = ss.str();
auto err = ISFErr(ISFErrType_ErrorLoading, "Invalid ISF", "", errDict);
throw err;
}
desc->scene = scene;
desc->status = "Compiled Successfully";
} catch (VVISF::ISFErr isfErr) {
// On Failed, format and save the risen error.
desc->scene = globalData->defaultScene;
desc->status = isfErr.getTypeString();
desc->errorLog = "";
// Pretty-format the risen error
for (auto err : isfErr.details) {
if (err.first == "fragSrc" || err.first == "vertSrc") {
continue;
}
if (err.first == "fragErrLog" || err.first == "vertErrLog") {
// Omit the text "ERROR: 0:"
auto log = regex_replace(err.second, regex("ERROR: 0:"), "Line ");
desc->errorLog += log + "\n";
} else if (err.first == "jsonErrLog") {
string str = err.second;
smatch m;
regex re(R"(\[.+\] parse error at line ([0-9]+).+?: (.+); last read.*)");
if (regex_match(str, m, re)) {
string line = m[1].str();
string msg = m[2].str();
desc->errorLog += "Line " + line + ": " + msg + "\n";
} else {
desc->errorLog += err.second;
}
} else {
desc->errorLog += err.second;
}
}
} catch (...) {
auto* desc = new SceneDesc();
desc->scene = globalData->defaultScene;
desc->status = "Unknown Error";
desc->errorLog = "";
}
scenes.set(key, desc);
return desc;
}
/**
* Open the file dialog and load a shader, then set it to the ISF parameter.
*/
PF_Err loadISF(PF_InData* in_data, PF_OutData* out_data, PF_ParamDef* params[]) {
PF_Err err = PF_Err_NONE;
AEGP_SuiteHandler suites(in_data->pica_basicP);
auto* globalData = reinterpret_cast<GlobalData*>(suites.HandleSuite1()->host_lock_handle(in_data->global_data));
// Load a shader
vector<string> fileTypes = {"fs", "txt", "frag", "glsl"};
// Without this USELESS variable I'm getting a glitch, where the scene
// doesn't work without any errors
// FIXME: Dig into it to figure it out the reason
ISF4AESceneRef useless = VVISF::CreateISF4AESceneRefUsing(globalData->context->newContextSharingMe());
string isfDirectory = "";
ERR(AEUtil::getStringPersistentData(in_data, CONFIG_MATCH_NAME, "ISF Directory", DEFAULT_ISF_DIRECTORY, &isfDirectory));
string srcPath = SystemUtil::openFileDialog(fileTypes, isfDirectory, "Open ISF File");
if (!err && !srcPath.empty()) {
string fsCode = SystemUtil::readTextFile(srcPath);
isfDirectory = getDirname(srcPath);
ERR(AEUtil::setStringPersistentData(in_data, CONFIG_MATCH_NAME, "ISF Directory", isfDirectory));
if (!fsCode.empty()) {
params[Param_ISF]->uu.change_flags |= PF_ChangeFlag_CHANGED_VALUE;
auto* isf = reinterpret_cast<ParamArbIsf*>(*params[Param_ISF]->u.arb_d.value);
uint32_t userParamIndex = 0;
// Backup old params' values
auto oldScene = isf->desc->scene;
PF_ParamDefUnion oldParamValues[NumUserParams];
for (int i = 0; i < NumUserParams; i++) {
AEFX_CLR_STRUCT(oldParamValues[i]);
}
for (auto& oldInput : oldScene->inputs()) {
if (!isISFAttrVisibleInECW(oldInput)) {
continue;
}
UserParamType userParamType = getUserParamTypeForISFAttr(oldInput);
PF_ParamIndex index = getIndexForUserParam(userParamIndex, userParamType);
oldParamValues[userParamIndex] = params[index]->u;
userParamIndex++;
}
// Load the optional vertex shader (same algorithm with ISFDoc.cpp:80)
string noExtPath = VVGL::StringByDeletingExtension(srcPath);
string vsCode = "";
vsCode = SystemUtil::readTextFile(noExtPath + ".vs");
if (vsCode.empty()) {
vsCode = SystemUtil::readTextFile(noExtPath + ".vert");
}
isf->name = getBasename(srcPath);
isf->desc = getCompiledSceneDesc(globalData, fsCode, vsCode);
ERR(AEUtil::setEffectName(globalData->aegpId, in_data, isf->name));
// Set default values
auto desc = isf->desc;
bool isTransition = desc->scene->doc()->type() == VVISF::ISFFileType_Transition;
userParamIndex = 0;
for (auto& input : desc->scene->inputs()) {
if (!isISFAttrVisibleInECW(input)) {
continue;
}
auto userParamType = getUserParamTypeForISFAttr(input);
auto index = getIndexForUserParam(userParamIndex, userParamType);
auto& param = *params[index];
auto oldInput = oldScene->inputNamed(input->name());
PF_ParamDefUnion* oldValue = nullptr;
if (oldInput && oldInput->type() == input->type()) {
// When the old scene has an input with same name and type
auto idx = 0;
for (auto& oi : oldScene->inputs()) {
if (!isISFAttrVisibleInECW(oi)) {
continue;
}
if (oldInput == oi) {
oldValue = &oldParamValues[idx];
break;
}
idx++;
}
}
param.uu.change_flags |= PF_ChangeFlag_CHANGED_VALUE;
switch (userParamType) {
case UserParamType_Bool:
if (oldValue) {
param.u.bd.value = oldValue->bd.value;
} else {
param.u.bd.value = input->defaultVal().getBoolVal();
}
break;
case UserParamType_Long: {
A_long dephault = 1;
auto values = input->valArray();
if (oldValue) {
dephault = oldValue->pd.value;
} else {
auto dephaultIsfVal = input->defaultVal().getLongVal();
dephault = mmax(1, findIndex(values, dephaultIsfVal) + 1);
}
param.u.pd.value = dephault;
break;
}
case UserParamType_Float: {
double dephault = 0.0;
if (oldValue) {
dephault = oldValue->fs_d.value;
} else {
if (input->type() == VVISF::ISFValType_Float) {
dephault = input->defaultVal().getDoubleVal();
} else {
// input->type() == VVISF::ISFValType_Long
dephault = input->defaultVal().getLongVal();
}
auto unit = input->unit();
if (unit == VVISF::ISFValUnit_Length) {
dephault *= in_data->width;
} else if (unit == VVISF::ISFValUnit_Percent) {
dephault *= 100;
}
if (isTransition && input->name() == "progress") {
dephault = 0;
}
}
param.u.fs_d.value = dephault;
break;
}
case UserParamType_Angle:
if (oldValue) {
param.u.ad.value = oldValue->ad.value;
} else {
param.u.ad.value = getDefaultForAngleInput(input);
}
break;
case UserParamType_Point2D: {
if (oldValue) {
param.u.td.x_value = oldValue->td.x_value;
param.u.td.y_value = oldValue->td.y_value;
} else {
auto x = input->defaultVal().getPointValByIndex(0);
auto y = input->defaultVal().getPointValByIndex(1);
param.u.td.x_value = FLOAT2FIX(x * in_data->width);
param.u.td.y_value = FLOAT2FIX((1.0 - y) * in_data->height);
}
break;
}
case UserParamType_Color: {
if (oldValue) {
param.u.cd.value = oldValue->cd.value;
} else {
auto dephault = input->defaultVal();
param.u.cd.value.red = dephault.getColorValByChannel(0) * 255;
param.u.cd.value.green = dephault.getColorValByChannel(1) * 255;
param.u.cd.value.blue = dephault.getColorValByChannel(2) * 255;
param.u.cd.value.alpha = dephault.getColorValByChannel(3) * 255;
}
break;
}
case UserParamType_Image:
if (oldValue) {
param.u.ld = oldValue->ld;
}
break;
default:
break;
}
userParamIndex++;
} // End of for-each ISF's inputs
} else {
// On failed reading the text file, or simply it's empty
suites.ANSICallbacksSuite1()->sprintf(out_data->return_msg, "Cannot open the shader file: %s", srcPath.c_str());
out_data->out_flags = PF_OutFlag_DISPLAY_ERROR_MESSAGE;
}
}
suites.HandleSuite1()->host_unlock_handle(in_data->global_data);
return err;
}
/**
* Save the current shader.
*/
PF_Err saveISF(PF_InData* in_data, PF_OutData* out_data) {
PF_Err err = PF_Err_NONE, err2 = PF_Err_NONE;
AEGP_SuiteHandler suites(in_data->pica_basicP);
PF_ParamDef paramIsf;
AEFX_CLR_STRUCT(paramIsf);
ERR(PF_CHECKOUT_PARAM(in_data, Param_ISF, in_data->current_time, in_data->time_step, in_data->time_scale, ¶mIsf));
auto* isf = reinterpret_cast<ParamArbIsf*>(*paramIsf.u.arb_d.value);
string isfDirectory = "";
ERR(AEUtil::getStringPersistentData(in_data, CONFIG_MATCH_NAME, "ISF Directory", DEFAULT_ISF_DIRECTORY, &isfDirectory));
// Set name of an effect instance as default file name
string effectName = isf->name;
// Then confirm a destination path and save it
string dstPath = SystemUtil::saveFileDialog(effectName + ".fs", isfDirectory, "Save ISF File");
if (!err && !dstPath.empty()) {
string fsCode = isf->desc->scene->getFragCode();
SystemUtil::writeTextFile(dstPath, fsCode);
auto& vsCode = *isf->desc->scene->doc()->vertShaderSource();
if (!vsCode.empty()) {
auto noExtPath = VVGL::StringByDeletingExtension(dstPath);
SystemUtil::writeTextFile(noExtPath + ".vs", vsCode);
}
isfDirectory = getDirname(dstPath);
ERR(AEUtil::setStringPersistentData(in_data, CONFIG_MATCH_NAME, "ISF Directory", isfDirectory));
}
ERR2(PF_CHECKIN_PARAM(in_data, ¶mIsf));
return err;
}
VVGL::GLBufferRef createRGBATexWithBitdepth(const VVGL::Size& size, VVGL::GLContextRef context, short bitdepth) {
context->makeCurrentIfNotCurrent();
VVGL::GLBufferPoolRef bp = VVGL::GetGlobalBufferPool();
switch (bitdepth) {
case 8:
return VVGL::CreateRGBATex(size, true, bp);
case 16:
return VVGL::CreateRGBAShortTex(size, true, bp);
case 32:
return VVGL::CreateRGBAFloatTex(size, true, bp);
default:
throw invalid_argument("Invalid bitdepth");
}
}
VVGL::GLBufferRef createRGBACPUBufferWithBitdepthUsing(const VVGL::Size& inCPUBufferSizeInPixels,
const void* inCPUBackingPtr,
const VVGL::Size& inImageSizeInPixels,
const short bitdepth) {
switch (bitdepth) {
case 8:
return VVGL::CreateRGBACPUBufferUsing(inCPUBufferSizeInPixels, inCPUBackingPtr, inImageSizeInPixels, NULL, NULL);
case 16:
return VVGL::CreateRGBAShortCPUBufferUsing(inCPUBufferSizeInPixels, inCPUBackingPtr, inImageSizeInPixels, NULL, NULL);
case 32:
return VVGL::CreateRGBAFloatCPUBufferUsing(inCPUBufferSizeInPixels, inCPUBackingPtr, inImageSizeInPixels, NULL, NULL);
default:
throw invalid_argument("Invalid bitdepth");
}
}
PF_Err uploadCPUBufferInSmartRender(GlobalData* globalData,
PF_ProgPtr effectRef,
PF_SmartRenderExtra* extra,
A_long checkoutIndex,
const VVGL::Size outImageSize,
VVGL::GLBufferRef& outImage) {
PF_Err err = PF_Err_NONE, err2 = PF_Err_NONE;
auto bitdepth = extra->input->bitdepth;
auto pixelBytes = bitdepth * 4 / 8;
PF_LayerDef* layerDef = nullptr;
ERR(extra->cb->checkout_layer_pixels(effectRef, checkoutIndex, &layerDef));
if (layerDef != nullptr) {
// Stores the actual buffer size of images which has just done checkout-- affected by downsamples and cropping.
VVGL::Size imageSize(layerDef->width, layerDef->height);
VVGL::Size bufferSizeInPixel(layerDef->rowbytes / pixelBytes, imageSize.height);
if (imageSize.width > outImageSize.width || imageSize.height > outImageSize.height) {
// I dunno why, but this case seems to occur without any exception when AE tries to generate thumanil for
// project pane.
FX_LOG("the size of image being done checkout exceeds the original dimension.");
return err;
}
VVGL::GLBufferRef imageAECPU = createRGBACPUBufferWithBitdepthUsing(bufferSizeInPixel, layerDef->data, imageSize, bitdepth);
auto imageAE = globalData->uploader->uploadCPUToTex(imageAECPU);
// Note that AE's inputImage is cropped by mask's region and smaller than ISF resolution.
glBindTexture(GL_TEXTURE_2D, imageAE->name);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
glBindTexture(GL_TEXTURE_2D, 0);
auto origin = VVISF::ISFVal(VVISF::ISFValType_Point2D, layerDef->origin_x, layerDef->origin_y);
globalData->ae2glScene->setBufferForInputNamed(imageAE, "inputImage");
globalData->ae2glScene->setValueForInputNamed(origin, "origin");
outImage = createRGBATexWithBitdepth(outImageSize, globalData->context, bitdepth);
globalData->ae2glScene->renderToBuffer(outImage);
// Though ISF specs does not specify the wrap mode of texture, set it to CLAMP_TO_EDGE to match with online ISF
// editor's behavior.
glBindTexture(GL_TEXTURE_2D, outImage->name);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glBindTexture(GL_TEXTURE_2D, 0);
}
ERR2(extra->cb->checkin_layer_pixels(effectRef, checkoutIndex));
return err;
}
/**
* Renders ISF scene to CPU buffer. It's used at SmartRender() and DrawEvent(), and assuming image inputs are already
* bounded by the callees.
*/
PF_Err
renderISFToCPUBuffer(PF_InData* in_data, PF_OutData* out_data, ISF4AEScene& scene, short bitdepth, VVGL::Size& outSize, VVGL::Size& pointScale, VVGL::GLBufferRef* outBuffer) {
PF_Err err = PF_Err_NONE;
AEGP_SuiteHandler suites(in_data->pica_basicP);
auto* globalData = reinterpret_cast<GlobalData*>(suites.HandleSuite1()->host_lock_handle(in_data->global_data));
// In After Effects, 16-bit pixel doesn't use the highest bit, and thus each channel ranges 0x0000 - 0x8000.
// So after passing pixel buffer to GPU, it should be scaled by (0xffff / 0x8000) to normalize the luminance to
// 0.0-1.0.
VVISF::ISFVal multiplier16bit(VVISF::ISFValType_Float, bitdepth == 16 ? (65535.0f / 32768.0f) : 1.0f);
globalData->ae2glScene->setValueForInputNamed(multiplier16bit, "multiplier16bit");
globalData->gl2aeScene->setValueForInputNamed(multiplier16bit, "multiplier16bit");
// Render ISF
auto isfImage = createRGBATexWithBitdepth(outSize, globalData->context, bitdepth);
{
// Assign time-related variables
double fps = in_data->time_scale / in_data->local_time_step;
double time = 0;
PF_Boolean useLayerTime = false;
ERR(AEUtil::getCheckboxParam(in_data, out_data, Param_UseLayerTime, &useLayerTime));
if (useLayerTime) {
time = (double)in_data->current_time / in_data->time_scale;
} else {
ERR(AEUtil::getFloatSliderParam(in_data, out_data, Param_Time, &time));
}
scene.setRenderFrameIndex(time * fps);
scene.setRenderTimeDelta(1.0 / fps);
// Assign user-defined parameters
PF_ParamIndex userParamIndex = 0;
for (auto input : scene.inputs()) {
if (!isISFAttrVisibleInECW(input)) {
continue;
}
auto isfType = input->type();
auto userParamType = getUserParamTypeForISFAttr(input);
auto paramIndex = getIndexForUserParam(userParamIndex, userParamType);
VVISF::ISFVal* val = nullptr;
switch (userParamType) {
case UserParamType_Bool: {
PF_Boolean v = false;
ERR(AEUtil::getCheckboxParam(in_data, out_data, paramIndex, &v));
val = new VVISF::ISFVal(isfType, v);
break;
}
case UserParamType_Long: {
A_long index = 0;
ERR(AEUtil::getPopupParam(in_data, out_data, paramIndex, &index));
auto v = index - 1; // Index of popup UI begins from 1
if (input->valArray().size() > v) {
v = input->valArray()[index - 1];
} else {
v = v + input->minVal().getLongVal(); // ISFEditor behaviour
}
val = new VVISF::ISFVal(isfType, v);
break;
}
case UserParamType_Float: {
if (input->type() == VVISF::ISFValType_Float) {
A_FpLong v = 0.0;
ERR(AEUtil::getFloatSliderParam(in_data, out_data, paramIndex, &v));
VVISF::ISFValUnit unit = input->unit();
if (scene.doc()->type() == VVISF::ISFFileType_Transition && input->name() == "progress") {
unit = VVISF::ISFValUnit_Percent;
}
if (unit == VVISF::ISFValUnit_Length) {
v /= in_data->width;
} else if (unit == VVISF::ISFValUnit_Percent) {
v /= 100;
}
val = new VVISF::ISFVal(isfType, v);
} else {
// input->type() == VVISF::ISFValType_Long
A_FpLong floatIndex = 0.0;
ERR(AEUtil::getFloatSliderParam(in_data, out_data, paramIndex, &floatIndex));
A_long index = (A_long)floatIndex;
val = new VVISF::ISFVal(isfType, index);
}
break;
}
case UserParamType_Angle: {
A_FpLong v = 0.0;
AEUtil::getAngleParam(in_data, out_data, paramIndex, &v);
if (input->unit() == VVISF::ISFValUnit_Direction) {
v = (-v + 90.0) * (PI / 180.0);
} else { // unit == VVISF::ISFValUnit_Angle
v = -v * (PI / 180.0);
}
val = new VVISF::ISFVal(isfType, v);
break;
}
case UserParamType_Point2D: {
A_FloatPoint point;
ERR(AEUtil::getPointParam(in_data, out_data, paramIndex, &point));
// Since the above getter returns a coordinate considering downsampling, it requries to be compensated
// inversely to render an image for Custom Comp UI
point.x *= pointScale.width;
point.y *= pointScale.height;
// Should be converted to normalized and vertically-flipped coordinate
point.x = point.x / outSize.width;
point.y = 1.0 - point.y / outSize.height;
val = new VVISF::ISFVal(isfType, point.x, point.y);
break;
}
case UserParamType_Color: {
PF_PixelFloat color;
ERR(AEUtil::getColorParam(in_data, out_data, paramIndex, &color));
val = new VVISF::ISFVal(isfType, color.red, color.green, color.blue, color.alpha);
break;
}
case UserParamType_Image:
// Assumes the image has already bounded
break;
default:
FX_LOG("Invalid ISFValType.");
break;
}
if (val != nullptr) {
input->setCurrentVal(*val);
}
userParamIndex++;
} // End of for each ISF->inputs
// Then, render it!
scene.renderToBuffer(isfImage, outSize, time);
}
// Download the result of ISF
auto& gl2aeScene = *globalData->gl2aeScene;
gl2aeScene.setBufferForInputNamed(isfImage, "inputImage");
auto outputImage = createRGBATexWithBitdepth(outSize, globalData->context, bitdepth);
gl2aeScene.renderToBuffer(outputImage);
(*outBuffer) = globalData->downloader->downloadTexToCPU(outputImage);
// Release resources
VVGL::GetGlobalBufferPool()->housekeeping();
suites.HandleSuite1()->host_unlock_handle(in_data->global_data);
return err;
}