TuttleOFX
1
|
00001 #include <tuttle/host/Graph.hpp> 00002 00003 #include <boost/gil/gil_all.hpp> 00004 00005 #define int_p_NULL (int*)NULL 00006 00007 #include <boost/gil/extension/io/png_io.hpp> 00008 #include <boost/gil/image_view_factory.hpp> 00009 00010 #include <boost/lexical_cast.hpp> 00011 00012 00013 namespace { 00014 typedef void* CustomDataPtr; 00015 void callbackImagePointer( OfxTime time, CustomDataPtr customData, void** outRawdata, int* outWidth, int* outHeight, int* outRowSizeBytes ) 00016 { 00017 boost::gil::rgba8_image_t& imgRead = *(boost::gil::rgba8_image_t*)customData; 00018 boost::gil::png_read_and_convert_image( "in.png", imgRead ); 00019 boost::gil::rgba8_view_t imgView( view( imgRead ) ); 00020 00021 *outRawdata = boost::gil::interleaved_view_get_raw_data( imgView ); 00022 *outWidth = imgView.width(); 00023 *outHeight = imgView.height(); 00024 *outRowSizeBytes = imgView.pixels().row_size(); 00025 } 00026 } 00027 00028 00029 int main( int argc, char** argv ) 00030 { 00031 try 00032 { 00033 using namespace tuttle::host; 00034 00035 core().preload(); 00036 00037 boost::gil::rgba8_image_t imgRead; 00038 00039 Graph g; 00040 //Graph::Node& inputBuffer = g.createNode("tuttle.inputbuffer"); 00041 InputBufferWrapper inputBuffer = g.createInputBuffer(); 00042 Graph::Node& write1 = g.createNode( "tuttle.pngwriter" ); 00043 00044 if( false ) 00045 { 00046 // set image buffer 00047 boost::gil::png_read_and_convert_image( "in.png", imgRead ); 00048 boost::gil::rgba8_view_t imgView( view( imgRead ) ); 00049 inputBuffer.setRawImageBuffer( 00050 (void*)boost::gil::interleaved_view_get_raw_data( imgView ), 00051 imgView.width(), imgView.height(), 00052 InputBufferWrapper::ePixelComponentRGBA, 00053 InputBufferWrapper::eBitDepthUByte 00054 ); 00055 } 00056 else 00057 { 00058 // set callback 00059 inputBuffer.setComponents( InputBufferWrapper::ePixelComponentRGBA ); 00060 inputBuffer.setBitDepth( InputBufferWrapper::eBitDepthUByte ); 00061 inputBuffer.setCallback( callbackImagePointer, &imgRead ); 00062 } 00063 00064 write1.getParam( "filename" ).setValue( "out.png" ); 00065 00066 g.connect( inputBuffer.getNode(), write1 ); 00067 g.compute( write1 ); 00068 } 00069 catch( tuttle::exception::Common& e ) 00070 { 00071 std::cout << "Tuttle Exception" << std::endl; 00072 std::cerr << boost::diagnostic_information( e ); 00073 } 00074 catch(... ) 00075 { 00076 std::cerr << boost::current_exception_diagnostic_information(); 00077 00078 } 00079 00080 return 0; 00081 }