Skip to content

Commit 59153b3

Browse files
committed
Fix prop defs & add ofxClip.h with more clip/image accessors
Signed-off-by: Gary Oberbrunner <[email protected]>
1 parent 1698815 commit 59153b3

File tree

5 files changed

+139
-10
lines changed

5 files changed

+139
-10
lines changed

include/ofx-props.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ propertySets:
3434
- OfxImageEffectPropSupportedComponents
3535
- OfxImageEffectPropSupportedContexts
3636
- OfxImageEffectPropMultipleClipDepths
37+
- OfxImageEffectPropOpenCLSupported
3738
- OfxImageEffectPropSupportsMultipleClipPARs
3839
- OfxImageEffectPropSetableFrameRate
3940
- OfxImageEffectPropSetableFielding
@@ -71,6 +72,7 @@ propertySets:
7172
- OfxImageEffectPluginRenderThreadSafety
7273
- OfxImageEffectPluginPropHostFrameThreading
7374
- OfxImageEffectPluginPropOverlayInteractV1
75+
- OfxImageEffectPropOpenCLSupported
7476
- OfxImageEffectPropSupportsMultiResolution
7577
- OfxImageEffectPropSupportsTiles
7678
- OfxImageEffectPropTemporalClipAccess
@@ -947,7 +949,7 @@ properties:
947949
dimension: 1
948950
introduced: "1.5"
949951
OfxImageEffectPropOpenCLImage:
950-
type: int
952+
type: pointer
951953
dimension: 1
952954
introduced: "1.5"
953955
OfxImageEffectPropOpenCLSupported:
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
// Copyright OpenFX and contributors to the OpenFX project.
2+
// SPDX-License-Identifier: BSD-3-Clause
3+
4+
#pragma once
5+
6+
#include <ofxCore.h>
7+
#include <ofxImageEffect.h>
8+
9+
#include <memory> // For std::unique_ptr
10+
11+
#include "openfx/ofxExceptions.h"
12+
#include "openfx/ofxImage.h"
13+
#include "openfx/ofxPropsAccess.h"
14+
15+
namespace openfx {
16+
17+
class Clip {
18+
private:
19+
const OfxImageEffectSuiteV1* mEffectSuite;
20+
const OfxPropertySuiteV1* mPropertySuite;
21+
OfxImageClipHandle mClip{};
22+
OfxPropertySetHandle mClipPropSet{}; // The clip property set handle
23+
std::unique_ptr<PropertyAccessor> mClipProps; // Accessor: use a pointer to defer construction
24+
25+
public:
26+
// Construct a clip given the raw clip handle.
27+
// Gets the property set and sets up accessor for it.
28+
Clip(const OfxImageEffectSuiteV1* effect_suite, const OfxPropertySuiteV1* prop_suite,
29+
OfxImageClipHandle clip)
30+
: mClip(clip), mEffectSuite(effect_suite), mPropertySuite(prop_suite), mClipProps(nullptr) {
31+
if (clip != nullptr) {
32+
OfxStatus status = mEffectSuite->clipGetPropertySet(clip, &mClipPropSet);
33+
if (status != kOfxStatOK)
34+
throw ClipNotFoundException(status);
35+
if (mClipPropSet) {
36+
mClipProps = std::make_unique<PropertyAccessor>(mClipPropSet, prop_suite);
37+
}
38+
}
39+
}
40+
41+
// Construct a clip given effect and clip name.
42+
// Gets the clip with its property set, and sets up accessor for it.
43+
Clip(const OfxImageEffectSuiteV1* effect_suite, const OfxPropertySuiteV1* prop_suite,
44+
OfxImageEffectHandle effect, std::string_view clip_name)
45+
: mEffectSuite(effect_suite), mPropertySuite(prop_suite), mClipProps(nullptr) {
46+
OfxStatus status = effect_suite->clipGetHandle(effect, clip_name.data(), &mClip, &mClipPropSet);
47+
if (status != kOfxStatOK || !mClip || !mClipPropSet)
48+
throw ClipNotFoundException(status);
49+
mClipProps = std::make_unique<PropertyAccessor>(mClipPropSet, prop_suite);
50+
}
51+
52+
// Default constructor: empty clip
53+
Clip() : mEffectSuite(nullptr), mClipProps(nullptr) {}
54+
55+
// Destructor releases the resource
56+
~Clip() {
57+
if (mClipPropSet) {
58+
mClipPropSet = nullptr;
59+
}
60+
}
61+
62+
// Disable copying
63+
Clip(const Clip&) = delete;
64+
Clip& operator=(const Clip&) = delete;
65+
66+
// Enable moving
67+
Clip(Clip&& other) noexcept
68+
: mEffectSuite(other.mEffectSuite),
69+
mPropertySuite(other.mPropertySuite),
70+
mClip(other.mClip),
71+
mClipPropSet(other.mClipPropSet),
72+
mClipProps(std::move(other.mClipProps)) {
73+
other.mClipPropSet = nullptr;
74+
}
75+
76+
Clip& operator=(Clip&& other) noexcept {
77+
if (this != &other) {
78+
// Release any existing resource
79+
80+
// Acquire the other's resource
81+
mEffectSuite = other.mEffectSuite;
82+
mPropertySuite = other.mPropertySuite;
83+
mClip = other.mClip;
84+
mClipPropSet = other.mClipPropSet;
85+
mClipProps = std::move(other.mClipProps);
86+
other.mClipPropSet = nullptr;
87+
}
88+
return *this;
89+
}
90+
91+
// Get an image from the clip at this time
92+
openfx::Image get_image(OfxTime time, const OfxRectD* rect = nullptr) {
93+
return openfx::Image(mEffectSuite, mPropertySuite, mClip, time, rect);
94+
}
95+
96+
// get the clip handle
97+
OfxImageClipHandle clip() const { return mClip; }
98+
99+
// get the clip's prop set
100+
OfxPropertySetHandle get_propset() const { return mClipPropSet; }
101+
102+
// Accessor for PropertyAccessor
103+
PropertyAccessor* props() { return mClipProps.get(); }
104+
const PropertyAccessor* props() const { return mClipProps.get(); }
105+
106+
// Implicit conversions to the handle types
107+
explicit operator OfxPropertySetHandle() const { return mClipPropSet; }
108+
explicit operator OfxImageClipHandle() const { return mClip; }
109+
110+
bool empty() const { return mClip == nullptr; }
111+
};
112+
113+
} // namespace openfx

