[Hdrflow-svn] SF.net SVN: hdrflow: [168] trunk/lib
Status: Pre-Alpha
Brought to you by:
glslang
From: <gl...@us...> - 2007-07-03 23:03:12
|
Revision: 168 http://hdrflow.svn.sourceforge.net/hdrflow/?rev=168&view=rev Author: glslang Date: 2007-07-03 16:02:52 -0700 (Tue, 03 Jul 2007) Log Message: ----------- + generic stream abstraction Modified Paths: -------------- trunk/lib/extras/src/raw/raw.cpp trunk/lib/openlibraries/installer/openlibraries_sdk.nsi trunk/lib/openlibraries/src/openassetlib/al/al.cpp trunk/lib/openlibraries/src/openimagelib/il/openimagelib_plugin.hpp trunk/lib/openlibraries/src/openimagelib/plugins/3D_lightmap/3D_lightmap_plugin.cpp trunk/lib/openlibraries/src/openimagelib/plugins/bmp/bmp_plugin.cpp trunk/lib/openlibraries/src/openimagelib/plugins/dds/dds_plugin.cpp trunk/lib/openlibraries/src/openimagelib/plugins/dpx/dpx_plugin.cpp trunk/lib/openlibraries/src/openimagelib/plugins/exr/exr_plugin.cpp trunk/lib/openlibraries/src/openimagelib/plugins/gdi+/gdi+_plugin.cpp trunk/lib/openlibraries/src/openimagelib/plugins/hdr/hdr_plugin.cpp trunk/lib/openlibraries/src/openimagelib/plugins/jpg/jpg_plugin.cpp trunk/lib/openlibraries/src/openimagelib/plugins/png/png_plugin.cpp trunk/lib/openlibraries/src/openimagelib/plugins/psd/psd_plugin.cpp trunk/lib/openlibraries/src/openimagelib/plugins/quicktime/quicktime_plugin.cpp trunk/lib/openlibraries/src/openimagelib/plugins/sgi/sgi_plugin.cpp trunk/lib/openlibraries/src/openimagelib/plugins/tga/tga_plugin.cpp trunk/lib/openlibraries/src/openimagelib/plugins/tiff/tiff_plugin.cpp trunk/lib/openlibraries/src/openimagelib/py/il.cpp trunk/lib/openlibraries/src/openmedialib/plugins/oil/oil_plugin.cpp trunk/lib/openlibraries/src/openobjectlib/sg/appearance.cpp trunk/lib/openlibraries/src/openpluginlib/pl/GL_utility.cpp trunk/lib/openlibraries/src/openpluginlib/pl/GL_utility.hpp trunk/lib/openlibraries/src/openpluginlib/pl/Makefile.am trunk/lib/openlibraries/src/openpluginlib/pl/stream.cpp trunk/lib/openlibraries/src/openpluginlib/pl/stream.hpp trunk/lib/openlibraries/test/openimagelib/GL/_2D/Makefile.am trunk/lib/openlibraries/test/openimagelib/GL/_2D/_2D.cpp trunk/lib/openlibraries/test/openimagelib/GL/_2D_compressed/Makefile.am trunk/lib/openlibraries/test/openimagelib/GL/_2D_compressed/_2D_compressed.cpp trunk/lib/openlibraries/test/openimagelib/GL/_2D_compressed_cubemap/Makefile.am trunk/lib/openlibraries/test/openimagelib/GL/_2D_compressed_cubemap/_2D_compressed_cubemap.cpp trunk/lib/openlibraries/test/openimagelib/GL/_2D_crop/Makefile.am trunk/lib/openlibraries/test/openimagelib/GL/_2D_crop/_2D_crop.cpp trunk/lib/openlibraries/test/openimagelib/GL/_2D_crop2/Makefile.am trunk/lib/openlibraries/test/openimagelib/GL/_2D_crop2/_2D_crop2.cpp trunk/lib/openlibraries/test/openimagelib/GL/_2D_exr/Makefile.am trunk/lib/openlibraries/test/openimagelib/GL/_2D_exr/_2D_exr.cpp trunk/lib/openlibraries/test/openimagelib/GL/_2D_sgi/Makefile.am trunk/lib/openlibraries/test/openimagelib/GL/_2D_sgi/_2D_sgi.cpp Modified: trunk/lib/extras/src/raw/raw.cpp =================================================================== --- trunk/lib/extras/src/raw/raw.cpp 2007-06-30 16:50:29 UTC (rev 167) +++ trunk/lib/extras/src/raw/raw.cpp 2007-07-03 23:02:52 UTC (rev 168) @@ -11,11 +11,10 @@ #include <windows.h> #endif -#include <openmedialib/ml/openmedialib_plugin.hpp> +#include <openmedialib/il/openimagelib_plugin.hpp> namespace pl = olib::openpluginlib; namespace il = olib::openimagelib::il; -namespace ml = olib::openmedialib::ml; namespace fs = boost::filesystem; namespace pcos = olib::openpluginlib::pcos; @@ -23,12 +22,16 @@ namespace { + bool dcraw( property_container properties ) + { + return true; + } } -class raw_input : public ml::input_type +class raw_plugin : public il::openimagelib_plugin { public: - explicit raw_input( const pl::wstring& resource ) + explicit raw_plugin( ) : verbose_( pcos::key::from_string( "verbose" ) ) , thumbnail_( pcos::key::from_string( "thumbnail" ) ) , camera_white_balance_( pcos::key::from_string( "camera_white_balance" ) ) @@ -51,6 +54,12 @@ , tiff_output_( pcos::key::from_string( "tiff_output" ) ) { } + virtual il::image_type_ptr load( const fs::path& path ) + { return il::image_type_ptr( ); } + + virtual bool store( const fs::path&, const il::image_type_ptr& ) + { return false; } + private: pcos::property verbose_; pcos::property thumbnail_; @@ -74,13 +83,6 @@ pcos::property tiff_output_; }; -class raw_plugin : public ml::openmedialib_plugin -{ -public: - explicit raw_plugin( ) - { } -}; - } } } extern "C" Modified: trunk/lib/openlibraries/installer/openlibraries_sdk.nsi =================================================================== --- trunk/lib/openlibraries/installer/openlibraries_sdk.nsi 2007-06-30 16:50:29 UTC (rev 167) +++ trunk/lib/openlibraries/installer/openlibraries_sdk.nsi 2007-07-03 23:02:52 UTC (rev 168) @@ -101,6 +101,7 @@ File ..\src\openpluginlib\pl\shader_manager.hpp File ..\src\openpluginlib\pl\simplestringstorage.h File ..\src\openpluginlib\pl\smallstringopt.h + File ..\src\openpluginlib\pl\stream.hpp File ..\src\openpluginlib\pl\string.hpp File ..\src\openpluginlib\pl\timer.hpp File ..\src\openpluginlib\pl\utf8_utils.hpp Modified: trunk/lib/openlibraries/src/openassetlib/al/al.cpp =================================================================== --- trunk/lib/openlibraries/src/openassetlib/al/al.cpp 2007-06-30 16:50:29 UTC (rev 167) +++ trunk/lib/openlibraries/src/openassetlib/al/al.cpp 2007-07-03 23:02:52 UTC (rev 168) @@ -630,7 +630,7 @@ if(!plugin) continue; - oil::il::image_type_ptr image = boost::shared_dynamic_cast<oil::il::openimagelib_plugin>(plugin)->load(fs::path( filepath.c_str( ), fs::native )); + oil::il::image_type_ptr image = boost::shared_dynamic_cast<oil::il::openimagelib_plugin>(plugin)->load( opl::make_stream( filepath, std::ios::in )); if(image) { asset->set("width", image->width()); Modified: trunk/lib/openlibraries/src/openimagelib/il/openimagelib_plugin.hpp =================================================================== --- trunk/lib/openlibraries/src/openimagelib/il/openimagelib_plugin.hpp 2007-06-30 16:50:29 UTC (rev 167) +++ trunk/lib/openlibraries/src/openimagelib/il/openimagelib_plugin.hpp 2007-07-03 23:02:52 UTC (rev 168) @@ -10,16 +10,17 @@ #include <boost/filesystem/path.hpp> +#include <openpluginlib/pl/openpluginlib.hpp> +#include <openpluginlib/pl/stream.hpp> + #include <openimagelib/il/il.hpp> -#include <openpluginlib/pl/openpluginlib.hpp> - namespace olib { namespace openimagelib { namespace il { struct IL_DECLSPEC openimagelib_plugin : public olib::openpluginlib::openplugin { - virtual image_type_ptr load( const boost::filesystem::path& path ) = 0; - virtual bool store( const boost::filesystem::path& path, const image_type_ptr& image ) = 0; + virtual image_type_ptr load( openpluginlib::stream_ptr stream ) = 0; + virtual bool store( openpluginlib::stream_ptr stream, const image_type_ptr& image ) = 0; }; typedef boost::shared_ptr<openimagelib_plugin> openimagelib_plugin_ptr; Modified: trunk/lib/openlibraries/src/openimagelib/plugins/3D_lightmap/3D_lightmap_plugin.cpp =================================================================== --- trunk/lib/openlibraries/src/openimagelib/plugins/3D_lightmap/3D_lightmap_plugin.cpp 2007-06-30 16:50:29 UTC (rev 167) +++ trunk/lib/openlibraries/src/openimagelib/plugins/3D_lightmap/3D_lightmap_plugin.cpp 2007-07-03 23:02:52 UTC (rev 168) @@ -10,7 +10,6 @@ #include <openimagelib/il/openimagelib_plugin.hpp> -namespace fs = boost::filesystem; namespace il = olib::openimagelib::il; namespace pl = olib::openpluginlib; @@ -21,6 +20,7 @@ void destroy( il::image_type* im ) { delete im; } +/* bool discover_lightmap_size( const boost::filesystem::path& path, int& radius ) { typedef boost::tokenizer< boost::char_separator<char> > tokenizer; @@ -81,15 +81,16 @@ return im; } +*/ } class lightmap3D_plugin : public il::openimagelib_plugin { public: - virtual il::image_type_ptr load( const boost::filesystem::path& path ) - { return generate_lightmap( path ); } + virtual il::image_type_ptr load( pl::stream_ptr stream ) + { return il::image_type_ptr( ); } - virtual bool store( const boost::filesystem::path&, const il::image_type_ptr& ) + virtual bool store( pl::stream_ptr stream, const il::image_type_ptr& ) { return false; } }; Modified: trunk/lib/openlibraries/src/openimagelib/plugins/bmp/bmp_plugin.cpp =================================================================== --- trunk/lib/openlibraries/src/openimagelib/plugins/bmp/bmp_plugin.cpp 2007-06-30 16:50:29 UTC (rev 167) +++ trunk/lib/openlibraries/src/openimagelib/plugins/bmp/bmp_plugin.cpp 2007-07-03 23:02:52 UTC (rev 168) @@ -8,7 +8,6 @@ #include <openimagelib/il/openimagelib_plugin.hpp> namespace il = olib::openimagelib::il; -namespace fs = boost::filesystem; namespace pl = olib::openpluginlib; namespace olib { namespace openimagelib { namespace il { @@ -19,10 +18,10 @@ struct bmp_plugin : public il::openimagelib_plugin { - virtual il::image_type_ptr load( const boost::filesystem::path& ) + virtual il::image_type_ptr load( pl::stream_ptr ) { return il::image_type_ptr( ); } - virtual bool store( const boost::filesystem::path&, const il::image_type_ptr& ) + virtual bool store( pl::stream_ptr, const il::image_type_ptr& ) { return false; } }; Modified: trunk/lib/openlibraries/src/openimagelib/plugins/dds/dds_plugin.cpp =================================================================== --- trunk/lib/openlibraries/src/openimagelib/plugins/dds/dds_plugin.cpp 2007-06-30 16:50:29 UTC (rev 167) +++ trunk/lib/openlibraries/src/openimagelib/plugins/dds/dds_plugin.cpp 2007-07-03 23:02:52 UTC (rev 168) @@ -6,16 +6,12 @@ // For more information, see http://www.openlibraries.org. #include <cstdlib> -#include <iostream> #include <vector> #include <string> -#include <boost/filesystem/fstream.hpp> - #include <openimagelib/il/openimagelib_plugin.hpp> namespace il = olib::openimagelib::il; -namespace fs = boost::filesystem; namespace pl = olib::openpluginlib; namespace olib { namespace openimagelib { namespace il { @@ -96,17 +92,6 @@ bool is_dds_header( const std::string& magic ) { return magic == std::string( "DDS " ); } - bool Read_s( fs::ifstream& file, char* s, std::streamsize size, std::streamsize max ) - { -#if _MSC_VER >= 1400 - file._Read_s( s, size, max ); -#else - file.read( s, size ); -#endif // _MSC_VER >= 1400 - - return !file.fail( ); - } - il::image_type_ptr ddsd_pixelformat_to_image_type( DDSURFACEDESC2 ddsd ) { # ifndef MAKEFOURCC @@ -186,21 +171,20 @@ #undef DDSCAPS2_CUBEMAP } - il::image_type_ptr load_dds( const fs::path& path ) + il::image_type_ptr load_dds( pl::stream_ptr stream ) { - typedef il::image_type::size_type size_type; + typedef il::image_type::size_type size_type; - fs::ifstream file( path, std::ios::in | std::ios::binary ); - if( !file.is_open( ) ) + if( stream->is_null( ) ) return il::image_type_ptr( ); char magic[ 4 ]; - Read_s( file, magic, 4, 4 ); + stream->read( magic, 4 ); if( !is_dds_header( std::string( magic, 4 ) ) ) return il::image_type_ptr( ); DDSURFACEDESC2 ddsd; - Read_s( file, reinterpret_cast<char*>( &ddsd ), sizeof( DDSURFACEDESC2 ), 124 ); + stream->read( reinterpret_cast<char*>( &ddsd ), sizeof( DDSURFACEDESC2 ) ); #ifdef __BIG_ENDIAN__ swap_surface_desc( ddsd ); @@ -210,7 +194,7 @@ if( !im ) return il::image_type_ptr( ); - Read_s( file, reinterpret_cast<char*>( im->data( ) ), std::streamsize( im->size( ) ), std::streamsize( im->size( ) ) ); + stream->read( reinterpret_cast<char*>( im->data( ) ), std::streamsize( im->size( ) ) ); return im; } @@ -218,10 +202,10 @@ struct dds_plugin : public il::openimagelib_plugin { - virtual il::image_type_ptr load( const boost::filesystem::path& path ) - { return load_dds( path ); } + virtual il::image_type_ptr load( pl::stream_ptr stream ) + { return load_dds( stream ); } - virtual bool store( const boost::filesystem::path&, const il::image_type_ptr& ) + virtual bool store( pl::stream_ptr, const il::image_type_ptr& ) { return false; } }; Modified: trunk/lib/openlibraries/src/openimagelib/plugins/dpx/dpx_plugin.cpp =================================================================== --- trunk/lib/openlibraries/src/openimagelib/plugins/dpx/dpx_plugin.cpp 2007-06-30 16:50:29 UTC (rev 167) +++ trunk/lib/openlibraries/src/openimagelib/plugins/dpx/dpx_plugin.cpp 2007-07-03 23:02:52 UTC (rev 168) @@ -7,12 +7,9 @@ #include <sstream> -#include <boost/filesystem/fstream.hpp> - #include <openimagelib/il/openimagelib_plugin.hpp> namespace il = olib::openimagelib::il; -namespace fs = boost::filesystem; namespace pl = olib::openpluginlib; namespace olib { namespace openimagelib { namespace il { @@ -342,22 +339,6 @@ return 0; } - bool Read_s( fs::ifstream& file, char* s, std::streamsize size, std::streamsize max ) - { -#if _MSC_VER >= 1400 - file._Read_s( s, size, max ); -#else - file.read( s, size ); -#endif - - return !file.fail( ); - } - - bool Write_s( fs::ofstream& file, char* s, std::streamsize size ) - { - return !file.write( s, size ).fail( ); - } - std::wstring generate_image_pf( const image_information_header& im_header ) { std::wostringstream str; @@ -590,33 +571,32 @@ } } - il::image_type_ptr load_dpx( const fs::path& path ) + il::image_type_ptr load_dpx( pl::stream_ptr stream ) { - fs::ifstream file( path, std::ios::in | std::ios::binary ); - if( !file.is_open( ) ) + if( stream->is_null( ) ) return il::image_type_ptr( ); file_information_header header; - if( !Read_s( file, ( char* ) &header, sizeof( header ), sizeof( header ) ) ) + if( !stream->read( ( char* ) &header, sizeof( header ) ) ) return il::image_type_ptr( ); if( header.magic != 0x58504453 && header.magic != 0x53445058 ) return il::image_type_ptr( ); image_information_header image_info_header; - if( !Read_s( file, ( char* ) &image_info_header, sizeof( image_info_header ), sizeof( image_info_header ) ) ) + if( !stream->read( ( char* ) &image_info_header, sizeof( image_info_header ) ) ) return il::image_type_ptr( ); image_orientation_information_header image_orientation_info_header; - if( !Read_s( file, ( char* ) &image_orientation_info_header, sizeof( image_orientation_info_header ), sizeof( image_orientation_info_header ) ) ) + if( !stream->read( ( char* ) &image_orientation_info_header, sizeof( image_orientation_info_header ) ) ) return il::image_type_ptr( ); motion_picture_film_information_header motion_info_header; - if( !Read_s( file, ( char* ) &motion_info_header, sizeof( motion_info_header ), sizeof( motion_info_header ) ) ) + if( !stream->read( ( char* ) &motion_info_header, sizeof( motion_info_header ) ) ) return il::image_type_ptr( ); television_information_header tv_info_header; - if( !Read_s( file, ( char* ) &tv_info_header, sizeof( tv_info_header ), sizeof( tv_info_header ) ) ) + if( !stream->read( ( char* ) &tv_info_header, sizeof( tv_info_header ) ) ) return il::image_type_ptr( ); bool swab = header.magic == 0x58504453 ? true : false; @@ -638,7 +618,7 @@ for( int i = 0; i < image_info_header.image_elements; ++i ) { - file.rdbuf( )->pubseekoff( image_info_header.element[ i ].offset, std::ios::beg ); + stream->seek( image_info_header.element[ i ].offset, std::ios::beg ); int bitdepth = image_info_header.element[ i ].bitdepth; int packing = image_info_header.element[ i ].packing; @@ -654,7 +634,7 @@ for( unsigned int j = 0; j < image_info_header.lines_per_element; ++j ) { - Read_s( file, reinterpret_cast<char*>( &data[ 0 ] ), linesize, linesize ); + stream->read( reinterpret_cast<char*>( &data[ 0 ] ), linesize ); data += im->pitch( i ); } } @@ -665,7 +645,7 @@ std::vector<unsigned char> image_data( linesize ); for( unsigned int j = 0; j < image_info_header.lines_per_element; ++j ) { - Read_s( file, reinterpret_cast<char*>( &image_data[ 0 ] ), linesize, linesize ); + stream->read( reinterpret_cast<char*>( &image_data[ 0 ] ), linesize ); memcpy( &data[ 0 ], &image_data[ 0 ], linesize ); data += im->pitch( i ); } @@ -680,7 +660,7 @@ else if( bitdepth == 10 || ( bitdepth == 12 || !packing ) ) { std::vector<unsigned char> image_data( linesize * image_info_header.lines_per_element ); - Read_s( file, reinterpret_cast<char*>( &image_data[ 0 ] ), linesize * image_info_header.lines_per_element, linesize * image_info_header.lines_per_element ); + stream->read( reinterpret_cast<char*>( &image_data[ 0 ] ), linesize * image_info_header.lines_per_element ); if( packing == 0 ) { @@ -757,10 +737,9 @@ return false; } - bool store_dpx( const fs::path& path, const il::image_type_ptr& im ) + bool store_dpx( pl::stream_ptr stream, const il::image_type_ptr& im ) { - fs::ofstream file( path, std::ios::out | std::ios::binary ); - if( !file.is_open( ) ) return false; + if( stream->is_null( ) ) return false; il::image_type::size_type width = im->width( ); il::image_type::size_type height = im->height( ); @@ -817,12 +796,12 @@ user_defined_data_header user_defined_header; memset( &user_defined_header, 0, sizeof( user_defined_header ) ); - if( !( Write_s( file, ( char* ) &header, sizeof( header ) ) && - Write_s( file, ( char* ) &image_info_header, sizeof( image_info_header ) ) && - Write_s( file, ( char* ) &image_orientation_info_header, sizeof( image_orientation_info_header ) ) && - Write_s( file, ( char* ) &motion_info_header, sizeof( motion_info_header ) ) && - Write_s( file, ( char* ) &tv_info_header, sizeof( tv_info_header ) ) && - Write_s( file, ( char* ) &user_defined_header, sizeof( user_defined_header ) ) ) ) + if( !( stream->write( ( char* ) &header, sizeof( header ) ) && + stream->write( ( char* ) &image_info_header, sizeof( image_info_header ) ) && + stream->write( ( char* ) &image_orientation_info_header, sizeof( image_orientation_info_header ) ) && + stream->write( ( char* ) &motion_info_header, sizeof( motion_info_header ) ) && + stream->write( ( char* ) &tv_info_header, sizeof( tv_info_header ) ) && + stream->write( ( char* ) &user_defined_header, sizeof( user_defined_header ) ) ) ) return false; for( int i = 0; i < image_info_header.image_elements; ++i ) @@ -832,7 +811,7 @@ il::image_type::const_pointer data = im->data( i ); for( int j = 0; j < height; ++j ) { - if( !Write_s( file, ( char* ) data, im->pitch( i ) ) ) + if( !stream->write( ( char* ) data, im->pitch( i ) ) ) return false; data += im->pitch( i ); @@ -843,7 +822,7 @@ unsigned short* data = ( unsigned short* ) im->data( i ); for( int j = 0; j < height; ++j ) { - if( !Write_s( file, ( char* ) data, im->linesize( i ) * sizeof( unsigned short ) ) ) + if( !stream->write( ( char* ) data, im->linesize( i ) * sizeof( unsigned short ) ) ) return false; data += im->pitch( i ); @@ -857,11 +836,11 @@ struct dpx_plugin : public il::openimagelib_plugin { - virtual il::image_type_ptr load( const boost::filesystem::path& path ) - { return load_dpx( path ); } + virtual il::image_type_ptr load( pl::stream_ptr stream ) + { return load_dpx( stream ); } - virtual bool store( const boost::filesystem::path& path, const il::image_type_ptr& im ) - { return store_dpx( path, im ); } + virtual bool store( pl::stream_ptr stream, const il::image_type_ptr& im ) + { return store_dpx( stream, im ); } }; } } } Modified: trunk/lib/openlibraries/src/openimagelib/plugins/exr/exr_plugin.cpp =================================================================== --- trunk/lib/openlibraries/src/openimagelib/plugins/exr/exr_plugin.cpp 2007-06-30 16:50:29 UTC (rev 167) +++ trunk/lib/openlibraries/src/openimagelib/plugins/exr/exr_plugin.cpp 2007-07-03 23:02:52 UTC (rev 168) @@ -11,7 +11,6 @@ #include <openimagelib/il/openimagelib_plugin.hpp> -namespace fs = boost::filesystem; namespace il = olib::openimagelib::il; namespace pl = olib::openpluginlib; @@ -22,9 +21,9 @@ void destroy( il::image_type* im ) { delete im; } - il::image_type_ptr load_exr( const fs::path& path ) + il::image_type_ptr load_exr( pl::stream_ptr stream ) { - Imf::RgbaInputFile file( path.native_file_string( ).c_str( ) ); + Imf::RgbaInputFile file( stream->path( ).c_str( ) ); Imath::Box2i dw = file.header( ).dataWindow( ); int width = dw.max.x - dw.min.x + 1; @@ -59,10 +58,10 @@ struct exr_plugin : public il::openimagelib_plugin { - virtual il::image_type_ptr load( const fs::path& path ) - { return load_exr( path ); } + virtual il::image_type_ptr load( pl::stream_ptr stream ) + { return load_exr( stream ); } - virtual bool store( const fs::path&, const il::image_type_ptr& ) + virtual bool store( pl::stream_ptr, const il::image_type_ptr& ) { return false; } }; Modified: trunk/lib/openlibraries/src/openimagelib/plugins/gdi+/gdi+_plugin.cpp =================================================================== --- trunk/lib/openlibraries/src/openimagelib/plugins/gdi+/gdi+_plugin.cpp 2007-06-30 16:50:29 UTC (rev 167) +++ trunk/lib/openlibraries/src/openimagelib/plugins/gdi+/gdi+_plugin.cpp 2007-07-03 23:02:52 UTC (rev 168) @@ -20,7 +20,6 @@ #include <openimagelib/il/openimagelib_plugin.hpp> namespace il = olib::openimagelib::il; -namespace fs = boost::filesystem; namespace pl = olib::openpluginlib; namespace olib { namespace openimagelib { namespace il { @@ -80,9 +79,9 @@ } } - il::image_type_ptr load_image( const fs::path& path ) + il::image_type_ptr load_image( pl::stream_ptr stream ) { - Gdiplus::Bitmap bitmap( ( pl::to_wstring( path.native_directory_string( ) ) ).c_str( ) ); + Gdiplus::Bitmap bitmap( ( pl::to_wstring( stream->path( ) ) ).c_str( ) ); Gdiplus::BitmapData bitmapData; Gdiplus::Rect rect( 0, 0, bitmap.GetWidth( ), bitmap.GetHeight( ) ); @@ -113,7 +112,7 @@ bitmap.UnlockBits( &bitmapData ); - return il::image_type_ptr( image ); + return image; } /* bool store_png( const fs::path& path, const image_type_ptr& image ) @@ -148,10 +147,10 @@ class gdi_plugin : public il::openimagelib_plugin { public: - virtual il::image_type_ptr load( const fs::path& path ) - { return load_image( path ); } + virtual il::image_type_ptr load( pl::stream_ptr stream ) + { return load_image( stream ); } - virtual bool store( const fs::path&, const il::image_type_ptr& ) + virtual bool store( pl::stream_ptr, const il::image_type_ptr& ) { return false; } }; Modified: trunk/lib/openlibraries/src/openimagelib/plugins/hdr/hdr_plugin.cpp =================================================================== --- trunk/lib/openlibraries/src/openimagelib/plugins/hdr/hdr_plugin.cpp 2007-06-30 16:50:29 UTC (rev 167) +++ trunk/lib/openlibraries/src/openimagelib/plugins/hdr/hdr_plugin.cpp 2007-07-03 23:02:52 UTC (rev 168) @@ -12,13 +12,11 @@ #include <cmath> #include <limits> #include <vector> +#include <sstream> -#include <boost/filesystem/fstream.hpp> - #include <openimagelib/il/openimagelib_plugin.hpp> namespace il = olib::openimagelib::il; -namespace fs = boost::filesystem; namespace pl = olib::openpluginlib; namespace olib { namespace openimagelib { namespace il { @@ -38,23 +36,12 @@ char format[ 16 ]; }; - bool Read_s( fs::ifstream& file, char* s, std::streamsize size, std::streamsize max ) + bool read_rgbe_pixels_raw( pl::stream_ptr stream, unsigned char* data, int width, int height ) { -#if _MSC_VER >= 1400 - file._Read_s( s, size, max ); -#else - file.read( s, size ); -#endif - - return !file.fail( ); - } - - bool read_rgbe_pixels_raw( fs::ifstream& file, unsigned char* data, int width, int height ) - { int numpixels = width * height; while( numpixels-- ) { - if( !Read_s( file, ( char* ) data, 4, 4 ) ) + if( !stream->read( ( char* ) data, 4 ) ) return false; data += 4; @@ -63,12 +50,12 @@ return true; } - bool read_rgbe_pixels( fs::ifstream& file, il::image_type_ptr im, int width, int height ) + bool read_rgbe_pixels( pl::stream_ptr stream, il::image_type_ptr im, int width, int height ) { il::image_type::pointer data = im->data( ); if( width < 8 || width > 0x7FFF ) - return read_rgbe_pixels_raw( file, data, width, height ); + return read_rgbe_pixels_raw( stream, data, width, height ); std::vector<unsigned char> line; line.resize( width * 4 * 4 ); @@ -76,7 +63,7 @@ unsigned char rgbe[ 4 ]; for( int i = 0; i < height; ++i ) { - if( !Read_s( file, ( char* ) rgbe, sizeof( rgbe ), sizeof( rgbe ) ) ) + if( !stream->read( ( char* ) rgbe, sizeof( rgbe ) ) ) return false; if( ( rgbe[ 0 ] != 2 ) || ( rgbe[ 1 ] != 2 ) || ( rgbe[ 2 ] & 0x80 ) ) @@ -88,7 +75,7 @@ data += 4; - return read_rgbe_pixels_raw( file, data, width, height ); + return read_rgbe_pixels_raw( stream, data, width, height ); } if( ( ( ( int ) rgbe[ 2 ] ) << 8 | rgbe[ 3 ] ) != width ) @@ -106,7 +93,7 @@ while( I < J ) { unsigned char buf[ 2 ]; - if( !Read_s( file, ( char* ) buf, 2, 2 ) ) + if( !stream->read( ( char* ) buf, 2 ) ) return false; if( buf[ 0 ] > 128 ) @@ -126,7 +113,7 @@ *I++ = buf[ 1 ]; if( --count > 0 ) { - if( !Read_s( file, ( char* ) I, count, count ) ) + if( !stream->read( ( char* ) I, count ) ) return false; } @@ -151,7 +138,7 @@ return true; } - bool read_hdr_header( fs::ifstream& file, RgbeInfo& info, int& width, int& height ) + bool read_hdr_header( pl::stream_ptr stream, RgbeInfo& info, int& width, int& height ) { info.valid = 0; memset( info.program_type, 0, sizeof( info.program_type ) ); @@ -161,8 +148,7 @@ char buffer[ 128 ]; - file.getline( buffer, 128 ); - if( file.fail( ) ) + if( !stream->getline( buffer, 128 ) ) return false; if( buffer[ 0 ] != '#' || buffer[ 1 ] != '?' ) @@ -177,8 +163,7 @@ info.program_type[ i ] = buffer[ i + 2 ]; } - file.getline( buffer, 128 ); - if( file.fail( ) ) + if( !stream->getline( buffer, 128 ) ) return false; for( ;; ) @@ -208,13 +193,12 @@ info.valid |= RGBE_VALID_EXPOSURE; } - file.getline( buffer, 128 ); + stream->getline( buffer, 128 ); if( !strlen( buffer ) ) break; } - file.getline( buffer, 128 ); - if( file.fail( ) ) + if( !stream->getline( buffer, 128 ) ) return false; #if _MSC_VER >= 1400 @@ -227,32 +211,30 @@ return true; } - il::image_type_ptr load_hdr( const fs::path& path ) + il::image_type_ptr load_hdr( pl::stream_ptr stream ) { - fs::ifstream file( path, std::ios::in | std::ios::binary ); - if( !file.is_open( ) ) + if( stream->is_null( ) ) return il::image_type_ptr( ); int width, height; RgbeInfo rgbe_info; - if( !read_hdr_header( file, rgbe_info, width, height ) ) + if( !read_hdr_header( stream, rgbe_info, width, height ) ) return il::image_type_ptr( ); il::image_type_ptr image = il::allocate( L"rgbe", width, height ); if( !image ) return il::image_type_ptr( ); - if( !read_rgbe_pixels( file, image, width, height ) ) + if( !read_rgbe_pixels( stream, image, width, height ) ) return il::image_type_ptr( ); return image; } - bool store_hdr( const fs::path& path, const il::image_type_ptr& im ) + bool store_hdr( pl::stream_ptr stream, const il::image_type_ptr& im ) { - fs::ofstream file( path, std::ios::out | std::ios::binary ); - if( !file.is_open( ) ) + if( stream->is_null( ) ) return false; il::image_type_ptr dst = il::convert( im, L"rgbe" ); @@ -262,15 +244,20 @@ il::image_type::size_type height = dst->height( ); // write header. - file << "#?RGBE\nGAMMA=1.0\nEXPOSURE=1.0\nFORMAT=32-bit_rle_rgbe\n\n"; - file << "-Y " << height << "+X " << width << "\n"; + std::ostringstream buf; + buf << "#?RGBE\nGAMMA=1.0\nEXPOSURE=1.0\nFORMAT=32-bit_rle_rgbe\n\n"; + stream->write( buf.str( ).c_str( ), buf.str( ).size( ) ); + buf.clear( ); + buf << "-Y " << height << "+X " << width << "\n"; + stream->write( buf.str( ).c_str( ), buf.str( ).size( ) ); + il::image_type::const_pointer data = dst->data( ); il::image_type::size_type pitch = dst->pitch( ); while( height-- ) { - file.write( ( char* ) data, dst->linesize( ) ); + stream->write( ( char* ) data, dst->linesize( ) ); data += pitch; } } @@ -281,11 +268,11 @@ struct hdr_plugin : public il::openimagelib_plugin { - virtual il::image_type_ptr load( const boost::filesystem::path& path ) - { return load_hdr( path ); } + virtual il::image_type_ptr load( pl::stream_ptr stream ) + { return load_hdr( stream ); } - virtual bool store( const boost::filesystem::path& path, const il::image_type_ptr& im ) - { return store_hdr( path, im ); } + virtual bool store( pl::stream_ptr stream, const il::image_type_ptr& im ) + { return store_hdr( stream, im ); } }; } } } Modified: trunk/lib/openlibraries/src/openimagelib/plugins/jpg/jpg_plugin.cpp =================================================================== --- trunk/lib/openlibraries/src/openimagelib/plugins/jpg/jpg_plugin.cpp 2007-06-30 16:50:29 UTC (rev 167) +++ trunk/lib/openlibraries/src/openimagelib/plugins/jpg/jpg_plugin.cpp 2007-07-03 23:02:52 UTC (rev 168) @@ -15,7 +15,7 @@ #include <openimagelib/il/openimagelib_plugin.hpp> -extern "C" { +extern "C" { #include <jpeglib.h> } @@ -25,24 +25,126 @@ #endif namespace il = olib::openimagelib::il; -namespace fs = boost::filesystem; namespace pl = olib::openpluginlib; namespace olib { namespace openimagelib { namespace il { namespace { - FILE* Fopen_s( const pl::string& path, const char* mode ) + struct olib_jpeg_source_mgr { -#if _MSC_VER >= 1400 - FILE* file; - fopen_s( &file, path.c_str( ), mode ); - return file; -#else - return fopen( path.c_str( ), mode ); -#endif + struct jpeg_source_mgr pub; + + pl::stream_ptr stream; + JOCTET* buffer; + boolean start_of_file; + }; + + typedef olib_jpeg_source_mgr* olib_jpeg_source_mgr_ptr; + + extern "C" void init_source( j_decompress_ptr cinfo ) + { + olib_jpeg_source_mgr_ptr src = ( olib_jpeg_source_mgr_ptr ) cinfo->src; + src->start_of_file = TRUE; } + + extern "C" boolean fill_input_buffer( j_decompress_ptr cinfo ) + { + olib_jpeg_source_mgr_ptr src = ( olib_jpeg_source_mgr_ptr ) cinfo->src; + + src->pub.next_input_byte = ( JOCTET* ) src->stream->data( ); + src->pub.bytes_in_buffer = src->stream->max_size( ); + src->start_of_file = FALSE; + + return TRUE; + } + + extern "C" void skip_input_data( j_decompress_ptr cinfo, long num_bytes ) + { + olib_jpeg_source_mgr_ptr src = ( olib_jpeg_source_mgr_ptr ) cinfo->src; + + src->pub.next_input_byte += static_cast<std::size_t>( num_bytes ); + src->pub.bytes_in_buffer -= static_cast<std::size_t>( num_bytes ); + } + + extern "C" void term_source( j_decompress_ptr ) + { + } + void jpeg_oil_stream_src( j_decompress_ptr cinfo, pl::stream_ptr stream ) + { + olib_jpeg_source_mgr_ptr src = 0; + + if( cinfo->src == NULL ) + { + cinfo->src = ( jpeg_source_mgr* ) ( *cinfo->mem->alloc_small )( ( j_common_ptr ) cinfo, JPOOL_PERMANENT, sizeof( olib_jpeg_source_mgr ) ); + memset( cinfo->src, 0, sizeof( olib_jpeg_source_mgr ) ); + } + + src = ( olib_jpeg_source_mgr_ptr ) cinfo->src; + src->stream = stream; + src->buffer = ( JOCTET* ) stream->data( ); + src->pub.init_source = init_source; + src->pub.fill_input_buffer = fill_input_buffer; + src->pub.skip_input_data = skip_input_data; + src->pub.resync_to_restart = jpeg_resync_to_restart; + src->pub.term_source = term_source; + src->pub.bytes_in_buffer = 0; + src->pub.next_input_byte = NULL; + } + + struct olib_jpeg_destination_mgr + { + struct jpeg_destination_mgr pub; + + pl::stream_ptr stream; + JOCTET* buffer; + }; + + typedef olib_jpeg_destination_mgr* olib_jpeg_destination_mgr_ptr; + + extern "C" void init_destination( j_compress_ptr cinfo ) + { + olib_jpeg_destination_mgr_ptr dest = ( olib_jpeg_destination_mgr_ptr ) cinfo->dest; + + dest->buffer = ( JOCTET* ) ( *cinfo->mem->alloc_small )( ( j_common_ptr ) cinfo, JPOOL_IMAGE, dest->stream->max_size( ) ); + dest->pub.next_output_byte = dest->buffer; + dest->pub.free_in_buffer = dest->stream->max_size( ); + } + + extern "C" boolean empty_output_buffer( j_compress_ptr cinfo ) + { + olib_jpeg_destination_mgr_ptr dest = ( olib_jpeg_destination_mgr_ptr ) cinfo->dest; + + dest->stream->write( ( pl::stream::const_pointer ) dest->buffer, dest->pub.free_in_buffer ); + + dest->pub.next_output_byte = dest->buffer; + dest->pub.free_in_buffer = dest->stream->max_size( ); + + return TRUE; + } + + extern "C" void term_destination( j_compress_ptr ) + { + } + + void jpeg_oil_stream_dest( j_compress_ptr cinfo, pl::stream_ptr stream ) + { + olib_jpeg_destination_mgr_ptr dest = 0; + + if( cinfo->dest == NULL ) + { + cinfo->dest = ( jpeg_destination_mgr* ) ( *cinfo->mem->alloc_small )( ( j_common_ptr ) cinfo, JPOOL_PERMANENT, sizeof( olib_jpeg_destination_mgr ) ); + memset( cinfo->dest, 0, sizeof( olib_jpeg_destination_mgr ) ); + } + + dest = ( olib_jpeg_destination_mgr_ptr ) cinfo->dest; + dest->pub.init_destination = init_destination; + dest->pub.empty_output_buffer = empty_output_buffer; + dest->pub.term_destination = term_destination; + dest->stream = stream; + } + void destroy( il::image_type* im ) { delete im; } @@ -84,10 +186,9 @@ } #endif - il::image_type_ptr load_jpg( const boost::filesystem::path& path ) + il::image_type_ptr load_jpg( pl::stream_ptr stream ) { - FILE* infile = Fopen_s( path.native_directory_string( ), "rb" ); - if( infile == NULL ) return il::image_type_ptr( ); + if( stream->is_null( ) ) return il::image_type_ptr( ); // TODO: some proper exception handling is needed. can't really be bothered // with that setjmp thingie... @@ -107,7 +208,7 @@ #ifdef HAVE_JPEGHDR jpeghdr_create_decompress( &info ); - jpeg_stdio_src( &info.cinfo, infile ); + jpeg_oil_stream_src( &info.cinfo, stream ); switch( jpeghdr_read_header( &info ) ) { @@ -125,7 +226,7 @@ } #else jpeg_create_decompress( &info ); - jpeg_stdio_src( &info, infile ); + jpeg_oil_stream_src( &info.cinfo, stream ); jpeg_read_header( &info, TRUE ); jpeg_start_decompress( &info ); #endif @@ -152,27 +253,23 @@ read_jpeg( &info, pixels, image->pitch( ) ); #endif - fclose( infile ); - return image; } - bool store_jpg( const boost::filesystem::path& path, il::image_type_ptr img ) + bool store_jpg( pl::stream_ptr stream, il::image_type_ptr img ) { struct jpeg_compress_struct cinfo; struct jpeg_error_mgr jerr; - FILE *out = Fopen_s( path.native_directory_string( ), "wb" ); - il::image_type_ptr image = il::convert( img, L"r8g8b8" ); image = il::conform( image, 0 ); - if ( out != NULL ) + if ( !stream->is_null( ) ) { il::image_type::pointer line = image->data( ); cinfo.err = jpeg_std_error( &jerr ); jpeg_create_compress( &cinfo ); - jpeg_stdio_dest( &cinfo, out ); + jpeg_oil_stream_dest( &cinfo, stream ); cinfo.image_width = image->width( ); cinfo.image_height = image->height( ); cinfo.input_components = 3; @@ -184,7 +281,6 @@ for ( int i = 0 ; i < image->height( ); i ++, line += image->pitch( ) ) jpeg_write_scanlines( &cinfo, &line, 1 ); jpeg_finish_compress( &cinfo ); - fclose( out ); jpeg_destroy_compress( &cinfo ); return true; } @@ -196,11 +292,11 @@ class jpg_plugin : public il::openimagelib_plugin { public: - virtual il::image_type_ptr load( const fs::path& path ) - { return load_jpg( path ); } + virtual il::image_type_ptr load( pl::stream_ptr stream ) + { return load_jpg( stream ); } - virtual bool store( const fs::path& path, const il::image_type_ptr& im ) - { return store_jpg( path, im ); } + virtual bool store( pl::stream_ptr stream, const il::image_type_ptr& im ) + { return store_jpg( stream, im ); } }; } } } Modified: trunk/lib/openlibraries/src/openimagelib/plugins/png/png_plugin.cpp =================================================================== --- trunk/lib/openlibraries/src/openimagelib/plugins/png/png_plugin.cpp 2007-06-30 16:50:29 UTC (rev 167) +++ trunk/lib/openlibraries/src/openimagelib/plugins/png/png_plugin.cpp 2007-07-03 23:02:52 UTC (rev 168) @@ -16,7 +16,6 @@ namespace pl = olib::openpluginlib; namespace il = olib::openimagelib::il; -namespace fs = boost::filesystem; namespace olib { namespace openimagelib { namespace il { @@ -40,10 +39,10 @@ } } - il::image_type_ptr load_png( const fs::path& path ) + il::image_type_ptr load_png( pl::stream_ptr stream ) { // TODO: some proper exception handling is needed. - FILE* infile = fopen( path.native_directory_string( ).c_str( ), "rb" ); + FILE* infile = fopen( stream->path( ).c_str( ), "rb" ); if( infile == NULL ) return il::image_type_ptr( ); png_byte sig[ 8 ]; @@ -100,10 +99,10 @@ struct png_plugin : public il::openimagelib_plugin { - virtual il::image_type_ptr load( const fs::path& path ) - { return load_png( path ); } + virtual il::image_type_ptr load( pl::stream_ptr stream ) + { return load_png( stream ); } - virtual bool store( const fs::path&, const il::image_type_ptr& ) + virtual bool store( pl::stream_ptr, const il::image_type_ptr& ) { return false; } }; Modified: trunk/lib/openlibraries/src/openimagelib/plugins/psd/psd_plugin.cpp =================================================================== --- trunk/lib/openlibraries/src/openimagelib/plugins/psd/psd_plugin.cpp 2007-06-30 16:50:29 UTC (rev 167) +++ trunk/lib/openlibraries/src/openimagelib/plugins/psd/psd_plugin.cpp 2007-07-03 23:02:52 UTC (rev 168) @@ -9,13 +9,10 @@ #include <vector> #include <string> -#include <boost/filesystem/fstream.hpp> - #include <openimagelib/il/openimagelib_plugin.hpp> namespace pl = olib::openpluginlib; namespace il = olib::openimagelib::il; -namespace fs = boost::filesystem; namespace olib { namespace openimagelib { namespace il { @@ -26,17 +23,6 @@ bool is_psd_header( const std::string& magic ) { return magic == std::string( "8BPS" ); } - - void Read_s( fs::ifstream& file, char* s, std::streamsize size, std::streamsize max ) - { -#if _MSC_VER >= 1400 - file._Read_s( s, size, max ); -#else - file.read( s, size ); -#endif // _MSC_VER >= 1400 - - assert( !file.fail( ) && L"PSD_image_loader::Read_s" ); - } } template<typename T> @@ -47,7 +33,7 @@ long psd_long( T s[ 4 ] ) { return ( s[ 0 ] << 24 ) + ( s[ 1 ] << 16 ) + ( s[ 2 ] << 8 ) + s[ 3 ]; } -il::image_type_ptr load_psd( const fs::path& path ) +il::image_type_ptr load_psd( pl::stream_ptr stream ) { #ifdef WIN32 # pragma pack( push, 1 ) @@ -73,12 +59,11 @@ // TODO: do the equivalent on Linux... #endif // WIN32 - fs::ifstream file( path, std::ios::in | std::ios::binary ); - if( !file.is_open( ) ) + if( stream->is_null( ) ) return il::image_type_ptr( ); PhotoshopHeader head; - Read_s( file, reinterpret_cast<char*>( &head ), sizeof( head ), sizeof( head ) ); + stream->read( reinterpret_cast<char*>( &head ), sizeof( head ) ); if( !is_psd_header( std::string( head.signature, 4 ) ) ) return il::image_type_ptr( ); @@ -88,10 +73,10 @@ class psd_plugin : public il::openimagelib_plugin { public: - virtual il::image_type_ptr load( const fs::path& path ) - { return load_psd( path ); } + virtual il::image_type_ptr load( pl::stream_ptr stream ) + { return load_psd( stream ); } - virtual bool store( const fs::path&, const il::image_type_ptr& ) + virtual bool store( pl::stream_ptr, const il::image_type_ptr& ) { return false; } }; Modified: trunk/lib/openlibraries/src/openimagelib/plugins/quicktime/quicktime_plugin.cpp =================================================================== --- trunk/lib/openlibraries/src/openimagelib/plugins/quicktime/quicktime_plugin.cpp 2007-06-30 16:50:29 UTC (rev 167) +++ trunk/lib/openlibraries/src/openimagelib/plugins/quicktime/quicktime_plugin.cpp 2007-07-03 23:02:52 UTC (rev 168) @@ -14,14 +14,12 @@ #include <QuickTime/QuickTimeComponents.h> #endif -#include <boost/filesystem/fstream.hpp> #include <boost/thread/recursive_mutex.hpp> #include <openpluginlib/pl/utf8_utils.hpp> #include <openimagelib/il/openimagelib_plugin.hpp> namespace il = olib::openimagelib::il; -namespace fs = boost::filesystem; namespace pl = olib::openpluginlib; namespace olib { namespace openimagelib { namespace il { @@ -31,13 +29,13 @@ void destroy( il::image_type* im ) { delete im; } - il::image_type_ptr load_quicktime( const fs::path& path ) + il::image_type_ptr load_quicktime( pl::stream_ptr stream ) { OSStatus err; FSSpec fsspec; #ifdef WIN32 - err = NativePathNameToFSSpec( const_cast<char*>( path.native_file_string( ).c_str( ) ), &fsspec, kErrorIfFileNotFound ); + err = NativePathNameToFSSpec( const_cast<char*>( stream->path( ).c_str( ) ), &fsspec, kErrorIfFileNotFound ); #else FSRef ref; err = FSPathMakeRef( ( const UInt8* ) ( path.native_file_string( ) ).c_str( ), &ref, 0 ); @@ -117,10 +115,10 @@ struct qt_plugin : public il::openimagelib_plugin { - virtual il::image_type_ptr load( const fs::path& path ) - { return load_quicktime( path ); } + virtual il::image_type_ptr load( pl::stream_ptr stream ) + { return load_quicktime( stream ); } - virtual bool store( const fs::path&, const il::image_type_ptr& ) + virtual bool store( pl::stream_ptr stream, const il::image_type_ptr& ) { return false; } }; Modified: trunk/lib/openlibraries/src/openimagelib/plugins/sgi/sgi_plugin.cpp =================================================================== --- trunk/lib/openlibraries/src/openimagelib/plugins/sgi/sgi_plugin.cpp 2007-06-30 16:50:29 UTC (rev 167) +++ trunk/lib/openlibraries/src/openimagelib/plugins/sgi/sgi_plugin.cpp 2007-07-03 23:02:52 UTC (rev 168) @@ -9,13 +9,10 @@ #include <vector> #include <string> -#include <boost/filesystem/fstream.hpp> - #include <openimagelib/il/openimagelib_plugin.hpp> namespace il = olib::openimagelib::il; namespace pl = olib::openpluginlib; -namespace fs = boost::filesystem; namespace olib { namespace openimagelib { namespace il { @@ -44,7 +41,7 @@ unsigned int t1 = *ptr++; unsigned int t2 = *ptr++; - *array++ = ( t1 << 8 ) | t2; + *array++ = static_cast<unsigned short>( ( t1 << 8 ) | t2 ); } } @@ -63,17 +60,6 @@ } } - bool Read_s( fs::ifstream& file, char* s, std::streamsize size, std::streamsize max ) - { -#if _MSC_VER >= 1400 - file._Read_s( s, size, max ); -#else - file.read( s, size ); -#endif // _MSC_VER >= 1400 - - return !file.fail( ); - } - il::image_type_ptr sgi_image_type_to_image_type( int /*dimension*/, int channels, int width, int height ) { typedef il::image<unsigned char, il::r8g8b8> r8g8b8_image_type; @@ -102,15 +88,15 @@ return il::image_type_ptr( ); } - bool read_row( fs::ifstream& file, SGI_image& di, unsigned char* buf, int y, int z ) + bool read_row( pl::stream_ptr stream, SGI_image& di, unsigned char* buf, int y, int z ) { if( ( di.type & 0xFF00 ) == 0x0100 ) { std::vector<unsigned char> tmp; tmp.resize( di.row_size[ y + z * di.ysize ] ); - file.rdbuf( )->pubseekoff( di.row_start[ y + z * di.ysize ], std::ios::beg ); - if( !Read_s( file, reinterpret_cast<char*>( &tmp[ 0 ] ), di.row_size[ y + z * di.ysize ], di.row_size[ y + z * di.ysize ] ) ) return false; + stream->seek( di.row_start[ y + z * di.ysize ], std::ios::beg ); + stream->read( reinterpret_cast<char*>( &tmp[ 0 ] ), di.row_size[ y + z * di.ysize ] ); unsigned char* s = &tmp[ 0 ]; unsigned char* t = buf; @@ -135,14 +121,14 @@ } else { - file.rdbuf( )->pubseekoff( 512 + ( y * di.xsize ) + ( z * di.xsize * di.ysize ), std::ios::beg ); - if( !Read_s( file, reinterpret_cast<char*>( buf ), di.xsize, di.xsize ) ) return false; + stream->seek( 512 + ( y * di.xsize ) + ( z * di.xsize * di.ysize ), std::ios::beg ); + stream->read( reinterpret_cast<char*>( buf ), di.xsize ); } return true; } - il::image_type_ptr load_sgi( const fs::path& path ) + il::image_type_ptr load_sgi( pl::stream_ptr stream ) { SGI_image di; @@ -150,10 +136,9 @@ big_endian_test.i = 1; bool is_big_endian = big_endian_test.c[ 0 ] == 1; - fs::ifstream file( path, std::ios::in | std::ios::binary ); - if( !file.is_open( ) ) return il::image_type_ptr( ); + if( stream->is_null( ) ) return il::image_type_ptr( ); - if( !Read_s( file, reinterpret_cast<char*>( &di ), 12, 12 ) ) + if( !stream->read( reinterpret_cast<char*>( &di ), 12 ) ) return il::image_type_ptr( ); if( is_big_endian ) @@ -173,12 +158,10 @@ di.rle_end = 512 + ( 2 * size ); - file.rdbuf( )->pubseekoff( 512, std::ios::beg ); + stream->seek( 512, std::ios::beg ); - if( !Read_s( file, reinterpret_cast<char*>( &di.row_start[ 0 ] ), size, size ) ) - return il::image_type_ptr( ); - if( !Read_s( file, reinterpret_cast<char*>( &di.row_size[ 0 ] ), size, size ) ) - return il::image_type_ptr( ); + stream->read( reinterpret_cast<char*>( &di.row_start[ 0 ] ), size ); + stream->read( reinterpret_cast<char*>( &di.row_size[ 0 ] ), size ); if( is_big_endian ) { @@ -199,10 +182,10 @@ { if( di.zsize >= 4 ) { - if( !read_row( file, di, &r[ 0 ], y, 0 ) ) return il::image_type_ptr( ); - if( !read_row( file, di, &g[ 0 ], y, 1 ) ) return il::image_type_ptr( ); - if( !read_row( file, di, &b[ 0 ], y, 2 ) ) return il::image_type_ptr( ); - if( !read_row( file, di, &a[ 0 ], y, 3 ) ) return il::image_type_ptr( ); + if( !read_row( stream, di, &r[ 0 ], y, 0 ) ) return il::image_type_ptr( ); + if( !read_row( stream, di, &g[ 0 ], y, 1 ) ) return il::image_type_ptr( ); + if( !read_row( stream, di, &b[ 0 ], y, 2 ) ) return il::image_type_ptr( ); + if( !read_row( stream, di, &a[ 0 ], y, 3 ) ) return il::image_type_ptr( ); unsigned char* rptr = &r[ 0 ]; unsigned char* gptr = &g[ 0 ]; @@ -222,9 +205,9 @@ } else if( di.zsize == 3 ) { - if( !read_row( file, di, &r[ 0 ], y, 0 ) ) return il::image_type_ptr( ); - if( !read_row( file, di, &g[ 0 ], y, 1 ) ) return il::image_type_ptr( ); - if( !read_row( file, di, &b[ 0 ], y, 2 ) ) return il::image_type_ptr( ); + if( !read_row( stream, di, &r[ 0 ], y, 0 ) ) return il::image_type_ptr( ); + if( !read_row( stream, di, &g[ 0 ], y, 1 ) ) return il::image_type_ptr( ); + if( !read_row( stream, di, &b[ 0 ], y, 2 ) ) return il::image_type_ptr( ); unsigned char* rptr = &r[ 0 ]; unsigned char* gptr = &g[ 0 ]; @@ -242,8 +225,8 @@ } else if( di.zsize == 2 ) { - if( !read_row( file, di, &r[ 0 ], y, 0 ) ) return il::image_type_ptr( ); - if( !read_row( file, di, &a[ 0 ], y, 1 ) ) return il::image_type_ptr( ); + if( !read_row( stream, di, &r[ 0 ], y, 0 ) ) return il::image_type_ptr( ); + if( !read_row( stream, di, &a[ 0 ], y, 1 ) ) return il::image_type_ptr( ); unsigned char* rptr = &r[ 0 ]; unsigned char* aptr = &a[ 0 ]; @@ -259,7 +242,7 @@ } else { - if( !read_row( file, di, &r[ 0 ], y, 0 ) ) return il::image_type_ptr( ); + if( !read_row( stream, di, &r[ 0 ], y, 0 ) ) return il::image_type_ptr( ); unsigned char* rptr = &r[ 0 ]; long n = di.xsize; @@ -281,10 +264,10 @@ class sgi_plugin : public il::openimagelib_plugin { public: - virtual il::image_type_ptr load( const fs::path& path ) - { return load_sgi( path ); } + virtual il::image_type_ptr load( pl::stream_ptr stream ) + { return load_sgi( stream ); } - virtual bool store( const fs::path&, const il::image_type_ptr& ) + virtual bool store( pl::stream_ptr, const il::image_type_ptr& ) { return false; } }; Modified: trunk/lib/openlibraries/src/openimagelib/plugins/tga/tga_plugin.cpp =================================================================== --- trunk/lib/openlibraries/src/openimagelib/plugins/tga/tga_plugin.cpp 2007-06-30 16:50:29 UTC (rev 167) +++ trunk/lib/openlibraries/src/openimagelib/plugins/tga/tga_plugin.cpp 2007-07-03 23:02:52 UTC (rev 168) @@ -12,12 +12,8 @@ #include <vector> #include <string> -#include <boost/filesystem/fstream.hpp> -#include <boost/filesystem/path.hpp> - #include <openimagelib/il/openimagelib_plugin.hpp> -namespace fs = boost::filesystem; namespace il = olib::openimagelib::il; namespace pl = olib::openpluginlib; @@ -28,17 +24,6 @@ void destroy( il::image_type* im ) { delete im; } - bool Read_s( fs::ifstream& file, char* s, std::streamsize size, std::streamsize max ) - { -#if _MSC_VER >= 1400 - file._Read_s( s, size, max ); -#else - file.read( s, size ); -#endif // _MSC_VER >= 1400 - - return !file.fail( ); - } - il::image_type_ptr tga_image_type_to_image_type( unsigned char type, unsigned char bpp, int width, int height ) { typedef il::image<unsigned char, il::b8g8r8> b8g8r8_image_type; @@ -65,7 +50,7 @@ } } - il::image_type_ptr load_tga( const fs::path& path ) + il::image_type_ptr load_tga( pl::stream_ptr stream ) { #ifdef WIN32 #pragma pack( push, 1 ) @@ -110,20 +95,8 @@ // TODO: do the equivalent on Linux... #endif // WIN32 - fs::ifstream file( path, std::ios::in | std::ios::binary ); - if( !file.is_open( ) ) - return il::image_type_ptr( ); + const char* data = stream->data( ); - std::ios::pos_type beg = file.rdbuf( )->pubseekoff( 0, std::ios::beg ); - std::ios::pos_type end = file.rdbuf( )->pubseekoff( 0, std::ios::end ); - file.rdbuf( )->pubseekoff( 0, std::ios::beg ); - - std::vector<char> stream_data; - stream_data.resize( end - beg ); - Read_s( file, &stream_data[ 0 ], end - beg, end - beg ); - - const char* data = &stream_data[ 0 ]; - TgaHeader head; head = *( ( TgaHeader* ) data ); data += sizeof( TgaHeader ); @@ -249,10 +222,10 @@ class tga_plugin : public il::openimagelib_plugin { public: - virtual il::image_type_ptr load( const fs::path& path ) - { return load_tga( path ); } - - virtual bool store( const fs::path&, const il::image_type_ptr& ) + virtual il::image_type_ptr load( pl::stream_ptr stream ) + { return load_tga( stream ); } + + virtual bool store( pl::stream_ptr, const il::image_type_ptr& ) { return false; } }; Modified: trunk/lib/openlibraries/src/openimagelib/plugins/tiff/tiff_plugin.cpp =================================================================== --- trunk/lib/openlibraries/src/openimagelib/plugins/tiff/tiff_plugin.cpp 2007-06-30 16:50:29 UTC (rev 167) +++ trunk/lib/openlibraries/src/openimagelib/plugins/tiff/tiff_plugin.cpp 2007-07-03 23:02:52 UTC (rev 168) @@ -10,12 +10,8 @@ #include <tiffio.h> -#include <boost/filesystem/fstream.hpp> -#include <boost/filesystem/path.hpp> - #include <openimagelib/il/openimagelib_plugin.hpp> -namespace fs = boost::filesystem; namespace il = olib::openimagelib::il; namespace pl = olib::openpluginlib; @@ -33,9 +29,9 @@ return il::image_type_ptr( ); } - il::image_type_ptr load_tiff( const fs::path& path ) + il::image_type_ptr load_tiff( pl::stream_ptr stream ) { - struct tiff* tif = TIFFOpen( path.native_file_string( ).c_str( ), "r" ); + struct tiff* tif = TIFFOpen( stream->path( ).c_str( ), "r" ); if( tif == NULL ) return il::image_type_ptr( ); @@ -125,10 +121,10 @@ class tiff_plugin : public il::openimagelib_plugin { public: - virtual il::image_type_ptr load( const fs::path& path ) - { return load_tiff( path ); } + virtual il::image_type_ptr load( pl::stream_ptr stream ) + { return load_tiff( stream ); } - virtual bool store( const fs::path&, const il::image_type_ptr& ) + virtual bool store( pl::stream_ptr, const il::image_type_ptr& ) { return false; } }; Modified: trunk/lib/openlibraries/src/openimagelib/py/il.cpp =================================================================== --- trunk/lib/openlibraries/src/openimagelib/py/il.cpp 2007-06-30 16:50:29 UTC (rev 167) +++ trunk/lib/openlibraries/src/openimagelib/py/il.cpp 2007-07-03 23:02:52 UTC (rev 168) @@ -22,7 +22,7 @@ if( !plug ) return il::image_type_ptr( ); - il::image_type_ptr image = plug->load( fs::path( path, fs::native ) ); + il::image_type_ptr image = plug->load( opl::make_stream( path, std::ios::in ) ); if( !image ) return il::image_type_ptr( ); Modified: trunk/lib/openlibraries/src/openmedialib/plugins/oil/oil_plugin.cpp =================================================================== --- trunk/lib/openlibraries/src/openmedialib/plugins/oil/oil_plugin.cpp 2007-06-30 16:50:29 UTC (rev 167) +++ trunk/lib/openlibraries/src/openmedialib/plugins/oil/oil_plugin.cpp 2007-07-03 23:02:52 UTC (rev 168) @@ -328,7 +328,7 @@ if ( full != last_image_name_ ) { last_image_name_ = full; - last_image_ = plug_->load( fs::path( full.c_str( ), fs::native ) ); + last_image_ = plug_->load( pl::make_stream( full, std::ios::in ) ); if ( last_image_ ) last_image_->set_writable( false ); } @@ -338,7 +338,7 @@ { if ( bucket_[ index ] == image_type_ptr( ) ) { - image_type_ptr image = plug_->load( fs::path( full.c_str( ), fs::native ) ); + image_type_ptr image = plug_->load( pl::make_stream( full, std::ios::in) ); if ( image ) { bucket_[ index ] = image; @@ -473,9 +473,9 @@ discovery plugins( query ); if ( plugins.size( ) == 0 ) return false; discovery::const_iterator i = plugins.begin( ); - boost::shared_ptr<il::openimagelib_plugin>plug = boost::shared_dynamic_cast<il::openimagelib_plugin>( i->create_plugin( "" ) ); + il::openimagelib_plugin_ptr plug = boost::shared_dynamic_cast<il::openimagelib_plugin>( i->create_plugin( "" ) ); if ( plug == 0 ) return false; - return plug->store( out.str( ), image ); + return plug->store( pl::make_stream( out, std::ios::out ), image ); } private: Modified: trunk/lib/openlibraries/src/openobjectlib/sg/appearance.cpp =================================================================== --- trunk/lib/openlibraries/src/openobjectlib/sg/appearance.cpp 2007-06-30 16:50:29 UTC (rev 167) +++ trunk/lib/openlibraries/src/openobjectlib/sg/appearance.cpp 2007-07-03 23:02:52 UTC (rev 168) @@ -144,7 +144,7 @@ il::openimagelib_plugin_ptr plug = boost::shared_dynamic_cast<il::openimagelib_plugin>( i->create_plugin( "" ) ); if( !plug ) return false; - im_ = plug->load( path ); + im_ = plug->load( opl::make_stream( path.native_file_string( ), std::ios::in ) ); if( !im_ ) return false; if( !opl::is_compressed_format( im_->pf( ).c_str( ) ) && im_->count( ) == 1 && im_->depth( ) == 1 ) Modified: trunk/lib/openlibraries/src/openpluginlib/pl/GL_utility.cpp =================================================================== --- trunk/lib/openlibraries/src/openpluginlib/pl/GL_utility.cpp 2007-06-30 16:50:29 UTC (rev 167) +++ trunk/lib/openlibraries/src/openpluginlib/pl/GL_utility.cpp 2007-07-03 23:02:52 UTC (rev 168) @@ -130,30 +130,4 @@ return false; } -bool proxy_texture_target( size_t width, size_t height, GLenum& target, bool force_2_0_targets ) -{ - if( ( ( GLEW_VERSION_2_0 || GLEW_ARB_texture_non_power_of_two ) && force_2_0_targets ) || ( !( width & ( width - 1 ) ) ) && ( !( height & ( height - 1 ) ) ) ) - { - target = GL_PROXY_TEXTURE_2D; - return true; - } - else if( GLEW_ARB_texture_rectangle ) - { - target = GL_PROXY_TEXTURE_RECTANGLE_ARB; - return true; - } - else if( GLEW_EXT_texture_rectangle ) - { - target = GL_PROXY_TEXTURE_RECTANGLE_EXT; - return true; - } - else if( GLEW_NV_texture_rectangle ) - { - target = GL_PROXY_TEXTURE_RECTANGLE_NV; - return true; - } - - return false; -} - } } Modified: trunk/lib/openlibraries/src/openpluginlib/pl/GL_utility.hpp =================================================================== --- trunk/lib/openlibraries/src/openpluginlib/pl/GL_utility.hpp 2007-06-30 16:50:29 UTC (rev 167) +++ trunk/lib/openlibraries/src/openpluginlib/pl/GL_utility.hpp 2007-07-03 23:02:52 UTC (rev 168) @@ -21,7 +21,6 @@ OPENPLUGINLIB_DECLSPEC bool is_compressed_format( const wstring& pf ); OPENPLUGINLIB_DECLSPEC bool is_yuv_format( const wstring& pf ); OPENPLUGINLIB_DECLSPEC bool texture_target( size_t width, size_t height, GLenum& target, float& tex_w, float& tex_h, bool force_2_0_targets = false ); -OPENPLUGINLIB_DECLSPEC bool proxy_texture_target( size_t width, size_t height, GLenum& target, bool force_2_0_targets = false ); } } Modified: trunk/lib/openlibraries/src/openpluginlib/pl/Makefile.am =================================================================== --- trunk/lib/openlibraries/src/openpluginlib/pl/Makefile.am 2007-06-30 16:50:29 UTC (rev 167) +++ trunk/lib/openlibraries/src/openpluginlib/pl/Makefile.am 2007-07-03 23:02:52 UTC (rev 168) @@ -44,10 +44,11 @@ flex_string_shell.h \ simplestringstorage.h \ smallstringopt.h \ + stream.hpp \ + stream.cpp \ vectorstringstorage.h \ GL_utility.hpp \ GL_utility.cpp \ - string.hpp \ cg.hpp \ cg.cpp \ pcos/key.hpp \ @@ -106,18 +107,11 @@ string.hpp \ timer.hpp \ shader_manager.hpp \ - allocatorstringstorage.h \ - cowstringopt.h \ - flex_string_details.h \ - flex_string.h \ - flex_string_shell.h \ - simplestringstorage.h \ - smallstringopt.h \ - vectorstringstorage.h \ geometry.hpp \ cg.hpp \ GL_utility.hpp \ string.hpp \ + stream.hpp \ pcos/key.hpp \ pcos/observer.hpp \ pcos/iproperty_container.hpp \ Modified: trunk/lib/openlibraries/src/openpluginlib/pl/stream.cpp =================================================================== --- trunk/lib/openlibraries/src/openpluginlib/pl/stream.cpp 2007-06-30 16:50:29 UTC (rev 167) +++ trunk/lib/openlibraries/src/openpluginlib/pl/stream.cpp 2007-07-03 23:02:52 UTC (rev 168) @@ -3,15 +3,121 @@ // Copyright (C) 2007 Goncalo Nuno M. de Carvalho // Released under the LGPL. -// For more information, see http://www.openlibraries.org. +// For more information, see http://www.cryogenicgraphics.com/hdrflow. +#include <boost/filesystem/operations.hpp> + +#include <openpluginlib/pl/utf8_utils.hpp> #include <openpluginlib/pl/stream.hpp> +namespace fs = boost::filesystem; + namespace olib { namespace openpluginlib { -stream_ptr make_stream( const string&, int ) +stream::stream( const string& path, std::ios::openmode flags, std::size_t max_size ) + : data_( 0 ) + , offset_( 0 ) + , max_size_( max_size ) + , flags_( flags ) + , path_( path ) { - return stream_ptr( ); + fs::path fs_path( path.c_str( ), fs::native ); + if( fs::exists( fs_path ) ) + { + mapped_.open( fs_path.native_file_string( ), flags ); + if( mapped_.is_open( ) ) + { + if( ( flags_ && std::ios::out ) != 0 )data_ = const_cast<char*>( mapped_.const_data( ) ); + else data_ = mapped_.data( ); + + max_size_ = mapped_.size( ); + } + } } +stream::~stream( ) +{ + if( mapped_.is_open( ) ) + { + data_ = 0; + offset_ = 0; + flags_ = 0; + mapped_.close( ); + } +} + +std::size_t stream::read( stream::pointer data, std::size_t bytes ) +{ + bytes = actual_bytes( bytes ); + + memcpy( data, data_ + offset_, bytes ); + offset_ += bytes; + + return bytes; +} + +std::size_t stream::write( stream::const_pointer data, std::size_t bytes ) +{ + bytes = actual_bytes( bytes ); + + memcpy( data_ + offset_, data, bytes ); + offset_ += bytes; + + return bytes; +} + +void stream::seek( std::size_t bytes, std::ios::seekdir flags ) +{ + if( flags == std::ios::beg ) + offset_ = bytes; + else if( flags == std::ios::cur ) + offset_ += bytes; + else if( flags == std::ios::end ) + offset_ = max_size_ - bytes; +} + +std::size_t stream::getline( pointer data, std::size_t bytes ) +{ + bytes = actual_bytes( bytes ); + + std::size_t i = 0; + for( ; *( data_ + i ) != '\n' && i < bytes; ++i ) + *data++ = *( data_ + i ); + + if( *( data_ + i ) == '\n' ) + ++i; +... [truncated message content] |