TuttleOFX
1
|
00001 #include "OfxhImageEffectSuite.hpp" 00002 #include "OfxhImageEffectNode.hpp" 00003 00004 namespace tuttle { 00005 namespace host { 00006 namespace ofx { 00007 namespace imageEffect { 00008 00009 namespace { 00010 00011 OfxStatus getPropertySet( OfxImageEffectHandle h1, 00012 OfxPropertySetHandle* h2 ) 00013 { 00014 OfxhImageEffectNodeBase* effectBase = reinterpret_cast<OfxhImageEffectNodeBase*>( h1 ); 00015 00016 if( !effectBase || !effectBase->verifyMagic() ) 00017 { 00018 return kOfxStatErrBadHandle; 00019 } 00020 00021 *h2 = effectBase->getProperties().getHandle(); 00022 return kOfxStatOK; 00023 } 00024 00025 OfxStatus getParamSet( OfxImageEffectHandle h1, 00026 OfxParamSetHandle* h2 ) 00027 { 00028 imageEffect::OfxhImageEffectNodeBase* effectBase = reinterpret_cast<imageEffect::OfxhImageEffectNodeBase*>( h1 ); 00029 00030 if( !effectBase || !effectBase->verifyMagic() ) 00031 { 00032 return kOfxStatErrBadHandle; 00033 } 00034 00035 imageEffect::OfxhImageEffectNodeDescriptor* effectDescriptor = dynamic_cast<imageEffect::OfxhImageEffectNodeDescriptor*>( effectBase ); 00036 00037 if( effectDescriptor ) 00038 { 00039 *h2 = effectDescriptor->getParamSetHandle(); 00040 return kOfxStatOK; 00041 } 00042 00043 imageEffect::OfxhImageEffectNode* effectInstance = dynamic_cast<imageEffect::OfxhImageEffectNode*>( effectBase ); 00044 00045 if( effectInstance ) 00046 { 00047 *h2 = effectInstance->getParamSetHandle(); 00048 return kOfxStatOK; 00049 } 00050 00051 return kOfxStatErrBadHandle; 00052 } 00053 00054 OfxStatus clipDefine( OfxImageEffectHandle h1, 00055 const char* name, 00056 OfxPropertySetHandle* h2 ) 00057 { 00058 imageEffect::OfxhImageEffectNodeBase* effectBase = reinterpret_cast<imageEffect::OfxhImageEffectNodeBase*>( h1 ); 00059 00060 if( !effectBase || !effectBase->verifyMagic() ) 00061 { 00062 return kOfxStatErrBadHandle; 00063 } 00064 00065 imageEffect::OfxhImageEffectNodeDescriptor* effectDescriptor = dynamic_cast<imageEffect::OfxhImageEffectNodeDescriptor*>( effectBase ); 00066 00067 if( !effectDescriptor ) 00068 return kOfxStatErrBadHandle; 00069 00070 attribute::OfxhClipImageDescriptor* clip = effectDescriptor->defineClip( name ); 00071 *h2 = clip->getPropHandle(); 00072 return kOfxStatOK; 00073 } 00074 00075 OfxStatus clipGetPropertySet( OfxImageClipHandle clip, 00076 OfxPropertySetHandle* propHandle ) 00077 { 00078 attribute::OfxhClipImage* clipInstance = reinterpret_cast<attribute::OfxhClipImage*>( clip ); 00079 00080 if( !clipInstance || !clipInstance->verifyMagic() ) 00081 { 00082 return kOfxStatErrBadHandle; 00083 } 00084 00085 *propHandle = clipInstance->getPropHandle(); 00086 return kOfxStatOK; 00087 } 00088 00089 OfxStatus clipGetImage( OfxImageClipHandle h1, 00090 OfxTime time, 00091 OfxRectD* h2, 00092 OfxPropertySetHandle* h3 ) 00093 { 00094 attribute::OfxhClipImage* clipInstance = reinterpret_cast<attribute::OfxhClipImage*>( h1 ); 00095 00096 if( !clipInstance || !clipInstance->verifyMagic() ) 00097 { 00098 return kOfxStatErrBadHandle; 00099 } 00100 00101 OfxhImage* image = clipInstance->getImage( time, h2 ); 00102 if( !image ) 00103 { 00104 h3 = NULL; 00105 return kOfxStatFailed; 00106 } 00107 00108 image->addReference( OfxhImage::eReferenceOwnerPlugin ); 00109 *h3 = image->getPropHandle(); // a pointer to the base class cast into OfxPropertySetHandle 00110 00111 return kOfxStatOK; 00112 } 00113 00114 OfxStatus clipReleaseImage( OfxPropertySetHandle h1 ) 00115 { 00116 property::OfxhSet* pset = reinterpret_cast<property::OfxhSet*>( h1 ); 00117 00118 if( !pset || !pset->verifyMagic() ) 00119 { 00120 return kOfxStatErrBadHandle; 00121 } 00122 00123 OfxhImage* image = dynamic_cast<OfxhImage*>( pset ); 00124 if( !image ) 00125 return kOfxStatErrBadHandle; 00126 00127 // clip::image has a virtual destructor for derived classes 00128 image->releaseReference( OfxhImage::eReferenceOwnerPlugin ); 00129 return kOfxStatOK; 00130 } 00131 00132 OfxStatus clipGetHandle( OfxImageEffectHandle imageEffect, 00133 const char* name, 00134 OfxImageClipHandle* clip, 00135 OfxPropertySetHandle* propertySet ) 00136 { 00137 imageEffect::OfxhImageEffectNodeBase* effectBase = reinterpret_cast<imageEffect::OfxhImageEffectNodeBase*>( imageEffect ); 00138 00139 if( !effectBase || !effectBase->verifyMagic() ) 00140 return kOfxStatErrBadHandle; 00141 00142 imageEffect::OfxhImageEffectNode* effectInstance = dynamic_cast<imageEffect::OfxhImageEffectNode*>( effectBase ); 00143 00144 if( !effectInstance ) 00145 return kOfxStatErrBadHandle; 00146 00147 attribute::OfxhClipImage& instance = effectInstance->getClip( name ); 00148 *clip = instance.getOfxImageClipHandle(); 00149 if( propertySet ) 00150 *propertySet = instance.getPropHandle(); 00151 00152 return kOfxStatOK; 00153 } 00154 00155 OfxStatus clipGetRegionOfDefinition( OfxImageClipHandle clip, 00156 OfxTime time, 00157 OfxRectD* bounds ) 00158 { 00159 attribute::OfxhClipImage* clipInstance = reinterpret_cast<attribute::OfxhClipImage*>( clip ); 00160 00161 if( !clipInstance || !clipInstance->verifyMagic() ) 00162 return kOfxStatErrBadHandle; 00163 00164 *bounds = clipInstance->fetchRegionOfDefinition( time ); 00165 return kOfxStatOK; 00166 } 00167 00168 // should processing be aborted? 00169 00170 int abort( OfxImageEffectHandle imageEffect ) 00171 { 00172 imageEffect::OfxhImageEffectNodeBase* effectBase = reinterpret_cast<imageEffect::OfxhImageEffectNodeBase*>( imageEffect ); 00173 00174 if( !effectBase || !effectBase->verifyMagic() ) 00175 return kOfxStatErrBadHandle; 00176 00177 imageEffect::OfxhImageEffectNode* effectInstance = dynamic_cast<imageEffect::OfxhImageEffectNode*>( effectBase ); 00178 00179 if( !effectInstance ) 00180 return kOfxStatErrBadHandle; 00181 00182 return effectInstance->abort(); 00183 } 00184 00185 OfxStatus imageMemoryAlloc( OfxImageEffectHandle instanceHandle, 00186 size_t nBytes, 00187 OfxImageMemoryHandle* memoryHandle ) 00188 { 00189 imageEffect::OfxhImageEffectNodeBase* effectBase = reinterpret_cast<imageEffect::OfxhImageEffectNodeBase*>( instanceHandle ); 00190 if( !effectBase || !effectBase->verifyMagic() ) 00191 return kOfxStatErrBadHandle; 00192 00193 imageEffect::OfxhImageEffectNode* effectInstance = dynamic_cast<imageEffect::OfxhImageEffectNode*>( effectBase ); 00194 OfxhMemory* memory; 00195 00196 if( effectInstance ) 00197 { 00198 if( !effectInstance->verifyMagic() ) 00199 return kOfxStatErrBadHandle; 00200 00201 memory = effectInstance->imageMemoryAlloc( nBytes ); 00202 } 00203 else 00204 { 00205 memory = new OfxhMemory; 00206 memory->alloc( nBytes ); 00207 } 00208 00209 *memoryHandle = memory->getHandle(); 00210 return kOfxStatOK; 00211 } 00212 00213 OfxStatus imageMemoryFree( OfxImageMemoryHandle memoryHandle ) 00214 { 00215 OfxhMemory* memoryInstance = reinterpret_cast<OfxhMemory*>( memoryHandle ); 00216 00217 if( !memoryInstance || !memoryInstance->verifyMagic() ) 00218 return kOfxStatErrBadHandle; 00219 00220 memoryInstance->freeMem(); 00221 delete memoryInstance; 00222 return kOfxStatOK; 00223 } 00224 00225 OfxStatus imageMemoryLock( OfxImageMemoryHandle memoryHandle, 00226 void** returnedPtr ) 00227 { 00228 OfxhMemory* memoryInstance = reinterpret_cast<OfxhMemory*>( memoryHandle ); 00229 00230 if( !memoryInstance || !memoryInstance->verifyMagic() ) 00231 return kOfxStatErrBadHandle; 00232 00233 memoryInstance->lock(); 00234 *returnedPtr = memoryInstance->getPtr(); 00235 return kOfxStatOK; 00236 } 00237 00238 OfxStatus imageMemoryUnlock( OfxImageMemoryHandle memoryHandle ) 00239 { 00240 OfxhMemory* memoryInstance = reinterpret_cast<OfxhMemory*>( memoryHandle ); 00241 00242 if( !memoryInstance || !memoryInstance->verifyMagic() ) 00243 return kOfxStatErrBadHandle; 00244 00245 memoryInstance->unlock(); 00246 return kOfxStatOK; 00247 } 00248 00249 struct OfxImageEffectSuiteV1 gImageEffectSuite = 00250 { 00251 getPropertySet, 00252 getParamSet, 00253 clipDefine, 00254 clipGetHandle, 00255 clipGetPropertySet, 00256 clipGetImage, 00257 clipReleaseImage, 00258 clipGetRegionOfDefinition, 00259 abort, 00260 imageMemoryAlloc, 00261 imageMemoryFree, 00262 imageMemoryLock, 00263 imageMemoryUnlock 00264 }; 00265 00266 } 00267 00268 void* getImageEffectSuite( const int version ) 00269 { 00270 if( version == 1 ) 00271 return &gImageEffectSuite; 00272 return NULL; 00273 } 00274 00275 } 00276 } 00277 } 00278 } 00279