openfx-cpp/include/openfx/ofxImage.h

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55

66
#include <ofxCore.h>
77
#include <ofxImageEffect.h>
8-
#include "ofxPropsAccess.h"
98

109
#include <memory> // For std::unique_ptr
1110

12-
#include "ofxExceptions.h"
11+
#include "openfx/ofxExceptions.h"
12+
#include "openfx/ofxMisc.h"
13+
#include "openfx/ofxPropsAccess.h"
1314

1415
namespace openfx {
1516

@@ -23,7 +24,7 @@ class Image {
2324
public:
2425
// Constructor acquires the resource
2526
Image(const OfxImageEffectSuiteV1* effect_suite, const OfxPropertySuiteV1* prop_suite,
26-
OfxImageClipHandle clip, OfxTime time, OfxRectD* rect = nullptr)
27+
OfxImageClipHandle clip, OfxTime time, const OfxRectD* rect = nullptr)
2728
: mEffectSuite(effect_suite), mImgProps(nullptr) {
2829
if (clip != nullptr) {
2930
OfxStatus status = mEffectSuite->clipGetImage(clip, time, rect, &mImg);
@@ -72,14 +73,25 @@ class Image {
7273
return *this;
7374
}
7475

75-
// Accessor to get the underlying handle
76-
OfxPropertySetHandle get() const { return mImg; }
76+
// Get the image's data pointer
77+
void* data() { return props()->get<openfx::PropId::OfxImagePropData>(); }
78+
79+
// Get the image's bounds
80+
OfxRectI bounds() {
81+
return openfx::toOfxRectI(props()->getAll<openfx::PropId::OfxImagePropBounds>());
82+
}
7783

78-
// Accessor for PropertyAccessor
84+
// Get the image's rowbytes
85+
int rowbytes() { return props()->get<openfx::PropId::OfxImagePropRowBytes>(); }
86+
87+
// Get the PropertyAccessor
7988
PropertyAccessor* props() { return mImgProps.get(); }
8089
const PropertyAccessor* props() const { return mImgProps.get(); }
8190

82-
// Implicit conversion to the handle type
91+
// Get the underlying handle
92+
OfxPropertySetHandle get() const { return mImg; }
93+
94+
// Implicit conversion to base handle type
8395
explicit operator OfxPropertySetHandle() const { return mImg; }
8496

8597
bool empty() const { return mImg == nullptr; }

openfx-cpp/include/openfx/ofxPropsBySet.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ static inline const std::map<const char *, std::vector<Prop>> prop_sets {
8888
{ "OfxImageEffectPluginRenderThreadSafety", prop_defs[PropId::OfxImageEffectPluginRenderThreadSafety], false, true, false },
8989
{ "OfxImageEffectPluginPropHostFrameThreading", prop_defs[PropId::OfxImageEffectPluginPropHostFrameThreading], false, true, false },
9090
{ "OfxImageEffectPluginPropOverlayInteractV1", prop_defs[PropId::OfxImageEffectPluginPropOverlayInteractV1], false, true, false },
91+
{ "OfxImageEffectPropOpenCLSupported", prop_defs[PropId::OfxImageEffectPropOpenCLSupported], false, true, false },
9192
{ "OfxImageEffectPropSupportsMultiResolution", prop_defs[PropId::OfxImageEffectPropSupportsMultiResolution], false, true, false },
9293
{ "OfxImageEffectPropSupportsTiles", prop_defs[PropId::OfxImageEffectPropSupportsTiles], false, true, false },
9394
{ "OfxImageEffectPropTemporalClipAccess", prop_defs[PropId::OfxImageEffectPropTemporalClipAccess], false, true, false },
@@ -155,6 +156,7 @@ static inline const std::map<const char *, std::vector<Prop>> prop_sets {
155156
{ "OfxImageEffectPropSupportedComponents", prop_defs[PropId::OfxImageEffectPropSupportedComponents], true, false, false },
156157
{ "OfxImageEffectPropSupportedContexts", prop_defs[PropId::OfxImageEffectPropSupportedContexts], true, false, false },
157158
{ "OfxImageEffectPropMultipleClipDepths", prop_defs[PropId::OfxImageEffectPropMultipleClipDepths], true, false, false },
159+
{ "OfxImageEffectPropOpenCLSupported", prop_defs[PropId::OfxImageEffectPropOpenCLSupported], true, false, false },
158160
{ "OfxImageEffectPropSupportsMultipleClipPARs", prop_defs[PropId::OfxImageEffectPropSupportsMultipleClipPARs], true, false, false },
159161
{ "OfxImageEffectPropSetableFrameRate", prop_defs[PropId::OfxImageEffectPropSetableFrameRate], true, false, false },
160162
{ "OfxImageEffectPropSetableFielding", prop_defs[PropId::OfxImageEffectPropSetableFielding], true, false, false },

openfx-cpp/include/openfx/ofxPropsMetadata.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ static inline constexpr PropDefsArray<PropDef> prop_defs = {
404404
{ "OfxImageEffectPropOpenCLEnabled", PropId::OfxImageEffectPropOpenCLEnabled,
405405
{PropType::Bool}, 1, 1, nullptr, 0},
406406
{ "OfxImageEffectPropOpenCLImage", PropId::OfxImageEffectPropOpenCLImage,
407-
{PropType::Int}, 1, 1, nullptr, 0},
407+
{PropType::Pointer}, 1, 1, nullptr, 0},
408408
{ "OfxImageEffectPropOpenCLRenderSupported", PropId::OfxImageEffectPropOpenCLRenderSupported,
409409
{PropType::Enum}, 1, 1, prop_enum_values::OfxImageEffectPropOpenCLRenderSupported.data(), prop_enum_values::OfxImageEffectPropOpenCLRenderSupported.size()},
410410
{ "OfxImageEffectPropOpenCLSupported", PropId::OfxImageEffectPropOpenCLSupported,
@@ -732,7 +732,7 @@ DEFINE_PROP_TRAITS(OfxImageEffectPropOCIODisplay, const char *, false);
732732
DEFINE_PROP_TRAITS(OfxImageEffectPropOCIOView, const char *, false);
733733
DEFINE_PROP_TRAITS(OfxImageEffectPropOpenCLCommandQueue, void *, false);
734734
DEFINE_PROP_TRAITS(OfxImageEffectPropOpenCLEnabled, bool, false);
735-
DEFINE_PROP_TRAITS(OfxImageEffectPropOpenCLImage, int, false);
735+
DEFINE_PROP_TRAITS(OfxImageEffectPropOpenCLImage, void *, false);
736736
DEFINE_PROP_TRAITS(OfxImageEffectPropOpenCLRenderSupported, const char *, false);
737737
DEFINE_PROP_TRAITS(OfxImageEffectPropOpenCLSupported, const char *, false);
738738
DEFINE_PROP_TRAITS(OfxImageEffectPropOpenGLEnabled, bool, false);

0 commit comments

Comments
 (0)