-
Notifications
You must be signed in to change notification settings - Fork 119
/
ofxsImageEffect.cpp
2991 lines (2558 loc) · 109 KB
/
ofxsImageEffect.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
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright OpenFX and contributors to the OpenFX project.
// SPDX-License-Identifier: BSD-3-Clause
/** @brief This file contains code that skins the ofx effect suite */
#include "ofxsSupportPrivate.h"
#include <algorithm> // for find
#include <cstring> // for strlen
#ifdef DEBUG
#include <iostream>
#endif
#include <stdexcept>
#ifdef OFX_SUPPORTS_OPENGLRENDER
#include "ofxGPURender.h"
#endif
#include "ofxsCore.h"
#if defined __APPLE__ || defined linux || defined __FreeBSD__
# if __GNUC__ >= 4
# define EXPORT __attribute__((visibility("default")))
# define LOCAL __attribute__((visibility("hidden")))
# else
# define EXPORT
# define LOCAL
# endif
#elif defined _WIN32
# define EXPORT OfxExport
# define LOCAL
#else
# error Not building on your operating system quite yet
#endif
// string utility functions
static bool ends_with(std::string const & value, std::string const & ending)
{
if (ending.size() > value.size()) return false;
return std::equal(ending.rbegin(), ending.rend(), value.rbegin());
}
static bool starts_with(std::string const & value, std::string const & beginning)
{
if (beginning.size() > value.size()) return false;
return std::equal(beginning.begin(), beginning.end(), value.begin());
}
/** @brief The core 'OFX Support' namespace, used by plugin implementations. All code for these are defined in the common support libraries. */
namespace OFX {
// globals to keep consistent data structures around.
OFX::PluginFactoryArray plugIDs;
//Put it all into a map, so we know when to delete what!
struct OfxPlugInfo
{
OfxPlugInfo() = default;
OfxPlugInfo(OFX::PluginFactory* f, std::unique_ptr<OfxPlugin> p):_factory(f), _plug(std::move(p)){}
OFX::PluginFactory* _factory = nullptr;
std::unique_ptr<OfxPlugin> _plug;
};
typedef std::map<std::string, OfxPlugInfo> OfxPlugInfoMap;
OfxPlugInfoMap plugInfoMap;
typedef std::vector<OfxPlugin*> OfxPluginArray;
OfxPluginArray ofxPlugs;
/** @brief the global host description */
ImageEffectHostDescription gHostDescription;
bool gHostDescriptionHasInit = false;
bool ImageEffectHostDescription::supportsPixelComponent(const PixelComponentEnum component) const
{
return std::find(_supportedComponents.begin(), _supportedComponents.end(), component) != _supportedComponents.end();
}
bool ImageEffectHostDescription::supportsBitDepth( const BitDepthEnum bitDepth) const
{
return std::find(_supportedPixelDepths.begin(), _supportedPixelDepths.end(), bitDepth) != _supportedPixelDepths.end();
}
bool ImageEffectHostDescription::supportsContext(const ContextEnum context) const
{
return std::find(_supportedContexts.begin(), _supportedContexts.end(), context) != _supportedContexts.end();
}
/** @return default pixel depth supported by host application. */
BitDepthEnum ImageEffectHostDescription::getDefaultPixelDepth() const
{
if(!_supportedPixelDepths.empty()) {
return _supportedPixelDepths[0];
} else {
OFX::Log::warning(true, "The host doesn't define supported pixel depth. (size: %d)", (int)_supportedPixelDepths.size());
return eBitDepthFloat;
}
}
/** @return default pixel component supported by host application. */
PixelComponentEnum ImageEffectHostDescription::getDefaultPixelComponent() const
{
if(! _supportedComponents.empty()) {
return _supportedComponents[0];
} else {
OFX::Log::warning(true, "The host doesn't define supported pixel component. (size: %d)", _supportedComponents.size());
return ePixelComponentRGBA;
}
}
ImageEffectHostDescription* getImageEffectHostDescription()
{
if(gHostDescriptionHasInit)
return &gHostDescription;
return NULL;
}
namespace Private {
// Suite and host pointers
OfxHost *gHost = 0;
OfxImageEffectSuiteV1 *gEffectSuite = 0;
OfxPropertySuiteV1 *gPropSuite = 0;
OfxInteractSuiteV1 *gInteractSuite = 0;
OfxParameterSuiteV1 *gParamSuite = 0;
OfxMemorySuiteV1 *gMemorySuite = 0;
OfxMultiThreadSuiteV1 *gThreadSuite = 0;
OfxMessageSuiteV1 *gMessageSuite = 0;
OfxMessageSuiteV2 *gMessageSuiteV2 = 0;
OfxProgressSuiteV1 *gProgressSuiteV1 = 0;
OfxProgressSuiteV2 *gProgressSuiteV2 = 0;
OfxTimeLineSuiteV1 *gTimeLineSuite = 0;
OfxParametricParameterSuiteV1 *gParametricParameterSuite = 0;
#ifdef OFX_SUPPORTS_OPENGLRENDER
OfxImageEffectOpenGLRenderSuiteV1 *gOpenGLRenderSuite = 0;
#endif
// @brief the set of descriptors, one per context used by kOfxActionDescribeInContext,
//'eContextNone' is the one used by the kOfxActionDescribe
EffectDescriptorMap gEffectDescriptors;
};
/** @brief map a std::string to a context */
ContextEnum mapToContextEnum(const std::string &s)
{
if(s == kOfxImageEffectContextGenerator) return eContextGenerator;
if(s == kOfxImageEffectContextFilter) return eContextFilter;
if(s == kOfxImageEffectContextTransition) return eContextTransition;
if(s == kOfxImageEffectContextPaint) return eContextPaint;
if(s == kOfxImageEffectContextGeneral) return eContextGeneral;
if(s == kOfxImageEffectContextRetimer) return eContextRetimer;
OFX::Log::error(true, "Unknown image effect context '%s'", s.c_str());
throw std::invalid_argument(s);
}
const char* mapContextEnumToStr(ContextEnum context)
{
switch (context) {
case eContextGenerator:
return kOfxImageEffectContextGenerator;
case eContextFilter:
return kOfxImageEffectContextFilter;
case eContextTransition:
return kOfxImageEffectContextTransition;
case eContextPaint:
return kOfxImageEffectContextPaint;
case eContextGeneral:
return kOfxImageEffectContextGeneral;
case eContextRetimer:
return kOfxImageEffectContextRetimer;
default:
OFX::Log::error(true, "Unknown context enum '%d'", (int)context);
throw std::invalid_argument("unknown ContextEnum");
}
}
const char* mapMessageTypeEnumToStr(OFX::Message::MessageTypeEnum type)
{
if(type == OFX::Message::eMessageFatal)
return kOfxMessageFatal;
else if(type == OFX::Message::eMessageError)
return kOfxMessageError;
else if(type == OFX::Message::eMessageMessage)
return kOfxMessageMessage;
else if(type == OFX::Message::eMessageWarning)
return kOfxMessageWarning;
else if(type == OFX::Message::eMessageLog)
return kOfxMessageLog;
else if(type == OFX::Message::eMessageQuestion)
return kOfxMessageQuestion;
OFX::Log::error(true, "Unknown message type enum '%d'", type);
return 0;
}
OFX::Message::MessageReplyEnum mapToMessageReplyEnum(OfxStatus stat)
{
if(stat == kOfxStatOK)
return OFX::Message::eMessageReplyOK;
else if(stat == kOfxStatReplyYes)
return OFX::Message::eMessageReplyYes;
else if(stat == kOfxStatReplyNo)
return OFX::Message::eMessageReplyNo;
else if(stat == kOfxStatFailed)
return OFX::Message::eMessageReplyFailed;
OFX::Log::error(true, "Unknown message reply status enum '%d'", stat);
return OFX::Message::eMessageReplyFailed;
}
/** @brief map a std::string to a context */
InstanceChangeReason mapToInstanceChangedReason(const std::string &s)
{
if(s == kOfxChangePluginEdited) return eChangePluginEdit;
if(s == kOfxChangeUserEdited) return eChangeUserEdit;
if(s == kOfxChangeTime) return eChangeTime;
OFX::Log::error(true, "Unknown instance changed reason '%s'", s.c_str());
throw std::invalid_argument(s);
}
/** @brief turns a bit depth string into and enum */
BitDepthEnum mapStrToBitDepthEnum(const std::string &str)
{
if(str == kOfxBitDepthByte) {
return eBitDepthUByte;
}
else if(str == kOfxBitDepthShort) {
return eBitDepthUShort;
}
else if(str == kOfxBitDepthHalf) {
return eBitDepthHalf;
}
else if(str == kOfxBitDepthFloat) {
return eBitDepthFloat;
}
else if(str == kOfxBitDepthNone) {
return eBitDepthNone;
}
else {
return eBitDepthCustom;
}
}
/** @brief turns a bit depth string into and enum */
const char* mapBitDepthEnumToStr(BitDepthEnum bitDepth)
{
switch (bitDepth) {
case eBitDepthUByte:
return kOfxBitDepthByte;
case eBitDepthUShort:
return kOfxBitDepthShort;
case eBitDepthHalf:
return kOfxBitDepthHalf;
case eBitDepthFloat:
return kOfxBitDepthFloat;
case eBitDepthNone:
return kOfxBitDepthNone;
case eBitDepthCustom:
return "OfxBitDepthCustom";
default:
OFX::Log::error(true, "Unknown bit depth enum '%d'", (int)bitDepth);
throw std::invalid_argument("unknown BitDepthEnum");
}
}
/** @brief turns a pixel component string into and enum */
PixelComponentEnum mapStrToPixelComponentEnum(const std::string &str)
{
if(str == kOfxImageComponentRGBA) {
return ePixelComponentRGBA;
}
else if(str == kOfxImageComponentRGB) {
return ePixelComponentRGB;
}
else if(str == kOfxImageComponentAlpha) {
return ePixelComponentAlpha;
}
else if(str == kOfxImageComponentNone) {
return ePixelComponentNone;
}
else {
return ePixelComponentCustom;
}
}
/** @brief turns a pixel component string into and enum */
const char* mapPixelComponentEnumToStr(PixelComponentEnum pixelComponent)
{
switch (pixelComponent) {
case ePixelComponentRGBA:
return kOfxImageComponentRGBA;
case ePixelComponentRGB:
return kOfxImageComponentRGB;
case ePixelComponentAlpha:
return kOfxImageComponentAlpha;
case ePixelComponentCustom:
return "OfxImageComponentCustom";
default:
OFX::Log::error(true, "Unknown pixel component enum '%d'", (int)pixelComponent);
throw std::invalid_argument("unknown PixelComponentEnum");
}
}
/** @brief turns a premultiplication string into and enum */
static PreMultiplicationEnum mapStrToPreMultiplicationEnum(const std::string &str)
{
if(str == kOfxImageOpaque) {
return eImageOpaque;
}
else if(str == kOfxImagePreMultiplied) {
return eImagePreMultiplied;
}
else if(str == kOfxImageUnPreMultiplied) {
return eImageUnPreMultiplied;
}
else {
throw std::invalid_argument("");
}
}
/** @brief turns a field string into and enum */
FieldEnum mapStrToFieldEnum(const std::string &str)
{
if(str == kOfxImageFieldNone) {
return eFieldNone;
}
else if(str == kOfxImageFieldBoth) {
return eFieldBoth;
}
else if(str == kOfxImageFieldLower) {
return eFieldLower;
}
else if(str == kOfxImageFieldUpper) {
return eFieldUpper;
}
else {
throw std::invalid_argument("");
}
}
////////////////////////////////////////////////////////////////////////////////
// clip descriptor
/** @brief hidden constructor */
ClipDescriptor::ClipDescriptor(const std::string &name, OfxPropertySetHandle props)
: _clipName(name)
, _clipProps(props)
{
OFX::Validation::validateClipDescriptorProperties(props);
}
/** @brief set the label properties */
void ClipDescriptor::setLabel(const std::string &label)
{
_clipProps.propSetString(kOfxPropLabel, label);
}
/** @brief set the label properties */
void ClipDescriptor::setLabels(const std::string &label, const std::string &shortLabel, const std::string &longLabel)
{
setLabel(label);
_clipProps.propSetString(kOfxPropShortLabel, shortLabel, false);
_clipProps.propSetString(kOfxPropLongLabel, longLabel, false);
}
/** @brief set how fielded images are extracted from the clip defaults to eFieldExtractDoubled */
void ClipDescriptor::setFieldExtraction(FieldExtractionEnum v)
{
switch(v)
{
case eFieldExtractBoth :
_clipProps.propSetString(kOfxImageClipPropFieldExtraction, kOfxImageFieldBoth);
break;
case eFieldExtractSingle :
_clipProps.propSetString(kOfxImageClipPropFieldExtraction, kOfxImageFieldSingle);
break;
case eFieldExtractDoubled :
_clipProps.propSetString(kOfxImageClipPropFieldExtraction, kOfxImageFieldDoubled);
break;
}
}
/** @brief set which components are supported, defaults to none set, this must be called at least once! */
void ClipDescriptor::addSupportedComponent(PixelComponentEnum v)
{
int n = _clipProps.propGetDimension(kOfxImageEffectPropSupportedComponents);
switch(v)
{
case ePixelComponentNone :
_clipProps.propSetString(kOfxImageEffectPropSupportedComponents, kOfxImageComponentNone, n);
break;
case ePixelComponentRGBA :
_clipProps.propSetString(kOfxImageEffectPropSupportedComponents, kOfxImageComponentRGBA, n);
break;
case ePixelComponentRGB :
_clipProps.propSetString(kOfxImageEffectPropSupportedComponents, kOfxImageComponentRGB, n);
break;
case ePixelComponentAlpha :
_clipProps.propSetString(kOfxImageEffectPropSupportedComponents, kOfxImageComponentAlpha, n);
break;
case ePixelComponentCustom :
break;
}
}
/** @brief set which components are supported, defaults to none set, this must be called at least once! */
void ClipDescriptor::addSupportedComponent(const std::string &comp)
{
int n = _clipProps.propGetDimension(kOfxImageEffectPropSupportedComponents);
_clipProps.propSetString(kOfxImageEffectPropSupportedComponents, comp, n);
}
/** @brief say whether we are going to do random temporal access on this clip, defaults to false */
void ClipDescriptor::setTemporalClipAccess(bool v)
{
_clipProps.propSetInt(kOfxImageEffectPropTemporalClipAccess, int(v));
}
/** @brief say whether if the clip is optional, defaults to false */
void ClipDescriptor::setOptional(bool v)
{
_clipProps.propSetInt(kOfxImageClipPropOptional, int(v));
}
/** @brief say whether this clip supports tiling, defaults to true */
void ClipDescriptor::setSupportsTiles(bool v)
{
_clipProps.propSetInt(kOfxImageEffectPropSupportsTiles, int(v));
}
/** @brief say whether this clip is a 'mask', so the host can know to replace with a roto or similar, defaults to false */
void ClipDescriptor::setIsMask(bool v)
{
_clipProps.propSetInt(kOfxImageClipPropIsMask, int(v));
}
////////////////////////////////////////////////////////////////////////////////
// image effect descriptor
/** @brief effect descriptor ctor */
ImageEffectDescriptor::ImageEffectDescriptor(OfxImageEffectHandle handle)
: _effectHandle(handle)
{
// fetch the property set handle of the effect
OfxPropertySetHandle props;
OfxStatus stat = OFX::Private::gEffectSuite->getPropertySet(handle, &props);
throwSuiteStatusException(stat);
_effectProps.propSetHandle(props);
OFX::Validation::validatePluginDescriptorProperties(props);
// fetch the param set handle and set it in our ParamSetDescriptor base
OfxParamSetHandle paramSetHandle;
stat = OFX::Private::gEffectSuite->getParamSet(handle, ¶mSetHandle);
throwSuiteStatusException(stat);
setParamSetHandle(paramSetHandle);
}
/** @brief dtor */
ImageEffectDescriptor::~ImageEffectDescriptor()
{
// delete any clip descriptors we may have constructed
std::map<std::string, ClipDescriptor *>::iterator iter;
for(iter = _definedClips.begin(); iter != _definedClips.end(); ++iter) {
if(iter->second) {
delete iter->second;
iter->second = NULL;
}
}
}
/** @brief, set the label properties in a plugin */
void ImageEffectDescriptor::setLabel(const std::string &label)
{
_effectProps.propSetString(kOfxPropLabel, label);
}
/** @brief, set the label properties in a plugin */
void ImageEffectDescriptor::setLabels(const std::string &label, const std::string &shortLabel, const std::string &longLabel)
{
setLabel(label);
_effectProps.propSetString(kOfxPropShortLabel, shortLabel, false);
_effectProps.propSetString(kOfxPropLongLabel, longLabel, false);
}
/** @brief, set the version properties in a plugin */
void ImageEffectDescriptor::setVersion(int major, int minor, int micro, int build, const std::string &versionLabel)
{
_effectProps.propSetInt(kOfxPropVersion, major, 0, false); // introduced in OFX 1.2
if (minor || micro || build) {
_effectProps.propSetInt(kOfxPropVersion, minor, 1, false); // introduced in OFX 1.2
if (micro || build) {
_effectProps.propSetInt(kOfxPropVersion, micro, 2, false); // introduced in OFX 1.2
if (build) {
_effectProps.propSetInt(kOfxPropVersion, build, 3, false); // introduced in OFX 1.2
}
}
}
if (!versionLabel.empty()) {
_effectProps.propSetString(kOfxPropVersionLabel, versionLabel, false);
}
}
/** @brief Set the plugin grouping */
void ImageEffectDescriptor::setPluginGrouping(const std::string &group)
{
_effectProps.propSetString(kOfxImageEffectPluginPropGrouping, group);
}
/** @brief Set the plugin description, defaults to "" */
void ImageEffectDescriptor::setPluginDescription(const std::string &description)
{
_effectProps.propSetString(kOfxPropPluginDescription, description, false); // introduced in OFX 1.2
}
/** @brief Add a context to those supported */
void ImageEffectDescriptor::addSupportedContext(ContextEnum v)
{
int n = _effectProps.propGetDimension(kOfxImageEffectPropSupportedContexts);
switch (v)
{
case eContextNone :
break;
case eContextGenerator :
_effectProps.propSetString(kOfxImageEffectPropSupportedContexts, kOfxImageEffectContextGenerator, n);
break;
case eContextFilter :
_effectProps.propSetString(kOfxImageEffectPropSupportedContexts, kOfxImageEffectContextFilter, n);
break;
case eContextTransition :
_effectProps.propSetString(kOfxImageEffectPropSupportedContexts, kOfxImageEffectContextTransition, n);
break;
case eContextPaint :
_effectProps.propSetString(kOfxImageEffectPropSupportedContexts, kOfxImageEffectContextPaint, n);
break;
case eContextGeneral :
_effectProps.propSetString(kOfxImageEffectPropSupportedContexts, kOfxImageEffectContextGeneral, n);
break;
case eContextRetimer :
_effectProps.propSetString(kOfxImageEffectPropSupportedContexts, kOfxImageEffectContextRetimer, n);
break;
}
}
void ImageEffectDescriptor::setOverlayInteractDescriptor(EffectOverlayDescriptor* desc)
{
_overlayDescriptor.reset(desc);
if(OFX::gHostDescription.supportsOverlays && desc->getMainEntry())
_effectProps.propSetPointer(kOfxImageEffectPluginPropOverlayInteractV1, (void*)desc->getMainEntry());
}
/** @brief Add a pixel depth to those supported */
void ImageEffectDescriptor::addSupportedBitDepth(BitDepthEnum v)
{
int n = _effectProps.propGetDimension(kOfxImageEffectPropSupportedPixelDepths);
switch(v)
{
case eBitDepthNone :
_effectProps.propSetString(kOfxImageEffectPropSupportedPixelDepths, kOfxBitDepthNone , n);
break;
case eBitDepthUByte :
_effectProps.propSetString(kOfxImageEffectPropSupportedPixelDepths, kOfxBitDepthByte , n);
break;
case eBitDepthUShort :
_effectProps.propSetString(kOfxImageEffectPropSupportedPixelDepths, kOfxBitDepthShort , n);
break;
case eBitDepthHalf :
_effectProps.propSetString(kOfxImageEffectPropSupportedPixelDepths, kOfxBitDepthHalf , n);
break;
case eBitDepthFloat :
_effectProps.propSetString(kOfxImageEffectPropSupportedPixelDepths, kOfxBitDepthFloat , n);
break;
case eBitDepthCustom :
break;
}
}
#ifdef OFX_SUPPORTS_OPENGLRENDER
/** @brief Add a pixel depth to those supported */
void ImageEffectDescriptor::addSupportedOpenGLBitDepth(BitDepthEnum v)
{
int n = _effectProps.propGetDimension(kOfxOpenGLPropPixelDepth);
switch(v)
{
case eBitDepthNone :
_effectProps.propSetString(kOfxOpenGLPropPixelDepth, kOfxBitDepthNone , n);
break;
case eBitDepthUByte :
_effectProps.propSetString(kOfxOpenGLPropPixelDepth, kOfxBitDepthByte , n);
break;
case eBitDepthUShort :
_effectProps.propSetString(kOfxOpenGLPropPixelDepth, kOfxBitDepthShort , n);
break;
case eBitDepthHalf :
_effectProps.propSetString(kOfxOpenGLPropPixelDepth, kOfxBitDepthHalf , n);
break;
case eBitDepthFloat :
_effectProps.propSetString(kOfxOpenGLPropPixelDepth, kOfxBitDepthFloat , n);
break;
default:
break;
}
}
#endif
/** @brief Is the plugin single instance only ? */
void ImageEffectDescriptor::setSingleInstance(bool v)
{
_effectProps.propSetInt(kOfxImageEffectPluginPropSingleInstance, int(v));
}
/** @brief Does the plugin expect the host to perform per frame SMP threading */
void ImageEffectDescriptor::setHostFrameThreading(bool v)
{
_effectProps.propSetInt(kOfxImageEffectPluginPropHostFrameThreading, int(v));
}
/** @brief Does the plugin support multi resolution images */
void ImageEffectDescriptor::setSupportsMultiResolution(bool v)
{
_effectProps.propSetInt(kOfxImageEffectPropSupportsMultiResolution, int(v));
}
/** @brief Does the plugin support image tiling */
void ImageEffectDescriptor::setSupportsTiles(bool v)
{
_effectProps.propSetInt(kOfxImageEffectPropSupportsTiles, int(v));
}
/** @brief Does the plugin perform temporal clip access */
void ImageEffectDescriptor::setTemporalClipAccess(bool v)
{
_effectProps.propSetInt(kOfxImageEffectPropTemporalClipAccess, int(v));
}
/** @brief Does the plugin want to have render called twice per frame in all circumanstances for fielded images ? */
void ImageEffectDescriptor::setRenderTwiceAlways(bool v)
{
_effectProps.propSetInt(kOfxImageEffectPluginPropFieldRenderTwiceAlways, int(v));
}
/** @brief Does the plugin support inputs and output clips of differing depths */
void ImageEffectDescriptor::setSupportsMultipleClipDepths(bool v)
{
_effectProps.propSetInt(kOfxImageEffectPropSupportsMultipleClipDepths, int(v));
}
/** @brief Does the plugin support inputs and output clips of pixel aspect ratios */
void ImageEffectDescriptor::setSupportsMultipleClipPARs(bool v)
{
_effectProps.propSetInt(kOfxImageEffectPropSupportsMultipleClipPARs, int(v));
}
/** @brief What kind of thread safety does the plugin have */
void ImageEffectDescriptor::setRenderThreadSafety(RenderSafetyEnum v)
{
switch(v)
{
case eRenderUnsafe :
_effectProps.propSetString(kOfxImageEffectPluginRenderThreadSafety, kOfxImageEffectRenderUnsafe);
break;
case eRenderInstanceSafe :
_effectProps.propSetString(kOfxImageEffectPluginRenderThreadSafety, kOfxImageEffectRenderInstanceSafe);
break;
case eRenderFullySafe :
_effectProps.propSetString(kOfxImageEffectPluginRenderThreadSafety, kOfxImageEffectRenderFullySafe);
break;
}
}
#ifdef OFX_SUPPORTS_OPENGLRENDER
/** @brief Does the plugin support OpenGL accelerated rendering (but is also capable of CPU rendering) ? */
void ImageEffectDescriptor::setSupportsOpenGLRender(bool v) {
if (gHostDescription.supportsOpenGLRender) {
_effectProps.propSetString(kOfxImageEffectPropOpenGLRenderSupported, (v ? "true" : "false"));
}
}
/** @brief Does the plugin require OpenGL accelerated rendering ? */
void ImageEffectDescriptor::setNeedsOpenGLRender(bool v) {
if (gHostDescription.supportsOpenGLRender) {
_effectProps.propSetString(kOfxImageEffectPropOpenGLRenderSupported, (v ? "needed" : "false"));
}
}
void ImageEffectDescriptor::addOpenGLBitDepth(BitDepthEnum v) {
int n = _effectProps.propGetDimension(kOfxImageEffectPropSupportedPixelDepths);
std::string value = mapBitDepthEnumToStr(v);
if (!value.empty()) {
_effectProps.propSetString(kOfxOpenGLPropPixelDepth, value, n);
}
}
#endif
/** @brief If the slave param changes the clip preferences need to be re-evaluated */
void ImageEffectDescriptor::addClipPreferencesSlaveParam(ParamDescriptor &p)
{
int n = _effectProps.propGetDimension(kOfxImageEffectPropClipPreferencesSlaveParam);
_effectProps.propSetString(kOfxImageEffectPropClipPreferencesSlaveParam, p.getName(), n);
}
/** @brief Create a clip, only callable from describe in context */
ClipDescriptor *ImageEffectDescriptor::defineClip(const std::string &name)
{
// do we have the clip already
std::map<std::string, ClipDescriptor *>::const_iterator search;
search = _definedClips.find(name);
if(search != _definedClips.end())
return search->second;
// no, so make it
OfxPropertySetHandle propSet;
OfxStatus stat = OFX::Private::gEffectSuite->clipDefine(_effectHandle, name.c_str(), &propSet);
(void)stat;
ClipDescriptor *clip = new ClipDescriptor(name, propSet);
_definedClips[name] = clip;
_clipComponentsPropNames[name] = std::string("OfxImageClipPropComponents_") + name;
_clipDepthPropNames[name] = std::string("OfxImageClipPropDepth_") + name;
_clipPARPropNames[name] = std::string("OfxImageClipPropPAR_") + name;
_clipROIPropNames[name] = std::string("OfxImageClipPropRoI_") + name;
_clipFrameRangePropNames[name] = std::string("OfxImageClipPropFrameRange_") + name;
return clip;
}
////////////////////////////////////////////////////////////////////////////////
// wraps up an image
ImageBase::ImageBase(OfxPropertySetHandle props)
: _imageProps(props)
{
OFX::Validation::validateImageBaseProperties(props);
// and fetch all the properties
_rowBytes = _imageProps.propGetInt(kOfxImagePropRowBytes);
_pixelAspectRatio = _imageProps.propGetDouble(kOfxImagePropPixelAspectRatio);;
std::string str = _imageProps.propGetString(kOfxImageEffectPropComponents);
_pixelComponents = mapStrToPixelComponentEnum(str);
switch (_pixelComponents) {
case ePixelComponentAlpha:
_pixelComponentCount = 1;
break;
case ePixelComponentNone:
_pixelComponentCount = 0;
break;
case ePixelComponentRGB:
_pixelComponentCount = 3;
break;
case ePixelComponentRGBA:
_pixelComponentCount = 4;
break;
case ePixelComponentCustom:
default:
_pixelComponentCount = 0;
break;
}
str = _imageProps.propGetString(kOfxImageEffectPropPixelDepth);
_pixelDepth = mapStrToBitDepthEnum(str);
// compute bytes per pixel
_pixelBytes = _pixelComponentCount;
switch(_pixelDepth)
{
case eBitDepthNone : _pixelBytes *= 0; break;
case eBitDepthUByte : _pixelBytes *= 1; break;
case eBitDepthUShort : _pixelBytes *= 2; break;
case eBitDepthHalf : _pixelBytes *= 2; break;
case eBitDepthFloat : _pixelBytes *= 4; break;
case eBitDepthCustom : _pixelBytes *= 0; break;
}
str = _imageProps.propGetString(kOfxImageEffectPropPreMultiplication);
_preMultiplication = mapStrToPreMultiplicationEnum(str);
_regionOfDefinition.x1 = _imageProps.propGetInt(kOfxImagePropRegionOfDefinition, 0);
_regionOfDefinition.y1 = _imageProps.propGetInt(kOfxImagePropRegionOfDefinition, 1);
_regionOfDefinition.x2 = _imageProps.propGetInt(kOfxImagePropRegionOfDefinition, 2);
_regionOfDefinition.y2 = _imageProps.propGetInt(kOfxImagePropRegionOfDefinition, 3);
_bounds.x1 = _imageProps.propGetInt(kOfxImagePropBounds, 0);
_bounds.y1 = _imageProps.propGetInt(kOfxImagePropBounds, 1);
_bounds.x2 = _imageProps.propGetInt(kOfxImagePropBounds, 2);
_bounds.y2 = _imageProps.propGetInt(kOfxImagePropBounds, 3);
str = _imageProps.propGetString(kOfxImagePropField);
if(str == kOfxImageFieldNone) {
_field = eFieldNone;
}
else if(str == kOfxImageFieldBoth) {
_field = eFieldBoth;
}
else if(str == kOfxImageFieldLower) {
_field = eFieldLower;
}
else if(str == kOfxImageFieldUpper) {
_field = eFieldLower;
}
else {
OFX::Log::error(true, "Unknown field state '%s' reported on an image", str.c_str());
_field = eFieldNone;
}
_uniqueID = _imageProps.propGetString(kOfxImagePropUniqueIdentifier);
_renderScale.x = _imageProps.propGetDouble(kOfxImageEffectPropRenderScale, 0);
_renderScale.y = _imageProps.propGetDouble(kOfxImageEffectPropRenderScale, 1);
}
ImageBase::~ImageBase()
{
}
////////////////////////////////////////////////////////////////////////////////
// wraps up an image
Image::Image(OfxPropertySetHandle props)
: ImageBase(props)
{
OFX::Validation::validateImageProperties(props);
// and fetch all the properties
// should throw if it is not an image
_pixelData = _imageProps.propGetPointer(kOfxImagePropData);
}
Image::~Image()
{
OFX::Private::gEffectSuite->clipReleaseImage(_imageProps.propSetHandle());
}
#ifdef OFX_SUPPORTS_OPENGLRENDER
////////////////////////////////////////////////////////////////////////////////
// wraps up an OpenGL texture
Texture::Texture(OfxPropertySetHandle props)
: ImageBase(props)
{
OFX::Validation::validateTextureProperties(props);
// should throw if it is not a texture
_index = _imageProps.propGetInt(kOfxImageEffectPropOpenGLTextureIndex);
_target = _imageProps.propGetInt(kOfxImageEffectPropOpenGLTextureTarget);
}
Texture::~Texture()
{
OfxStatus stat = OFX::Private::gOpenGLRenderSuite->clipFreeTexture(_imageProps.propSetHandle());
if (stat != kOfxStatOK) {
throwSuiteStatusException(stat);
}
}
#endif
/** @brief return a pixel pointer
No attempt made to be uber efficient here.
*/
void *Image::getPixelAddress(int x, int y)
{
// are we in the image bounds
if(x < _bounds.x1 || x >= _bounds.x2 || y < _bounds.y1 || y >= _bounds.y2 || _pixelBytes == 0)
return 0;
char *pix = ((char *) _pixelData) + (size_t)(y - _bounds.y1) * _rowBytes;
pix += (x - _bounds.x1) * _pixelBytes;
return (void *) pix;
}
const void *Image::getPixelAddress(int x, int y) const
{
// are we in the image bounds
if(x < _bounds.x1 || x >= _bounds.x2 || y < _bounds.y1 || y >= _bounds.y2 || _pixelBytes == 0)
return 0;
const char *pix = ((const char *) _pixelData) + (size_t)(y - _bounds.y1) * _rowBytes;
pix += (x - _bounds.x1) * _pixelBytes;
return (const void *) pix;
}
////////////////////////////////////////////////////////////////////////////////
// clip instance
/** @brief hidden constructor */
Clip::Clip(ImageEffect *effect, const std::string &name, OfxImageClipHandle handle, OfxPropertySetHandle props)
: _clipName(name)
, _clipProps(props)
, _clipHandle(handle)
, _effect(effect)
{
OFX::Validation::validateClipInstanceProperties(_clipProps);
}
/** @brief fetch the label */
void Clip::getLabel(std::string &label) const
{
label = _clipProps.propGetString(kOfxPropLabel);
}
/** @brief fetch the labels */
void Clip::getLabels(std::string &label, std::string &shortLabel, std::string &longLabel) const
{
getLabel(label);
shortLabel = _clipProps.propGetString(kOfxPropShortLabel, false);
longLabel = _clipProps.propGetString(kOfxPropLongLabel, false);
}
/** @brief get the pixel depth */
BitDepthEnum Clip::getPixelDepth(void) const
{
std::string str = _clipProps.propGetString(kOfxImageEffectPropPixelDepth);
BitDepthEnum e;
try {
e = mapStrToBitDepthEnum(str);
if(e == eBitDepthNone && isConnected()) {
OFX::Log::error(true, "Clip %s is connected and has no pixel depth.", _clipName.c_str());
}
}
// gone wrong ?
catch(std::invalid_argument&) {
OFX::Log::error(true, "Unknown pixel depth property '%s' reported on clip '%s'", str.c_str(), _clipName.c_str());
e = eBitDepthNone;
}
return e;
}
/** @brief get the components in the image */
PixelComponentEnum Clip::getPixelComponents(void) const
{
std::string str = _clipProps.propGetString(kOfxImageEffectPropComponents);
PixelComponentEnum e;
try {
e = mapStrToPixelComponentEnum(str);
if(e == ePixelComponentNone && isConnected()) {
OFX::Log::error(true, "Clip %s is connected and has no pixel component type!", _clipName.c_str());
}
}
// gone wrong ?
catch(std::invalid_argument&) {
OFX::Log::error(true, "Unknown pixel component type '%s' reported on clip '%s'", str.c_str(), _clipName.c_str());
e = ePixelComponentNone;
}
return e;
}
/** @brief get the number of components in the image */
int Clip::getPixelComponentCount(void) const
{
std::string str = _clipProps.propGetString(kOfxImageEffectPropComponents);
PixelComponentEnum e;
try {
e = mapStrToPixelComponentEnum(str);
if(e == ePixelComponentNone && isConnected()) {
OFX::Log::error(true, "Clip %s is connected and has no pixel component type!", _clipName.c_str());
}
}
// gone wrong ?
catch(std::invalid_argument&) {
OFX::Log::error(true, "Unknown pixel component type '%s' reported on clip '%s'", str.c_str(), _clipName.c_str());
e = ePixelComponentNone;
}
switch (e) {
case ePixelComponentAlpha:
return 1;
case ePixelComponentNone:
return 0;
case ePixelComponentRGB:
return 3;
case ePixelComponentRGBA:
return 4;
case ePixelComponentCustom:
default:
return 0;
}
}
/** @brief what is the actual pixel depth of the clip */
BitDepthEnum Clip::getUnmappedPixelDepth(void) const
{
std::string str = _clipProps.propGetString(kOfxImageClipPropUnmappedPixelDepth);
BitDepthEnum e;
try {
e = mapStrToBitDepthEnum(str);
if(e == eBitDepthNone && !isConnected()) {
OFX::Log::error(true, "Clip %s is connected and has no unmapped pixel depth.", _clipName.c_str());
}
}
// gone wrong ?
catch(std::invalid_argument&) {
OFX::Log::error(true, "Unknown unmapped pixel depth property '%s' reported on clip '%s'", str.c_str(), _clipName.c_str());
e = eBitDepthNone;
}
return e;
}
/** @brief what is the component type of the clip */
PixelComponentEnum Clip::getUnmappedPixelComponents(void) const
{
std::string str = _clipProps.propGetString(kOfxImageClipPropUnmappedComponents);