[Hdrflow-svn] SF.net SVN: hdrflow: [280] trunk/lib/extras/src/imf/mfn
Status: Pre-Alpha
Brought to you by:
glslang
From: <gl...@us...> - 2007-08-27 15:50:15
|
Revision: 280 http://hdrflow.svn.sourceforge.net/hdrflow/?rev=280&view=rev Author: glslang Date: 2007-08-26 07:36:26 -0700 (Sun, 26 Aug 2007) Log Message: ----------- + maya 8.5 HDR plugin functional. needs testing Modified Paths: -------------- trunk/lib/extras/src/imf/mfn/Makefile.am trunk/lib/extras/src/imf/mfn/mfn.cpp Modified: trunk/lib/extras/src/imf/mfn/Makefile.am =================================================================== --- trunk/lib/extras/src/imf/mfn/Makefile.am 2007-08-26 14:14:16 UTC (rev 279) +++ trunk/lib/extras/src/imf/mfn/Makefile.am 2007-08-26 14:36:26 UTC (rev 280) @@ -19,7 +19,8 @@ libhdrflow_extras_mfn_la_LIBADD = \ $(MAYA_LIBS) \ - $(top_builddir)/../openlibraries/src/openpluginlib/pl/libopenpluginlib_pl.la + $(top_builddir)/../openlibraries/src/openpluginlib/pl/libopenpluginlib_pl.la \ + $(top_builddir)/../openlibraries/src/openimagelib/il/libopenimagelib_il.la libhdrflow_extras_mfn_la_LDFLAGS = \ $(MAYA_LDFLAGS) Modified: trunk/lib/extras/src/imf/mfn/mfn.cpp =================================================================== --- trunk/lib/extras/src/imf/mfn/mfn.cpp 2007-08-26 14:14:16 UTC (rev 279) +++ trunk/lib/extras/src/imf/mfn/mfn.cpp 2007-08-26 14:36:26 UTC (rev 280) @@ -5,6 +5,10 @@ // Released under the GPL. // For more information, see http://www.cryogenicgraphics.com/hdrflow. +#ifdef __APPLE__ +#include <maya/OpenMayaMac.h> +#endif + #include <maya/MPxImageFile.h> #include <maya/MImageFileInfo.h> #include <maya/MImage.h> @@ -13,3 +17,189 @@ #include <maya/MIOStream.h> #include <maya/MGlobal.h> +#include <openpluginlib/pl/openpluginlib.hpp> +#include <openpluginlib/pl/utf8_utils.hpp> +#include <openpluginlib/pl/stream.hpp> + +#include <openimagelib/il/openimagelib_plugin.hpp> + +namespace pl = olib::openpluginlib; +namespace il = olib::openimagelib::il; + +namespace hdrflow { namespace extras { namespace mfn { + +namespace +{ + struct query_traits + { + query_traits( const pl::wstring& filename ) + : filename_( filename ) + { } + + pl::wstring libname( ) const + { return L"openimagelib"; } + + pl::wstring to_match( ) const + { return filename_; } + + pl::wstring type( ) const + { return L""; } + + int merit( ) const + { return 0; } + + pl::wstring filename_; + }; +} + +class image_reader : public MPxImageFile +{ +public: + explicit image_reader( ); + virtual ~image_reader( ); + + static void* creator( ); + + virtual MStatus open( MString pathname, MImageFileInfo* info ); + virtual MStatus load( MImage& image, unsigned int idx ); + virtual MStatus close( ); + +private: + il::image_type_ptr im_; +}; + +image_reader::image_reader( ) +{ } + +image_reader::~image_reader( ) +{ } + +void* image_reader::creator( ) +{ + return new image_reader; +} + +MStatus image_reader::open( MString pathname, MImageFileInfo* info ) +{ +#ifndef NDEBUG + MGlobal::displayInfo( "HDRFlow: opening image..." ); +#endif + + typedef pl::discovery<query_traits> discovery; + + discovery plugins( query_traits( pl::to_wstring( pathname.asChar( ) ) ) ); + if( plugins.empty( ) ) return MS::kFailure; + + for( discovery::const_iterator i = plugins.begin( ); i != plugins.end( ); ++i ) + { + il::openimagelib_plugin_ptr plug = boost::shared_dynamic_cast<il::openimagelib_plugin>( i->create_plugin( "" ) ); + if( plug ) + { +#ifndef NDEBUG + MGlobal::displayInfo( "HDRFlow: plugin found ..." ); +#endif + im_ = il::conform( plug->load( pl::make_stream( pathname.asChar( ), std::ios::in ) ), il::flipped ); + if( im_ ) + { +#ifndef NDEBUG + MGlobal::displayInfo( "HDRFlow: image opened." ); +#endif + if( info ) + { + info->width( im_->width( ) ); + info->height( im_->height( ) ); + info->channels( 4 ); // always assumes alpha/matte exists + info->numberOfImages( 1 ); + info->pixelType( MImage::kFloat ); // convert everything to float by default + } + + return MS::kSuccess; + } +#ifndef NDEBUG + else + { + MGlobal::displayInfo( "HDRFlow: image is null." ); + } +#endif + } +#ifndef NDEBUG + else + { + MGlobal::displayInfo( "HDRFlow: plugin is null." ); + } +#endif + } + +#ifndef NDEBUG + MGlobal::displayInfo( "HDRFlow: failed to open." ); +#endif + + return MS::kFailure; +} + +MStatus image_reader::load( MImage& image, unsigned int idx ) +{ +#ifndef NDEBUG + MGlobal::displayInfo( "HDRFlow: loading image..." ); +#endif + + im_ = il::convert( im_, L"r32g32b32a32f" ); + if( !im_ ) return MS::kFailure; + + int width = im_->width( ); + int height = im_->height( ); + int pitch = im_->pitch( ); + int linesize = im_->linesize( ); + + image.create( im_->width( ), im_->height( ), 4, MImage::kFloat ); + + const float* src = reinterpret_cast<const float*>( im_->data( ) ); + float* dst = image.floatPixels( ); + + for( int i = 0; i < height; ++i ) + { + memcpy( dst, src, im_->linesize( ) * sizeof( float ) ); + + src += pitch; + dst += width * 4; + } + +#ifndef NDEBUG + MGlobal::displayInfo( "HDRFlow: image loaded." ); +#endif + + return MS::kSuccess; +} + +MStatus image_reader::close( ) +{ + im_.reset( ); + + return MS::kSuccess; +} + +} } } + +extern "C" MStatus initializePlugin( MObject obj ) +{ +#ifndef NDEBUG + MGlobal::displayInfo( "HDRFlow: initialising ..." ); +#endif + + MFnPlugin plugin( obj, "com.cryogenicgraphics", "8.0", "Any" ); + MStringArray extensions; + extensions.append( "hdr" ); + CHECK_MSTATUS( plugin.registerImageFile( "HDRFlow", hdrflow::extras::mfn::image_reader::creator, extensions ) ); + + pl::init( ); + + return MS::kSuccess; +} + +extern "C" MStatus uninitializePlugin( MObject obj ) +{ + MFnPlugin plugin( obj ); + CHECK_MSTATUS( plugin.deregisterImageFile( "HDRFlow" ) ); + + return MS::kSuccess; +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |