int main(int argc, char **argv) { #ifdef _WIN32 _CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF ); #endif /// set the version label in the global cache OFX::Host::PluginCache::getPluginCache()->setCacheVersion("cacheDemoV1"); /// create our derived image effect host CacheHost myHost; /// make an image effect plugin cache OFX::Host::ImageEffect::PluginCache imageEffectPluginCache(myHost); /// register the image effect cache with the global plugin cache imageEffectPluginCache.registerInCache(*OFX::Host::PluginCache::getPluginCache()); /// now read an old cache cache std::ifstream ifs("oldcache.xml"); OFX::Host::PluginCache::getPluginCache()->readCache(ifs); OFX::Host::PluginCache::getPluginCache()->scanPluginFiles(); ifs.close(); /// and write a new cache, long version with everything in there std::ofstream of("newCache.xml"); OFX::Host::PluginCache::getPluginCache()->writePluginCache(of); of.close(); imageEffectPluginCache.dumpToStdOut(); //Clean up, to be polite. OFX::Host::PluginCache::clearPluginCache(); }
int main(int argc, char **argv) { //_CrtSetBreakAlloc(3168); #ifdef _WIN32 _CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF ); #endif // set the version label in the global cache OFX::Host::PluginCache::getPluginCache()->setCacheVersion("hostDemoV1"); // create our derived image effect host which provides // a factory to make plugin instances and acts // as a description of the host application MyHost::Host myHost; // make an image effect plugin cache. This is what knows about // all the plugins. OFX::Host::ImageEffect::PluginCache imageEffectPluginCache(myHost); // register the image effect cache with the global plugin cache imageEffectPluginCache.registerInCache(*OFX::Host::PluginCache::getPluginCache()); // try to read an old cache std::ifstream ifs("hostDemoPluginCache.xml"); OFX::Host::PluginCache::getPluginCache()->readCache(ifs); OFX::Host::PluginCache::getPluginCache()->scanPluginFiles(); ifs.close(); /// flush out the current cache std::ofstream of("hostDemoPluginCache.xml"); OFX::Host::PluginCache::getPluginCache()->writePluginCache(of); of.close(); // get the invert example plugin which uses the OFX C++ support code OFX::Host::ImageEffect::ImageEffectPlugin* plugin = imageEffectPluginCache.getPluginById("net.sf.openfx:invertPlugin"); imageEffectPluginCache.dumpToStdOut(); if(plugin) { // create an instance of it as a filter // the first arg is the context, the second is client data we are allowed to pass down the call chain std::auto_ptr<OFX::Host::ImageEffect::Instance> instance(plugin->createInstance(kOfxImageEffectContextFilter, NULL)); if(instance.get()) { OfxStatus stat; // now we need to call the create instance action. Only call this once you have initialised all the params // and clips to their correct values. So if you are loading a saved plugin state, set up your params from // that state, _then_ call create instance. stat = instance->createInstanceAction(); assert(stat == kOfxStatOK || stat == kOfxStatReplyDefault); // now we need to to call getClipPreferences on the instance so that it does the clip component/depth // logic and caches away the components and depth on each clip. bool ok = instance->getClipPreferences(); assert(ok); // current render scale of 1 OfxPointD renderScale; renderScale.x = renderScale.y = 1.0; // The render window is in pixel coordinates // ie: render scale and a PAR of not 1 OfxRectI renderWindow; renderWindow.x1 = renderWindow.y1 = 0; renderWindow.x2 = 720; renderWindow.y2 = 576; /// RoI is in canonical coords, OfxRectD regionOfInterest; regionOfInterest.x1 = regionOfInterest.y1 = 0; regionOfInterest.x2 = renderWindow.x2 * instance->getProjectPixelAspectRatio(); regionOfInterest.y2 = 576; int numFramesToRender = OFXHOSTDEMOCLIPLENGTH; // say we are about to render a bunch of frames stat = instance->beginRenderAction(0, numFramesToRender, 1.0, false, renderScale, /*sequential=*/true, /*interactive=*/false, # ifdef OFX_SUPPORTS_OPENGLRENDER /*openGLRender=*/false, # endif /*draftRender=*/false # ifdef OFX_EXTENSIONS_NUKE , 0 /* view*/ # endif ); assert(stat == kOfxStatOK || stat == kOfxStatReplyDefault); // get the output clip MyHost::MyClipInstance* outputClip = dynamic_cast<MyHost::MyClipInstance*>(instance->getClip("Output")); assert(outputClip); for(int t = 0; t <= numFramesToRender; ++t) { // call get region of interest on each of the inputs OfxTime frame = t; // get the RoI for each input clip // the regions of interest for each input clip are returned in a std::map // on a real host, these will be the regions of each input clip that the // effect needs to render a given frame (clipped to the RoD). // // In our example we are doing full frame fetches regardless. std::map<OFX::Host::ImageEffect::ClipInstance *, OfxRectD> rois; stat = instance->getRegionOfInterestAction(frame, renderScale, #ifdef OFX_EXTENSIONS_NUKE /*view=*/0, #endif regionOfInterest, rois); assert(stat == kOfxStatOK || stat == kOfxStatReplyDefault); #if defined(OFX_EXTENSIONS_VEGAS) || defined(OFX_EXTENSIONS_NUKE) // render a stereoscopic frame { // left view stat = instance->renderAction(t,kOfxImageFieldBoth,renderWindow, renderScale, /*sequential=*/true, /*interactive=*/false, # ifdef OFX_SUPPORTS_OPENGLRENDER /*openGLRender=*/false, # endif /*draft=*/false, 0 /*view*/ # ifdef OFX_EXTENSIONS_VEGAS , 2 /*nViews*/ # endif # ifdef OFX_EXTENSIONS_NUKE , std::list<std::string>() /*planes*/ # endif ); assert(stat == kOfxStatOK); // get the output image buffer MyHost::MyImage *outputImage = outputClip->getOutputImage(); assert(outputImage); std::ostringstream ss; ss << "Output." << t << "l.ppm"; exportToPPM(ss.str(), outputImage); } { // right view instance->renderAction(t,kOfxImageFieldBoth,renderWindow, renderScale, /*sequential=*/true, /*interactive=*/false, # ifdef OFX_SUPPORTS_OPENGLRENDER /*openGLRender=*/false, # endif /*draft=*/false, 1 /*view*/ # ifdef OFX_EXTENSIONS_VEGAS , 2 /*nViews*/ # endif # ifdef OFX_EXTENSIONS_NUKE , std::list<std::string>() /*planes*/ # endif ); assert(stat == kOfxStatOK); // get the output image buffer MyHost::MyImage *outputImage = outputClip->getOutputImage(); assert(outputImage); std::ostringstream ss; ss << "Output." << t << "r.ppm"; exportToPPM(ss.str(), outputImage); } #else // render a frame stat = instance->renderAction(t,kOfxImageFieldBoth,renderWindow, renderScale, /*sequential=*/true, /*interactive=*/false, /*draft=*/false); assert(stat == kOfxStatOK); // get the output image buffer MyHost::MyImage *outputImage = outputClip->getOutputImage(); std::ostringstream ss; ss << "Output." << t << ".ppm"; exportToPPM(ss.str(), outputImage); #endif } instance->endRenderAction(0, numFramesToRender, 1.0, false, renderScale, /*sequential=*/true, /*interactive=*/false, # ifdef OFX_SUPPORTS_OPENGLRENDER /*openGLRender=*/false, # endif /*draftRender=*/false # ifdef OFX_EXTENSIONS_NUKE , 0 /* view*/ # endif ); } } OFX::Host::PluginCache::clearPluginCache(); return 0; }