TuttleOFX
1
|
00001 #include "ViewerPlugin.hpp" 00002 #include "ViewerProcess.hpp" 00003 #include "ViewerDefinitions.hpp" 00004 00005 #include <boost/gil/gil_all.hpp> 00006 00007 namespace tuttle { 00008 namespace plugin { 00009 namespace viewer { 00010 00011 00012 ViewerPlugin::ViewerPlugin( OfxImageEffectHandle handle ) 00013 : ImageEffectGilPlugin( handle ) 00014 { 00015 // _clipSrcMatte = fetchClip( kClipMatte ); 00016 } 00017 00018 ViewerProcessParams<ViewerPlugin::Scalar> ViewerPlugin::getProcessParams( const OfxPointD& renderScale ) const 00019 { 00020 ViewerProcessParams<Scalar> params; 00021 return params; 00022 } 00023 00024 void ViewerPlugin::changedParam( const OFX::InstanceChangedArgs &args, const std::string ¶mName ) 00025 { 00026 } 00027 00028 bool ViewerPlugin::isIdentity( const OFX::RenderArguments& args, OFX::Clip*& identityClip, double& identityTime ) 00029 { 00030 return false; 00031 } 00032 00033 /** 00034 * @brief The overridden render function 00035 * @param[in] args Rendering parameters 00036 */ 00037 void ViewerPlugin::render( const OFX::RenderArguments &args ) 00038 { 00039 boost::scoped_ptr<OFX::Image> src( _clipSrc->fetchImage( args.time ) ); 00040 boost::scoped_ptr<OFX::Image> dst( _clipDst->fetchImage( args.time ) ); 00041 00042 // Copy buffer 00043 const OfxRectI bounds = dst->getBounds(); 00044 TUTTLE_TLOG_VAR( TUTTLE_INFO, bounds ); 00045 00046 size_t width = dst->getBoundsSize().x; 00047 size_t height = dst->getBoundsSize().y; 00048 size_t components = 0; 00049 00050 GLenum format = GL_RGB; 00051 GLenum type = GL_FLOAT; 00052 00053 switch( dst->getPixelDepth() ) 00054 { 00055 case OFX::eBitDepthCustom: 00056 case OFX::eBitDepthNone: 00057 BOOST_THROW_EXCEPTION( exception::BitDepthMismatch() 00058 << exception::user( "Viewer: Unable to compute custom or non bit depth" ) ); 00059 break; 00060 case OFX::eBitDepthUByte: type = GL_UNSIGNED_BYTE; break; 00061 case OFX::eBitDepthUShort: type = GL_UNSIGNED_SHORT; break; 00062 case OFX::eBitDepthFloat: type = GL_FLOAT; break; 00063 } 00064 switch( dst->getPixelComponents() ) 00065 { 00066 case OFX::ePixelComponentAlpha: components = 1; format = GL_LUMINANCE; break; 00067 case OFX::ePixelComponentRGB : components = 3; format = GL_RGB; break; 00068 case OFX::ePixelComponentRGBA : components = 4; format = GL_RGBA; break; 00069 default: 00070 BOOST_THROW_EXCEPTION( exception::BitDepthMismatch() 00071 << exception::user( "Viewer: Unable to compute unknown component." ) ); 00072 break; 00073 } 00074 00075 size_t imgSizeBytes = width * height * dst->getPixelBytes() ; 00076 00077 char* data = new char[ imgSizeBytes ]; 00078 char* tmpData = data; 00079 00080 if( src->isLinearBuffer() && dst->isLinearBuffer() ) 00081 { 00082 TUTTLE_TLOG( TUTTLE_INFO, "isLinearBuffer" ); 00083 const std::size_t imageDataBytes = dst->getBoundsImageDataBytes(); 00084 TUTTLE_TLOG_VAR( TUTTLE_INFO, imageDataBytes ); 00085 if( imageDataBytes ) 00086 { 00087 void* dataSrcPtr = src->getPixelAddress( bounds.x1, bounds.y1 ); 00088 void* dataDstPtr = dst->getPixelAddress( bounds.x1, bounds.y1 ); 00089 memcpy( dataDstPtr, dataSrcPtr, imageDataBytes ); 00090 memcpy( tmpData, dataSrcPtr, imageDataBytes ); 00091 tmpData += imageDataBytes; 00092 } 00093 } 00094 else 00095 { 00096 const std::size_t rowBytesToCopy = dst->getBoundsRowDataBytes(); 00097 for( int y = bounds.y1; y < bounds.y2; ++y ) 00098 { 00099 void* dataSrcPtr = src->getPixelAddress( bounds.x1, y ); 00100 void* dataDstPtr = dst->getPixelAddress( bounds.x1, y ); 00101 memcpy( dataDstPtr, dataSrcPtr, rowBytesToCopy ); 00102 memcpy( tmpData, dataSrcPtr, rowBytesToCopy ); 00103 tmpData += rowBytesToCopy; 00104 } 00105 } 00106 00107 openGLWindow( width, height ); 00108 00109 loadNewTexture( data, components, width, height, format, type ); 00110 00111 glutIdleFunc(idle); 00112 glutMainLoop(); 00113 } 00114 00115 00116 } 00117 } 00118 }