TuttleOFX
1
|
00001 #include "InputBufferWrapper.hpp" 00002 #include "Core.hpp" 00003 #include "exceptions.hpp" 00004 #include "memory/LinkData.hpp" 00005 00006 #include <tuttle/host/ofx/attribute/OfxhClipImageDescriptor.hpp> 00007 00008 #include <boost/lexical_cast.hpp> 00009 #include <boost/assign/list_of.hpp> 00010 00011 #include <map> 00012 00013 00014 namespace tuttle { 00015 namespace host { 00016 00017 using namespace boost::assign; 00018 00019 void InputBufferWrapper::setMode( const EMode mode ) 00020 { 00021 static std::map<EMode, const char*> toString = map_list_of 00022 ( eModeBuffer, "bufferPointer" ) 00023 ( eModeCallback, "callbackPointer" ); 00024 00025 getNode().getParam( "mode" ).setValue( toString.find(mode)->second ); 00026 } 00027 00028 void InputBufferWrapper::setBuffer( void* rawBuffer ) 00029 { 00030 getNode().getParam( "bufferPointer" ).setValue( 00031 boost::lexical_cast<std::string>( reinterpret_cast<std::ptrdiff_t>(rawBuffer) ) 00032 ); 00033 } 00034 00035 void InputBufferWrapper::set2DArrayBuffer( void* rawBuffer, const int width, const int height ) 00036 { 00037 setBuffer( rawBuffer ); 00038 setSize( width, height ); 00039 setComponents( ePixelComponentAlpha ); 00040 } 00041 00042 void InputBufferWrapper::set3DArrayBuffer( void* rawBuffer, const int width, const int height, const int nbComponents ) 00043 { 00044 TUTTLE_TLOG_INFOS; 00045 TUTTLE_TLOG( TUTTLE_INFO, "[Inpput buffer wrapper] width = " << width << ", height = " << height << ", components = " << nbComponents ); 00046 setBuffer( rawBuffer ); 00047 setSize( width, height ); 00048 switch( nbComponents ) 00049 { 00050 case 1: 00051 setComponents( ePixelComponentAlpha ); 00052 break; 00053 case 3: 00054 setComponents( ePixelComponentRGB ); 00055 break; 00056 case 4: 00057 setComponents( ePixelComponentRGBA ); 00058 break; 00059 default: 00060 BOOST_THROW_EXCEPTION( exception::Value() 00061 << exception::dev() + "Unrecognized component size: " + nbComponents ); 00062 break; 00063 } 00064 } 00065 00066 void InputBufferWrapper::setSize( const int width, const int height ) 00067 { 00068 getNode().getParam( "size" ).setValue( width, height ); 00069 } 00070 00071 void InputBufferWrapper::setComponents( const EPixelComponent components ) 00072 { 00073 static std::map<EPixelComponent, const char*> toString = map_list_of 00074 ( ePixelComponentRGBA, "RGBA" ) 00075 ( ePixelComponentRGB, "RGB" ) 00076 ( ePixelComponentAlpha, "Gray" ); 00077 00078 getNode().getParam( "components" ).setValue( toString.find(components)->second ); 00079 } 00080 00081 void InputBufferWrapper::setBitDepth( const EBitDepth bitDepth ) 00082 { 00083 static std::map<EBitDepth, const char*> toString = map_list_of 00084 ( eBitDepthFloat, "Float" ) 00085 ( eBitDepthUShort, "UShort" ) 00086 ( eBitDepthUByte, "UByte" ); 00087 00088 getNode().getParam( "bitDepth" ).setValue( toString.find(bitDepth)->second ); 00089 } 00090 00091 void InputBufferWrapper::setRowDistanceSize( const int rowDistanceBytes ) 00092 { 00093 getNode().getParam( "rowBytesSize" ).setValue( rowDistanceBytes ); 00094 } 00095 00096 void InputBufferWrapper::setOrientation( const EImageOrientation orientation ) 00097 { 00098 static std::map<EImageOrientation, const char*> toString = map_list_of 00099 ( eImageOrientationFromBottomToTop, "bottomToTop" ) 00100 ( eImageOrientationFromTopToBottom, "topToBottom" ); 00101 00102 getNode().getParam( "orientation" ).setValue( toString.find(orientation)->second ); 00103 } 00104 00105 void InputBufferWrapper::setRawImageBuffer( 00106 void* rawBuffer, 00107 const int width, const int height, 00108 const EPixelComponent components, 00109 const EBitDepth bitDepth, 00110 const int rowDistanceBytes, 00111 const EImageOrientation orientation ) 00112 { 00113 setMode( eModeBuffer ); 00114 setBuffer( rawBuffer ); 00115 setSize( width, height ); 00116 setComponents( components ); 00117 setBitDepth( bitDepth ); 00118 setRowDistanceSize( rowDistanceBytes ); 00119 setOrientation( orientation ); 00120 00121 // _outputClip.setComponents( components ); 00122 // _outputClip.setBitDepth( bitDepth ); 00123 // _imageCache.reset( new attribute::Image( 00124 // _outputClip, 00125 // 0, // no time information 00126 // rod, 00127 // orientation, 00128 // rowDistanceBytes 00129 // ) ); 00130 // _imageCache->setPoolData( new memory::LinkData( rawBuffer ) ); 00131 } 00132 00133 00134 //void InputBufferWrapper::process( graph::ProcessVertexAtTimeData& vData ) 00135 //{ 00136 // core().getMemoryCache().put( _outputClip.getClipIdentifier(), vData._time, _imageCache ); 00137 // if( vData._outDegree > 0 ) 00138 // { 00139 // _imageCache->addReference( ofx::imageEffect::OfxhImage::eReferenceOwnerHost, vData._outDegree ); // add a reference on this getNode() for each future usages 00140 // } 00141 //} 00142 00143 00144 void InputBufferWrapper::setCallback( CallbackInputImagePtr callback, CustomDataPtr customData, CallbackDestroyCustomDataPtr destroyCustomData ) 00145 { 00146 getNode().getParam( "callbackPointer" ).setValue( 00147 boost::lexical_cast<std::string>( reinterpret_cast<std::ptrdiff_t>( callback ) ) 00148 ); 00149 getNode().getParam( "customData" ).setValue( 00150 boost::lexical_cast<std::string>( reinterpret_cast<std::ptrdiff_t>( customData ) ) 00151 ); 00152 getNode().getParam( "callbackDestroyCustomData" ).setValue( 00153 boost::lexical_cast<std::string>( reinterpret_cast<std::ptrdiff_t>( destroyCustomData ) ) 00154 ); 00155 } 00156 00157 } 00158 } 00159