change: Switch to offical OpenFX Support. Still can't compile.

This commit is contained in:
Mike Solar
2025-09-03 21:14:56 +08:00
parent 7ff76427f9
commit b649b5e1bd
198 changed files with 57444 additions and 980 deletions
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleExecutable</key>
<string>multibundle.ofx</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>0.0.1d1</string>
<key>CSResourcesFileMapped</key>
<true/>
</dict>
</plist>
+20
View File
@@ -0,0 +1,20 @@
#include <stdio.h>
#include "ofxsImageEffect.h"
#include "multibundle1.h"
#include "multibundle2.h"
namespace OFX
{
namespace Plugin
{
void getPluginIDs(OFX::PluginFactoryArray &ids)
{
static DotExamplePluginFactory p1;
ids.push_back(&p1);
static GammaExamplePluginFactory p2;
ids.push_back(&p2);
}
}
}
+444
View File
@@ -0,0 +1,444 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="8.00"
Name="MultiBundle"
ProjectGUID="{F14ECC69-3767-44B1-A28C-32FB09F50C7E}"
RootNamespace="MultiBundle"
>
<Platforms>
<Platform
Name="Win32"
/>
<Platform
Name="x64"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory=".\$(ConfigurationName)-$(PlatformName)"
IntermediateDirectory=".\$(ConfigurationName)-$(PlatformName)"
ConfigurationType="2"
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC60.vsprops"
UseOfMFC="0"
ATLMinimizesCRunTimeLibraryUsage="false"
CharacterSet="2"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
PreprocessorDefinitions="_DEBUG"
MkTypLibCompatible="true"
SuppressStartupBanner="true"
TargetEnvironment="1"
TypeLibraryName=".\Debug/$(InputName).tlb"
HeaderFileName=""
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="../../include,../../../include"
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;PROPTESTER_EXPORTS"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
PrecompiledHeaderFile=".\$(ConfigurationName)-$(PlatformName)/$(InputName).pch"
AssemblerListingLocation="$(IntDir)/"
ObjectFile="$(IntDir)/"
ProgramDataBaseFileName="$(IntDir)/"
WarningLevel="3"
SuppressStartupBanner="true"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
PreprocessorDefinitions="_DEBUG"
Culture="2057"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="odbc32.lib odbccp32.lib opengl32.lib"
OutputFile="../$(OutDir)/$(InputName).ofx.bundle/Contents/Win32/$(InputName).ofx"
LinkIncremental="1"
SuppressStartupBanner="true"
GenerateDebugInformation="true"
ProgramDatabaseFile="$(IntDir)/$(InputName).pdb"
ImportLibrary="$(IntDir)/$(InputName).lib"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
SuppressStartupBanner="true"
OutputFile=".\Debug/$(InputName).bsc"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory=".\$(ConfigurationName)-$(PlatformName)"
IntermediateDirectory=".\$(ConfigurationName)-$(PlatformName)"
ConfigurationType="2"
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC60.vsprops"
UseOfMFC="0"
ATLMinimizesCRunTimeLibraryUsage="false"
CharacterSet="2"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
PreprocessorDefinitions="NDEBUG"
MkTypLibCompatible="true"
SuppressStartupBanner="true"
TargetEnvironment="1"
TypeLibraryName=".\Release/$(InputName).tlb"
HeaderFileName=""
/>
<Tool
Name="VCCLCompilerTool"
Optimization="2"
InlineFunctionExpansion="1"
AdditionalIncludeDirectories="../../include,../../../include"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;PROPTESTER_EXPORTS"
StringPooling="true"
RuntimeLibrary="2"
EnableFunctionLevelLinking="true"
PrecompiledHeaderFile=".\$(ConfigurationName)-$(PlatformName)/$(InputName).pch"
AssemblerListingLocation="$(IntDir)/"
ObjectFile="$(IntDir)/"
ProgramDataBaseFileName="$(IntDir)/"
WarningLevel="3"
SuppressStartupBanner="true"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
PreprocessorDefinitions="NDEBUG"
Culture="2057"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="odbc32.lib odbccp32.lib opengl32.lib"
OutputFile="../$(OutDir)/$(InputName).ofx.bundle/Contents/Win32/$(InputName).ofx"
LinkIncremental="1"
SuppressStartupBanner="true"
ProgramDatabaseFile="$(IntDir)/$(InputName).pdb"
ImportLibrary="$(IntDir)/$(InputName).lib"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
SuppressStartupBanner="true"
OutputFile=".\Release/$(InputName).bsc"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Debug|x64"
OutputDirectory=".\$(ConfigurationName)-$(PlatformName)"
IntermediateDirectory=".\$(ConfigurationName)-$(PlatformName)"
ConfigurationType="2"
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC60.vsprops"
UseOfMFC="0"
ATLMinimizesCRunTimeLibraryUsage="false"
CharacterSet="2"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
PreprocessorDefinitions="_DEBUG"
MkTypLibCompatible="true"
SuppressStartupBanner="true"
TargetEnvironment="3"
TypeLibraryName=".\Debug/$(InputName).tlb"
HeaderFileName=""
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="../../include,../../../include"
PreprocessorDefinitions="WIN64;_DEBUG;_WINDOWS;_USRDLL;"
MinimalRebuild="false"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
PrecompiledHeaderFile=".\$(ConfigurationName)-$(PlatformName)/$(InputName).pch"
AssemblerListingLocation="$(IntDir)/"
ObjectFile="$(IntDir)/"
ProgramDataBaseFileName="$(IntDir)/"
WarningLevel="3"
SuppressStartupBanner="true"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
PreprocessorDefinitions="_DEBUG"
Culture="2057"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="odbc32.lib odbccp32.lib opengl32.lib"
OutputFile="../$(OutDir)/$(InputName).ofx.bundle/Contents/Win64/$(InputName).ofx"
LinkIncremental="1"
SuppressStartupBanner="true"
GenerateDebugInformation="true"
ProgramDatabaseFile="$(OutDir)/$(InputName).pdb"
ImportLibrary="$(OutDir)/$(InputName).lib"
TargetMachine="17"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
SuppressStartupBanner="true"
OutputFile=".\Debug/$(InputName).bsc"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release|x64"
OutputDirectory=".\$(ConfigurationName)-$(PlatformName)"
IntermediateDirectory=".\$(ConfigurationName)-$(PlatformName)"
ConfigurationType="2"
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC60.vsprops"
UseOfMFC="0"
ATLMinimizesCRunTimeLibraryUsage="false"
CharacterSet="2"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
PreprocessorDefinitions="NDEBUG"
MkTypLibCompatible="true"
SuppressStartupBanner="true"
TargetEnvironment="3"
TypeLibraryName=".\Release/$(InputName).tlb"
HeaderFileName=""
/>
<Tool
Name="VCCLCompilerTool"
Optimization="2"
InlineFunctionExpansion="1"
AdditionalIncludeDirectories="../../include,../../../include"
PreprocessorDefinitions="WIN64;NDEBUG;_WINDOWS;_USRDLL;"
StringPooling="false"
RuntimeLibrary="2"
EnableFunctionLevelLinking="true"
PrecompiledHeaderFile=".\$(ConfigurationName)-$(PlatformName)/$(InputName).pch"
AssemblerListingLocation="$(IntDir)/"
ObjectFile="$(IntDir)/"
ProgramDataBaseFileName="$(IntDir)/"
WarningLevel="3"
SuppressStartupBanner="true"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
PreprocessorDefinitions="NDEBUG"
Culture="2057"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="odbc32.lib odbccp32.lib opengl32.lib"
OutputFile="../$(OutDir)/$(InputName).ofx.bundle/Contents/Win64/$(InputName).ofx"
LinkIncremental="1"
SuppressStartupBanner="true"
ProgramDatabaseFile="$(OutDir)/$(InputName).pdb"
ImportLibrary="$(OutDir)/$(InputName).lib"
TargetMachine="17"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
SuppressStartupBanner="true"
OutputFile=".\Release/$(InputName).bsc"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
>
<File
RelativePath=".\multibundle1.cpp"
>
</File>
<File
RelativePath=".\multibundle2.cpp"
>
</File>
<File
RelativePath=".\PluginRegistration.cpp"
>
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl"
>
<File
RelativePath=".\multibundle1.h"
>
</File>
<File
RelativePath=".\multibundle2.h"
>
</File>
</Filter>
<Filter
Name="Resource Files"
Filter="ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>
+529
View File
@@ -0,0 +1,529 @@
#ifdef _WINDOWS
#include <windows.h>
#endif
#ifdef __APPLE__
#include <OpenGL/gl.h>
#else
#include <GL/gl.h>
#endif
#include <stdio.h>
#include <math.h>
#include "ofxsImageEffect.h"
#include "ofxsMultiThread.h"
#include "../include/ofxsProcessing.H"
#include "multibundle1.h"
static const OfxPointD kBoxSize = {20, 20};
class GammaInteract : public OFX::OverlayInteract
{
protected :
enum StateEnum {
eInActive,
ePoised,
ePicked
};
OfxPointD _position;
StateEnum _state;
public :
GammaInteract(OfxInteractHandle handle, OFX::ImageEffect* /*effect*/) : OFX::OverlayInteract(handle), _state(eInActive)
{
_position.x = 0;
_position.y = 0;
}
virtual bool draw(const OFX::DrawArgs &args);
virtual bool penMotion(const OFX::PenArgs &args);
virtual bool penDown(const OFX::PenArgs &args);
virtual bool penUp(const OFX::PenArgs &args);
};
template <class T>
inline T Absolute(T a)
{
return (a < 0) ? -a : a;
}
template <class T>
inline T Clamp(T v, int min, int max)
{
if(v < T(min))
return T(min);
if(v > T(max))
return T(max);
return v;
}
class ImageScalerBase : public OFX::ImageProcessor
{
protected :
OFX::Image *_srcImg;
OFX::Image *_maskImg;
double _rScale, _gScale, _bScale, _aScale;
bool _doMasking;
public :
ImageScalerBase(OFX::ImageEffect &instance): OFX::ImageProcessor(instance), _srcImg(0), _maskImg(0),
_rScale(1), _gScale(1), _bScale(1), _aScale(1), _doMasking(false)
{
}
void setSrcImg(OFX::Image *v) {_srcImg = v;}
void setMaskImg(OFX::Image *v) {_maskImg = v;}
void doMasking(bool v) {_doMasking = v;}
void setScales(float r, float g, float b, float a)
{
_rScale = r;
_gScale = g;
_bScale = b;
_aScale = a;
}
};
template <class PIX, int nComponents, int max>
class ImageScaler : public ImageScalerBase
{
public :
ImageScaler(OFX::ImageEffect &instance): ImageScalerBase(instance)
{}
void multiThreadProcessImages(OfxRectI procWindow)
{
float scales[4];
scales[0] = nComponents == 1 ? (float)_aScale : (float)_rScale;
scales[1] = (float)_gScale;
scales[2] = (float)_bScale;
scales[3] = (float)_aScale;
float maskScale = 1.0f;
for(int y = procWindow.y1; y < procWindow.y2; y++)
{
if(_effect.abort())
break;
PIX *dstPix = (PIX *) _dstImg->getPixelAddress(procWindow.x1, y);
for(int x = procWindow.x1; x < procWindow.x2; x++)
{
PIX *srcPix = (PIX *) (_srcImg ? _srcImg->getPixelAddress(x, y) : 0);
if(_doMasking)
{
if(!_maskImg)
maskScale = 1.0f;
else
{
PIX *maskPix = (PIX *) (_maskImg ? _maskImg->getPixelAddress(x, y) : 0);
maskScale = maskPix != 0 ? float(*maskPix)/float(max) : 0.0f;
}
}
if(srcPix)
{
for(int c = 0; c < nComponents; c++)
{
float v = (float)(pow((double)srcPix[c], (double)scales[c])) * maskScale + (1.0f - maskScale) * srcPix[c];
if(max == 1)
dstPix[c] = PIX(v);
else
dstPix[c] = PIX(Clamp(v, 0, max));
}
}
else
{
for(int c = 0; c < nComponents; c++)
dstPix[c] = 0;
}
dstPix += nComponents;
}
}
}
};
class GammaPlugin : public OFX::ImageEffect
{
protected :
OFX::Clip *dstClip_;
OFX::Clip *srcClip_;
OFX::Clip *maskClip_;
OFX::DoubleParam *scale_;
OFX::DoubleParam *rScale_;
OFX::DoubleParam *gScale_;
OFX::DoubleParam *bScale_;
OFX::DoubleParam *aScale_;
OFX::BooleanParam *componentScalesEnabled_;
public :
GammaPlugin(OfxImageEffectHandle handle): ImageEffect(handle), dstClip_(0), srcClip_(0), scale_(0)
, rScale_(0), gScale_(0), bScale_(0), aScale_(0), componentScalesEnabled_(0)
{
dstClip_ = fetchClip(kOfxImageEffectOutputClipName);
srcClip_ = fetchClip(kOfxImageEffectSimpleSourceClipName);
maskClip_ = getContext() == OFX::eContextFilter ? NULL : fetchClip(getContext() == OFX::eContextPaint ? "Brush" : "Mask");
scale_ = fetchDoubleParam("scale");
rScale_ = fetchDoubleParam("scaleR");
gScale_ = fetchDoubleParam("scaleG");
bScale_ = fetchDoubleParam("scaleB");
aScale_ = fetchDoubleParam("scaleA");
componentScalesEnabled_ = fetchBooleanParam("scaleComponents");
setEnabledness();
}
void setEnabledness();
virtual void render(const OFX::RenderArguments &args);
virtual bool isIdentity(const OFX::IsIdentityArguments &args, OFX::Clip * &identityClip, double &identityTime);
virtual void changedParam(const OFX::InstanceChangedArgs &args, const std::string &paramName);
virtual void changedClip(const OFX::InstanceChangedArgs &args, const std::string &clipName);
virtual bool getRegionOfDefinition(const OFX::RegionOfDefinitionArguments &args, OfxRectD &rod);
virtual void getRegionsOfInterest(const OFX::RegionsOfInterestArguments &args, OFX::RegionOfInterestSetter &rois);
void setupAndProcess(ImageScalerBase &, const OFX::RenderArguments &args);
};
void GammaPlugin::setupAndProcess(ImageScalerBase &processor, const OFX::RenderArguments &args)
{
std::unique_ptr<OFX::Image> dst(dstClip_->fetchImage(args.time));
OFX::BitDepthEnum dstBitDepth = dst->getPixelDepth();
OFX::PixelComponentEnum dstComponents = dst->getPixelComponents();
std::unique_ptr<OFX::Image> src(srcClip_->fetchImage(args.time));
if(src.get())
{
OFX::BitDepthEnum srcBitDepth = src->getPixelDepth();
OFX::PixelComponentEnum srcComponents = src->getPixelComponents();
if(srcBitDepth != dstBitDepth || srcComponents != dstComponents)
throw int(1);
}
std::unique_ptr<OFX::Image> mask;
if(getContext() != OFX::eContextFilter)
{
mask.reset(maskClip_->fetchImage(args.time));
processor.doMasking(true);
processor.setMaskImg(mask.get());
}
double r, g, b, a = aScale_->getValueAtTime(args.time);
r = g = b = scale_->getValueAtTime(args.time);
if(componentScalesEnabled_->getValueAtTime(args.time))
{
r += rScale_->getValueAtTime(args.time);
g += gScale_->getValueAtTime(args.time);
b += bScale_->getValueAtTime(args.time);
}
processor.setDstImg(dst.get());
processor.setSrcImg(src.get());
processor.setRenderWindow(args.renderWindow);
processor.setScales((float)r, (float)g, (float)b, (float)a);
processor.process();
}
bool GammaPlugin::getRegionOfDefinition(const OFX::RegionOfDefinitionArguments &args, OfxRectD &rod)
{
rod = srcClip_->getRegionOfDefinition(args.time);
return true;
}
void GammaPlugin::getRegionsOfInterest(const OFX::RegionsOfInterestArguments &args, OFX::RegionOfInterestSetter &rois)
{
rois.setRegionOfInterest(*srcClip_, args.regionOfInterest);
if(getContext() != OFX::eContextFilter)
rois.setRegionOfInterest(*maskClip_, args.regionOfInterest);
}
void GammaPlugin::render(const OFX::RenderArguments &args)
{
OFX::BitDepthEnum dstBitDepth = dstClip_->getPixelDepth();
OFX::PixelComponentEnum dstComponents = dstClip_->getPixelComponents();
if(dstComponents == OFX::ePixelComponentRGBA)
{
switch(dstBitDepth)
{
case OFX::eBitDepthUByte :
{
ImageScaler<unsigned char, 4, 255> fred(*this);
setupAndProcess(fred, args);
break;
}
case OFX::eBitDepthUShort :
{
ImageScaler<unsigned short, 4, 65535> fred(*this);
setupAndProcess(fred, args);
break;
}
case OFX::eBitDepthFloat :
{
ImageScaler<float, 4, 1> fred(*this);
setupAndProcess(fred, args);
break;
}
default :
OFX::throwSuiteStatusException(kOfxStatErrUnsupported);
}
}
else
{
switch(dstBitDepth)
{
case OFX::eBitDepthUByte :
{
ImageScaler<unsigned char, 1, 255> fred(*this);
setupAndProcess(fred, args);
break;
}
case OFX::eBitDepthUShort :
{
ImageScaler<unsigned short, 1, 65535> fred(*this);
setupAndProcess(fred, args);
break;
}
case OFX::eBitDepthFloat :
{
ImageScaler<float, 1, 1> fred(*this);
setupAndProcess(fred, args);
break;
}
default :
OFX::throwSuiteStatusException(kOfxStatErrUnsupported);
}
}
}
bool GammaPlugin:: isIdentity(const OFX::IsIdentityArguments &args, OFX::Clip * &identityClip, double &identityTime)
{
double scale = scale_->getValueAtTime(args.time);
double rScale = 1, gScale = 1, bScale = 1, aScale = 1;
if(componentScalesEnabled_->getValueAtTime(args.time)) {
rScale = rScale_->getValueAtTime(args.time);
gScale = gScale_->getValueAtTime(args.time);
bScale = bScale_->getValueAtTime(args.time);
aScale = aScale_->getValueAtTime(args.time);
}
rScale += scale;
gScale += scale;
bScale += scale;
if(rScale == 1 && gScale == 1 && bScale == 1 && aScale == 1) {
identityClip = srcClip_;
identityTime = args.time;
return true;
}
return false;
}
void GammaPlugin::setEnabledness(void)
{
bool v = componentScalesEnabled_->getValue() && srcClip_->getPixelComponents() == OFX::ePixelComponentRGBA;
rScale_->setEnabled(v);
gScale_->setEnabled(v);
bScale_->setEnabled(v);
aScale_->setEnabled(v);
}
void GammaPlugin::changedParam(const OFX::InstanceChangedArgs &/*args*/, const std::string &paramName)
{
if(paramName == "scaleComponents")
setEnabledness();
}
void GammaPlugin::changedClip(const OFX::InstanceChangedArgs &/*args*/, const std::string &clipName)
{
if(clipName == kOfxImageEffectSimpleSourceClipName)
setEnabledness();
}
bool GammaInteract::draw(const OFX::DrawArgs &args)
{
OfxRGBColourF col;
switch(_state) {
case eInActive :
col.r = col.g = col.b = 0.0f;
break;
case ePoised :
col.r = col.g = col.b = 0.5f;
break;
case ePicked :
col.r = col.g = col.b = 1.0f;
break;
}
float dx = (float)(kBoxSize.x * args.pixelScale.x);
float dy = (float)(kBoxSize.y * args.pixelScale.y);
glPushMatrix();
glColor3f(col.r, col.g, col.b);
glTranslated(_position.x, _position.y, 0);
glBegin(GL_POLYGON);
glVertex2f(-dx, -dy);
glVertex2f(-dx, dy);
glVertex2f( dx, dy);
glVertex2f( dx, -dy);
glEnd();
glPopMatrix();
glColor3f(1.0f - col.r, 1.0f - col.g, 1.0f - col.b);
glTranslated(_position.x, _position.y, 0);
glBegin(GL_LINE_LOOP);
glVertex2f(-dx, -dy);
glVertex2f(-dx, dy);
glVertex2f( dx, dy);
glVertex2f( dx, -dy);
glEnd();
glPopMatrix();
return true;
}
bool GammaInteract::penMotion(const OFX::PenArgs &args)
{
float dx = (float)(kBoxSize.x * args.pixelScale.x);
float dy = (float)(kBoxSize.y * args.pixelScale.y);
OfxPointD penPos = args.penPosition;
switch(_state)
{
case eInActive :
case ePoised :
{
StateEnum newState;
penPos.x -= _position.x;
penPos.y -= _position.y;
if(Absolute(penPos.x) < dx && Absolute(penPos.y) < dy)
{
newState = ePoised;
}
else
{
newState = eInActive;
}
if(_state != newState)
{
_state = newState;
_effect->redrawOverlays();
}
}
break;
case ePicked :
{
_position = penPos;
_effect->redrawOverlays();
}
break;
}
return _state != eInActive;
}
bool GammaInteract::penDown(const OFX::PenArgs &args)
{
penMotion(args);
if(_state == ePoised)
{
_state = ePicked;
_position = args.penPosition;
_effect->redrawOverlays();
}
return _state == ePicked;
}
bool GammaInteract::penUp(const OFX::PenArgs &args)
{
if(_state == ePicked)
{
_state = ePoised;
penMotion(args);
_effect->redrawOverlays();
return true;
}
return false;
}
using namespace OFX;
class GammaOverlayDescriptor : public DefaultEffectOverlayDescriptor<GammaOverlayDescriptor, GammaInteract> {};
void GammaExamplePluginFactory::describe(OFX::ImageEffectDescriptor &desc)
{
desc.setLabels("Gamma", "Gamma", "Gamma");
desc.setPluginGrouping("OFX Example (Support)");
desc.addSupportedContext(eContextFilter);
desc.addSupportedContext(eContextGeneral);
desc.addSupportedContext(eContextPaint);
desc.addSupportedBitDepth(eBitDepthUByte);
desc.addSupportedBitDepth(eBitDepthUShort);
desc.addSupportedBitDepth(eBitDepthFloat);
desc.setSingleInstance(false);
desc.setHostFrameThreading(false);
desc.setSupportsMultiResolution(true);
desc.setSupportsTiles(true);
desc.setTemporalClipAccess(false);
desc.setRenderTwiceAlways(false);
desc.setSupportsMultipleClipPARs(false);
desc.setOverlayInteractDescriptor( new GammaOverlayDescriptor );
}
static
DoubleParamDescriptor *defineScaleParam(OFX::ImageEffectDescriptor &desc,
const std::string &name, const std::string &label, const std::string &hint,
GroupParamDescriptor *parent, double def = 1.0)
{
DoubleParamDescriptor *param = desc.defineDoubleParam(name);
param->setLabels(label, label, label);
param->setScriptName(name);
param->setHint(hint);
param->setDefault(def);
param->setRange(0, 10);
param->setIncrement(0.1);
param->setDisplayRange(0, 10);
param->setDoubleType(eDoubleTypeScale);
if(parent)
param->setParent(*parent);
return param;
}
void GammaExamplePluginFactory::describeInContext(OFX::ImageEffectDescriptor &desc, OFX::ContextEnum context)
{
ClipDescriptor *srcClip = desc.defineClip(kOfxImageEffectSimpleSourceClipName);
srcClip->addSupportedComponent(ePixelComponentRGBA);
srcClip->addSupportedComponent(ePixelComponentAlpha);
srcClip->setTemporalClipAccess(false);
srcClip->setSupportsTiles(true);
srcClip->setIsMask(false);
if(context == eContextGeneral || context == eContextPaint)
{
ClipDescriptor *maskClip = context == eContextGeneral ? desc.defineClip("Mask") : desc.defineClip("Brush");
maskClip->addSupportedComponent(ePixelComponentAlpha);
maskClip->setTemporalClipAccess(false);
if(context == eContextGeneral)
maskClip->setOptional(true);
maskClip->setSupportsTiles(true);
maskClip->setIsMask(true);
}
ClipDescriptor *dstClip = desc.defineClip(kOfxImageEffectOutputClipName);
dstClip->addSupportedComponent(ePixelComponentRGBA);
dstClip->addSupportedComponent(ePixelComponentAlpha);
dstClip->setSupportsTiles(true);
PageParamDescriptor *page = desc.definePageParam("Controls");
GroupParamDescriptor *componentScalesGroup = desc.defineGroupParam("componentScales");
componentScalesGroup->setHint("Scales on the individual component");
componentScalesGroup->setLabels("Components", "Components", "Components");
DoubleParamDescriptor *param = defineScaleParam(desc, "scale", "scale", "Scales all component in the image", 0, 1.0);
page->addChild(*param);
BooleanParamDescriptor *boolP = desc.defineBooleanParam("scaleComponents");
boolP->setDefault(true);
boolP->setHint("Enables gamma correction on individual components");
boolP->setLabels("Gamma Components", "Gamma Components", "Gamma Components");
boolP->setParent(*componentScalesGroup);
page->addChild(*boolP);
param = defineScaleParam(desc, "scaleR", "red", "Gamma corrects the red component of the image", componentScalesGroup, 0.0);
page->addChild(*param);
param = defineScaleParam(desc, "scaleG", "green", "Gamma corrects the green component of the image", componentScalesGroup, 0.0);
page->addChild(*param);
param = defineScaleParam(desc, "scaleB", "blue", "Gamma corrects the blue component of the image", componentScalesGroup, 0.0);
page->addChild(*param);
param = defineScaleParam(desc, "scaleA", "alpha", "Gamma corrects the alpha component of the image", componentScalesGroup, 0.0);
page->addChild(*param);
}
ImageEffect* GammaExamplePluginFactory::createInstance(OfxImageEffectHandle handle, OFX::ContextEnum /*context*/)
{
return new GammaPlugin(handle);
}
+13
View File
@@ -0,0 +1,13 @@
#include "ofxsCore.h"
class GammaExamplePluginFactory : public OFX::PluginFactoryHelper<GammaExamplePluginFactory>
{
public:
GammaExamplePluginFactory():OFX::PluginFactoryHelper<GammaExamplePluginFactory>("net.sf.openfx.gammaexample", 1, 0){}
virtual void describe(OFX::ImageEffectDescriptor &desc);
virtual void describeInContext(OFX::ImageEffectDescriptor &desc, OFX::ContextEnum context);
virtual OFX::ImageEffect* createInstance(OfxImageEffectHandle handle, OFX::ContextEnum context);
};
@@ -0,0 +1,431 @@
#ifdef _WINDOWS
#include <windows.h>
#endif
#ifdef __APPLE__
#include <OpenGL/gl.h>
#else
#include <GL/gl.h>
#endif
#include <cassert>
#include "ofxsImageEffect.h"
#include "ofxsMultiThread.h"
#include "../include/ofxsProcessing.H"
#include "multibundle2.h"
static const OfxPointD kBoxSize = {20, 20};
class DotExampleInteract : public OFX::OverlayInteract
{
protected :
enum StateEnum {
eInActive,
ePoised,
ePicked
};
StateEnum _state;
OFX::Double2DParam* position_;
public :
DotExampleInteract(OfxInteractHandle handle, OFX::ImageEffect* effect) : OFX::OverlayInteract(handle), _state(eInActive)
{
position_ = effect->fetchDouble2DParam("position");
}
virtual bool draw(const OFX::DrawArgs &args);
virtual bool penMotion(const OFX::PenArgs &args);
virtual bool penDown(const OFX::PenArgs &args);
virtual bool penUp(const OFX::PenArgs &args);
};
template <class T>
inline T Absolute(T a)
{
return (a < 0) ? -a : a;
}
class DotGeneratorBase : public OFX::ImageProcessor
{
public :
DotGeneratorBase(OFX::ImageEffect &instance) : OFX::ImageProcessor(instance), _radius(0.0f), _positionx(0.0f), _positiony(0.0f)
{
_colour[0] = _colour[1] = _colour[2] = _colour[3] = 0;
}
void setRadius(float v) { _radius = v; }
void setR(float v) { _colour[0] = v;}
void setG(float v) { _colour[1] = v;}
void setB(float v) { _colour[2] = v;}
void setA(float v) { _colour[3] = v;}
void setColour(double r, double g, double b, double a)
{
setR((float)r);
setG((float)g);
setB((float)b);
setA((float)a);
}
void setPosition(float x, float y)
{
_positionx = x;
_positiony = y;
}
protected:
float _radius;
float _colour[4];
float _positionx;
float _positiony;
};
template <class PIX, int nComponents, int max>
class DotGenerator : public DotGeneratorBase {
public :
DotGenerator(OFX::ImageEffect &instance): DotGeneratorBase(instance){}
void multiThreadProcessImages(OfxRectI procWindow)
{
float radiusSq = _radius * _radius;
for(int y = procWindow.y1; y < procWindow.y2; y++)
{
if(_effect.abort())
break;
PIX *dstPix = (PIX *) _dstImg->getPixelAddress(procWindow.x1, y);
for(int x = procWindow.x1; x < procWindow.x2; x++)
{
float radsq = (x - _positionx)*(x - _positionx) + (y - _positiony)*(y - _positiony);
float val = radsq/radiusSq;
for(int c = 0; c < nComponents; c++)
{
dstPix[c] = val < 1.0f ? PIX((1.0f-val)*max) : PIX(0);
dstPix[c] = (PIX)(dstPix[c] * _colour[c]);
}
dstPix += nComponents;
}
}
}
};
class DotExamplePlugin : public OFX::ImageEffect
{
protected:
OFX::Clip *dstClip_;
OFX::DoubleParam *radius_;
OFX::RGBAParam *colour_;
OFX::Double2DParam* position_;
public:
DotExamplePlugin(OfxImageEffectHandle handle): ImageEffect(handle), dstClip_(0), radius_(0) , colour_(0), position_(0)
{
dstClip_ = fetchClip(kOfxImageEffectOutputClipName);
radius_ = fetchDoubleParam("radius");
colour_ = fetchRGBAParam("colour");
position_ = fetchDouble2DParam("position");
}
virtual void render(const OFX::RenderArguments &args);
void setupAndProcess(DotGeneratorBase &, const OFX::RenderArguments &args);
bool getRegionOfDefinition(const OFX::RegionOfDefinitionArguments &args, OfxRectD &rod);
template<class ARGS>
void getPositionInPixels(double& x, double& y, const ARGS& args);
template<class ARGS>
void getPositionInCanonical(double& x, double& y, const ARGS& args);
};
template<class ARGS>
void DotExamplePlugin::getPositionInCanonical(double& x, double& y, const ARGS& args)
{
position_->getValueAtTime(args.time, x, y);
}
template<class ARGS>
void DotExamplePlugin::getPositionInPixels(double& x, double& y, const ARGS& args)
{
double xpos, ypos;
getPositionInCanonical(xpos, ypos, args);
x = (xpos * args.renderScale.x) /getProjectPixelAspectRatio();
y = ypos * args.renderScale.y;
}
void DotExamplePlugin::setupAndProcess(DotGeneratorBase &processor, const OFX::RenderArguments &args)
{
std::unique_ptr<OFX::Image> dst(dstClip_->fetchImage(args.time));
//OFX::BitDepthEnum dstBitDepth = dst->getPixelDepth();
//OFX::PixelComponentEnum dstComponents = dst->getPixelComponents();
double rad = radius_->getValueAtTime(args.time);
processor.setRadius((float)(rad));
double r, g, b, a;
colour_->getValueAtTime(args.time, r, g, b, a);
processor.setColour(r,g,b,a);
processor.setDstImg(dst.get());
processor.setRenderWindow(args.renderWindow);
double xpospixel, ypospixel;
getPositionInPixels(xpospixel, ypospixel, args);
float fieldScaler = (args.fieldToRender == OFX::eFieldLower || args.fieldToRender == OFX::eFieldUpper)? 0.5f: 1.0f;
ypospixel *= fieldScaler;
processor.setPosition((float)xpospixel, (float)ypospixel);
processor.process();
}
bool DotExamplePlugin::getRegionOfDefinition(const OFX::RegionOfDefinitionArguments &args, OfxRectD &rod)
{
double r = radius_->getValueAtTime(args.time);
double x, y;
position_->getValueAtTime(args.time, x, y);
rod.x1 = x - r;
rod.y1 = y - r;
rod.x2 = x + r;
rod.y2 = y + r;
return true;
}
void DotExamplePlugin::render(const OFX::RenderArguments &args)
{
OFX::BitDepthEnum dstBitDepth = dstClip_->getPixelDepth();
OFX::PixelComponentEnum dstComponents = dstClip_->getPixelComponents();
if(dstComponents == OFX::ePixelComponentRGBA)
{
switch(dstBitDepth)
{
case OFX::eBitDepthUByte :
{
DotGenerator<unsigned char, 4, 255> fred(*this);
setupAndProcess(fred, args);
}
break;
case OFX::eBitDepthUShort :
{
DotGenerator<unsigned short, 4, 65535> fred(*this);
setupAndProcess(fred, args);
}
break;
case OFX::eBitDepthFloat :
{
DotGenerator<float, 4, 1> fred(*this);
setupAndProcess(fred, args);
}
break;
default :
OFX::throwSuiteStatusException(kOfxStatErrUnsupported);
}
}
else
{
switch(dstBitDepth)
{
case OFX::eBitDepthUByte :
{
DotGenerator<unsigned char, 1, 255> fred(*this);
setupAndProcess(fred, args);
}
break;
case OFX::eBitDepthUShort :
{
DotGenerator<unsigned short, 1, 65535> fred(*this);
setupAndProcess(fred, args);
}
break;
case OFX::eBitDepthFloat :
{
DotGenerator<float, 1, 1> fred(*this);
setupAndProcess(fred, args);
}
break;
default :
OFX::throwSuiteStatusException(kOfxStatErrUnsupported);
}
}
}
bool DotExampleInteract::draw(const OFX::DrawArgs &args)
{
OfxRGBColourF col;
col.r = 0.5f;
col.g = 0.0f;
switch(_state)
{
case eInActive :
col.b = 0.0f;
break;
case ePoised :
col.b = 0.5f;
break;
case ePicked :
col.b = 1.0f;
break;
}
float dx = (float)(kBoxSize.x * args.pixelScale.x);
float dy = (float)(kBoxSize.y * args.pixelScale.y);
double xpos = 0., ypos = 0.;
DotExamplePlugin* plug = dynamic_cast<DotExamplePlugin*>(_effect);
assert(plug);
if (plug) {
plug->getPositionInCanonical(xpos, ypos, args);
}
glPushMatrix();
glColor3f(col.r, col.g, col.b);
glTranslated(xpos, ypos, 0);
glBegin(GL_POLYGON);
glVertex2f(-dx, -dy);
glVertex2f(-dx, dy);
glVertex2f( dx, dy);
glVertex2f( dx, -dy);
glEnd();
glPopMatrix();
glColor3f(1.0f - col.r, 1.0f - col.g, 1.0f - col.b);
glTranslated(xpos, ypos, 0);
glBegin(GL_LINE_LOOP);
glVertex2f(-dx, -dy);
glVertex2f(-dx, dy);
glVertex2f( dx, dy);
glVertex2f( dx, -dy);
glEnd();
glPopMatrix();
return true;
}
bool DotExampleInteract::penMotion(const OFX::PenArgs &args)
{
float dx = (float)(kBoxSize.x * args.pixelScale.x);
float dy = (float)(kBoxSize.y * args.pixelScale.y);
OfxPointD penPos = args.penPosition;
switch(_state)
{
case eInActive :
case ePoised :
{
StateEnum newState;
double xpos = 0., ypos = 0.;
DotExamplePlugin* plug = dynamic_cast<DotExamplePlugin*>(_effect);
if (plug) {
plug->getPositionInCanonical(xpos, ypos, args);
}
penPos.x -= xpos;
penPos.y -= ypos;
if(Absolute(penPos.x) < dx && Absolute(penPos.y) < dy)
{
newState = ePoised;
}
else
{
newState = eInActive;
}
if(_state != newState)
{
_state = newState;
_effect->redrawOverlays();
}
}
break;
case ePicked :
{
position_->setValueAtTime(args.time, args.penPosition.x, args.penPosition.y);
_effect->redrawOverlays();
}
break;
}
return _state != eInActive;
}
bool DotExampleInteract::penDown(const OFX::PenArgs &args)
{
penMotion(args);
if(_state == ePoised)
{
_state = ePicked;
_effect->redrawOverlays();
}
return _state == ePicked;
}
bool DotExampleInteract::penUp(const OFX::PenArgs &args)
{
if(_state == ePicked)
{
_state = ePoised;
penMotion(args);
_effect->redrawOverlays();
return true;
}
return false;
}
using namespace OFX;
class DotExampleOverlayDescriptor : public DefaultEffectOverlayDescriptor<DotExampleOverlayDescriptor, DotExampleInteract> {};
void DotExamplePluginFactory::describe(OFX::ImageEffectDescriptor &desc)
{
desc.setLabels("Dot Generator", "Dot Generator", "Dot Generator");
desc.setPluginGrouping("OFX Example (Support)");
desc.addSupportedContext(eContextGenerator);
desc.addSupportedContext(eContextGeneral);
desc.addSupportedBitDepth(eBitDepthUByte);
desc.addSupportedBitDepth(eBitDepthUShort);
desc.addSupportedBitDepth(eBitDepthFloat);
desc.setSingleInstance(false);
desc.setHostFrameThreading(false);
desc.setSupportsMultiResolution(true);
desc.setSupportsTiles(true);
desc.setTemporalClipAccess(false);
desc.setRenderTwiceAlways(false);
desc.setSupportsMultipleClipPARs(false);
desc.setRenderTwiceAlways(false);
desc.setOverlayInteractDescriptor( new DotExampleOverlayDescriptor );
}
void DotExamplePluginFactory::describeInContext(OFX::ImageEffectDescriptor &desc, OFX::ContextEnum /*context*/)
{
// there has to be an input clip, even for generators
ClipDescriptor* srcClip = desc.defineClip( kOfxImageEffectSimpleSourceClipName );
srcClip->addSupportedComponent( OFX::ePixelComponentRGBA );
srcClip->addSupportedComponent( OFX::ePixelComponentAlpha );
srcClip->setSupportsTiles(true);
srcClip->setOptional(true);
ClipDescriptor *dstClip = desc.defineClip(kOfxImageEffectOutputClipName);
dstClip->addSupportedComponent(ePixelComponentRGBA);
dstClip->addSupportedComponent(ePixelComponentAlpha);
dstClip->setSupportsTiles(true);
dstClip->setFieldExtraction(eFieldExtractSingle);
DoubleParamDescriptor *param = desc.defineDoubleParam("radius");
param->setLabels("Radius", "Radius", "Radius");
param->setScriptName("radius");
param->setHint("The radius of the dot produced.");
param->setDoubleType(eDoubleTypeX);
param->setDefaultCoordinateSystem(eCoordinatesNormalised);
param->setDefault(0.02);
//param->setRange(0, 1);
param->setIncrement(1);
param->setDisplayRange(0, 1);
param->setAnimates(true);
RGBAParamDescriptor *param2 = desc.defineRGBAParam("colour");
param2->setAnimates(true);
param2->setLabels("Colour", "Colour", "Colour");
param2->setHint("The colour of the dot produced.");
param2->setScriptName("colour");
param2->setDefault(1.0, 1.0, 1.0, 1.0);
Double2DParamDescriptor* param3 = desc.defineDouble2DParam("position");
param3->setLabels("Dot Position", "Dot Position", "Dot Position");
param3->setDoubleType(eDoubleTypeXY);
param3->setDefaultCoordinateSystem(eCoordinatesNormalised);
param3->setAnimates(true);
param3->setDimensionLabels("X", "Y");
param3->setDefault(0.5, 0.5);
PageParamDescriptor *page = desc.definePageParam("Controls");
page->addChild(*param);
page->addChild(*param2);
page->addChild(*param3);
}
ImageEffect* DotExamplePluginFactory::createInstance(OfxImageEffectHandle handle, OFX::ContextEnum /*context*/)
{
return new DotExamplePlugin(handle);
}
+13
View File
@@ -0,0 +1,13 @@
#include "ofxsImageEffect.h"
class DotExamplePluginFactory : public OFX::PluginFactoryHelper<DotExamplePluginFactory>
{
public:
DotExamplePluginFactory():OFX::PluginFactoryHelper<DotExamplePluginFactory>("net.sf.openfx.dotexample", 1, 0){}
virtual void describe(OFX::ImageEffectDescriptor &desc);
virtual void describeInContext(OFX::ImageEffectDescriptor &desc, OFX::ContextEnum context);
virtual OFX::ImageEffect* createInstance(OfxImageEffectHandle handle, OFX::ContextEnum context);
};