CVSROOT: /sources/gnash Module name: gnash Changes by: Sandro Santilli <strk> 07/08/28 13:12:38
Modified files: . : ChangeLog libbase : image.h jpeg.cpp jpeg.h server : stream.h server/swf : tag_loaders.cpp Log message: * libbase/: image.{cpp,h}, jpeg.{cpp,h}: extend interface for jpeg creators taking tu_file to specify ownership of the input stream. * server/swf/tag_loaders.cpp: substitute calls to stream::get_underlying_stream with use of a quick&dirty tu_file adpater using stream underneath. * server/stream.h: remove get_underlying_stream method. CVSWeb URLs: http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.4136&r2=1.4137 http://cvs.savannah.gnu.org/viewcvs/gnash/libbase/image.h?cvsroot=gnash&r1=1.14&r2=1.15 http://cvs.savannah.gnu.org/viewcvs/gnash/libbase/jpeg.cpp?cvsroot=gnash&r1=1.19&r2=1.20 http://cvs.savannah.gnu.org/viewcvs/gnash/libbase/jpeg.h?cvsroot=gnash&r1=1.7&r2=1.8 http://cvs.savannah.gnu.org/viewcvs/gnash/server/stream.h?cvsroot=gnash&r1=1.28&r2=1.29 http://cvs.savannah.gnu.org/viewcvs/gnash/server/swf/tag_loaders.cpp?cvsroot=gnash&r1=1.133&r2=1.134 Patches: Index: ChangeLog =================================================================== RCS file: /sources/gnash/gnash/ChangeLog,v retrieving revision 1.4136 retrieving revision 1.4137 diff -u -b -r1.4136 -r1.4137 --- ChangeLog 28 Aug 2007 12:39:12 -0000 1.4136 +++ ChangeLog 28 Aug 2007 13:12:37 -0000 1.4137 @@ -1,3 +1,13 @@ +2007-08-28 Sandro Santilli <[EMAIL PROTECTED]> + + * libbase/: image.{cpp,h}, jpeg.{cpp,h}: extend interface + for jpeg creators taking tu_file to specify + ownership of the input stream. + * server/swf/tag_loaders.cpp: substitute calls to + stream::get_underlying_stream with use of a quick&dirty + tu_file adpater using stream underneath. + * server/stream.h: remove get_underlying_stream method. + 2007-08-28 Udo Giacomozzi <[EMAIL PROTECTED]> * server/stream.h: documented some functions Index: libbase/image.h =================================================================== RCS file: /sources/gnash/gnash/libbase/image.h,v retrieving revision 1.14 retrieving revision 1.15 diff -u -b -r1.14 -r1.15 --- libbase/image.h 16 Jun 2007 12:47:53 -0000 1.14 +++ libbase/image.h 28 Aug 2007 13:12:38 -0000 1.15 @@ -155,6 +155,11 @@ DSOEXPORT rgb* read_jpeg(const char* filename); /// Create and read a new image from the stream. + // + /// @param in + /// Stream to read from. Ownership to the caller, + /// not needed after return. + /// DSOEXPORT rgb* read_jpeg(tu_file* in); /// \brief Index: libbase/jpeg.cpp =================================================================== RCS file: /sources/gnash/gnash/libbase/jpeg.cpp,v retrieving revision 1.19 retrieving revision 1.20 diff -u -b -r1.19 -r1.20 --- libbase/jpeg.cpp 28 Aug 2007 10:20:57 -0000 1.19 +++ libbase/jpeg.cpp 28 Aug 2007 13:12:38 -0000 1.20 @@ -46,21 +46,29 @@ public: struct jpeg_source_mgr m_pub; /* public fields */ + // Constructor. The caller is responsible for closing the input stream + // after it's done using us. + // rw_source_tu_file(tu_file* in) : + _ownSourceStream(false), m_in_stream(in), m_start_of_file(true) - // Constructor. The caller is responsible for closing the input stream - // after it's done using us. { - // fill in function pointers... - m_pub.init_source = init_source; - m_pub.fill_input_buffer = fill_input_buffer; - m_pub.skip_input_data = skip_input_data; - m_pub.resync_to_restart = jpeg_resync_to_restart; // use default method - m_pub.term_source = term_source; - m_pub.bytes_in_buffer = 0; - m_pub.next_input_byte = NULL; + init(); + } + + void takeStreamOwnership() + { + _ownSourceStream=true; + } + + ~rw_source_tu_file() + { + if ( _ownSourceStream ) + { + delete m_in_stream; + } } static void init_source(j_decompress_ptr cinfo) @@ -159,15 +167,40 @@ m_pub.next_input_byte = NULL; } - // Set up the given decompress object to read from the given - // stream. - static void setup(jpeg_decompress_struct* cinfo, tu_file* instream) + /// Set up the given decompress object to read from the given + /// stream. + /// + /// @param instream + /// Stream to read from. Ownership decided by last arg. + /// + /// @param takeOwnership + /// If false, ownership of the stream + /// is left to caller, otherwise we take it. + // + static void setup(jpeg_decompress_struct* cinfo, tu_file* instream, + bool takeOwnership=false) { // assert(cinfo->src == NULL); - cinfo->src = (jpeg_source_mgr*) (new rw_source_tu_file(instream)); + rw_source_tu_file* source = new rw_source_tu_file(instream); + if ( takeOwnership ) source->takeStreamOwnership(); + cinfo->src = (jpeg_source_mgr*)source; } private: + + void init() + { + // fill in function pointers... + m_pub.init_source = init_source; + m_pub.fill_input_buffer = fill_input_buffer; + m_pub.skip_input_data = skip_input_data; + m_pub.resync_to_restart = jpeg_resync_to_restart; // use default method + m_pub.term_source = term_source; + m_pub.bytes_in_buffer = 0; + m_pub.next_input_byte = NULL; + } + + bool _ownSourceStream; tu_file* m_in_stream; /* source stream */ bool m_start_of_file; /* have we gotten any data yet? */ JOCTET m_buffer[IO_BUF_SIZE]; /* start of buffer */ @@ -288,9 +321,18 @@ enum SWF_DEFINE_BITS_JPEG2 { SWF_JPEG2 }; enum SWF_DEFINE_BITS_JPEG2_HEADER_ONLY { SWF_JPEG2_HEADER_ONLY }; - // Constructor. Read the header data from in, and - // prepare to read data. - input_tu_file(tu_file* in) + /// \brief + /// Constructor. Read the header data from in, and + /// prepare to read data. + // + /// @param in + /// The stream to read from. Ownership specified by + /// second argument. + /// + /// @param takeOwnership + /// If true, we take ownership of the input stream. + /// + input_tu_file(tu_file* in, bool takeOwnership=false) : m_compressor_opened(false) { @@ -301,7 +343,7 @@ // Initialize decompression object. jpeg_create_decompress(&m_cinfo); - rw_source_tu_file::setup(&m_cinfo, in); + rw_source_tu_file::setup(&m_cinfo, in, takeOwnership); start_image(); } @@ -314,7 +356,15 @@ // start_image() and finish_image() around any calls // to get_width/height/components and read_scanline. // - input_tu_file(SWF_DEFINE_BITS_JPEG2_HEADER_ONLY /* e */, tu_file* in) + /// @param in + /// The stream to read from. Ownership specified by + /// last argument. + /// + /// @param takeOwnership + /// If true, we take ownership of the input stream. + /// + input_tu_file(SWF_DEFINE_BITS_JPEG2_HEADER_ONLY /* e */, tu_file* in, + bool takeOwnership=false) : m_compressor_opened(false) { @@ -325,7 +375,7 @@ // Initialize decompression object. jpeg_create_decompress(&m_cinfo); - rw_source_tu_file::setup(&m_cinfo, in); + rw_source_tu_file::setup(&m_cinfo, in, takeOwnership); // Read the encoding tables. int ret = jpeg_read_header(&m_cinfo, FALSE); @@ -364,7 +414,6 @@ delete src; m_cinfo.src = NULL; - jpeg_destroy_decompress(&m_cinfo); } @@ -576,18 +625,18 @@ /*static*/ input* -input::create(tu_file* in) +input::create(tu_file* in, bool takeOwnership) { - input* ret = new tu_file_wrappers::input_tu_file(in); + input* ret = new tu_file_wrappers::input_tu_file(in, takeOwnership); return ret; } /*static*/ input* -input::create_swf_jpeg2_header_only(tu_file* in) +input::create_swf_jpeg2_header_only(tu_file* in, bool takeOwnership) { using tu_file_wrappers::input_tu_file; - input* ret = new input_tu_file(input_tu_file::SWF_JPEG2_HEADER_ONLY, in); + input* ret = new input_tu_file(input_tu_file::SWF_JPEG2_HEADER_ONLY, in, takeOwnership); return ret; } Index: libbase/jpeg.h =================================================================== RCS file: /sources/gnash/gnash/libbase/jpeg.h,v retrieving revision 1.7 retrieving revision 1.8 diff -u -b -r1.7 -r1.8 --- libbase/jpeg.h 28 Aug 2007 10:20:57 -0000 1.7 +++ libbase/jpeg.h 28 Aug 2007 13:12:38 -0000 1.8 @@ -43,9 +43,19 @@ // /// The created input reads the jpeg header /// + /// @param in + /// The stream to read from. Ownership specified by last arg. + /// + /// @param takeOwnership + /// If false, ownership of the stream + /// is left to caller, otherwise we take it. + /// NOTE: In case the caller retains ownership, it must + /// make sure the stream is alive and not modified + /// for the whole lifetime of the returned instance. + /// /// @return NULL on error /// - DSOEXPORT static input* create(tu_file* in); + DSOEXPORT static input* create(tu_file* in, bool takeOwnership=false); /// Read SWF JPEG2-style header. // @@ -53,9 +63,21 @@ /// image data. Multiple images can be loaded by /// bracketing within start_image()/finish_image() pairs. /// + /// @param in + /// The tu_file to use for input. Ownership specified + /// by last arg. + /// + /// @param takeOwnership + /// If false, ownership of the stream + /// is left to caller, otherwise we take it. + /// NOTE: In case the caller retains ownership, it must + /// make sure the stream is alive and not modified + /// for the whole lifetime of the returned instance. + /// /// @return NULL on error /// - DSOEXPORT static input* create_swf_jpeg2_header_only(tu_file* in); + DSOEXPORT static input* create_swf_jpeg2_header_only(tu_file* in, + bool takeOwnership=false); /// Discard existing bytes in our buffer. virtual void discard_partial_buffer() = 0; Index: server/stream.h =================================================================== RCS file: /sources/gnash/gnash/server/stream.h,v retrieving revision 1.28 retrieving revision 1.29 diff -u -b -r1.28 -r1.29 --- server/stream.h 28 Aug 2007 12:39:12 -0000 1.28 +++ server/stream.h 28 Aug 2007 13:12:38 -0000 1.29 @@ -203,7 +203,7 @@ /// Seek to the end of the most-recently-opened tag. void close_tag(); - tu_file* get_underlying_stream() { return m_input; } + //tu_file* get_underlying_stream() { return m_input; } /// Discard given number of bytes // Index: server/swf/tag_loaders.cpp =================================================================== RCS file: /sources/gnash/gnash/server/swf/tag_loaders.cpp,v retrieving revision 1.133 retrieving revision 1.134 diff -u -b -r1.133 -r1.134 --- server/swf/tag_loaders.cpp 28 Aug 2007 12:01:30 -0000 1.133 +++ server/swf/tag_loaders.cpp 28 Aug 2007 13:12:38 -0000 1.134 @@ -17,7 +17,7 @@ // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA // -/* $Id: tag_loaders.cpp,v 1.133 2007/08/28 12:01:30 strk Exp $ */ +/* $Id: tag_loaders.cpp,v 1.134 2007/08/28 13:12:38 strk Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -80,6 +80,62 @@ namespace SWF { namespace tag_loaders { + +namespace { // anonymous + +/// +/// tu_file adapter using a stream underneath +/// + +/// Provide a tu_file interface around a gnash::stream +class StreamAdapter +{ + stream& s; + + StreamAdapter(stream& str) + : + s(str) + {} + + static int readFunc(void* dst, int bytes, void* appdata) + { + StreamAdapter* br = (StreamAdapter*) appdata; + return br->s.read((char*)dst, bytes); + } + + static int closeFunc(void* appdata) + { + StreamAdapter* br = (StreamAdapter*) appdata; + delete br; + return 0; // ok ? or TU_FILE_CLOSE_ERROR ? + } + +public: + + /// Get a tu_file from a gnash::stream + static std::auto_ptr<tu_file> getFile(stream& str) + { + std::auto_ptr<tu_file> ret ( + new tu_file ( + new StreamAdapter(str), + readFunc, + 0, // write_func wf, + 0, //seek_func sf, + 0, //seek_to_end_func ef, + 0, //tell_func tf, + 0, //get_eof_func gef, + 0, //get_err_func ger + 0, // get_stream_size_func gss, + closeFunc + ) + ); + + return ret; + } +}; + +} // anonymous namespace + // ---------------------------------------------------------------------------- // ADPCMDecoder class // ---------------------------------------------------------------------------- @@ -488,7 +544,11 @@ try { - j_in.reset(jpeg::input::create_swf_jpeg2_header_only(in->get_underlying_stream())); + std::auto_ptr<tu_file> ad( StreamAdapter::getFile(*in) ); + // transfer ownerhip to the jpeg::input + j_in.reset(jpeg::input::create_swf_jpeg2_header_only(ad.release(), true)); + + //j_in.reset(jpeg::input::create_swf_jpeg2_header_only(in->get_underlying_stream())); } catch (std::exception& e) { @@ -579,12 +639,9 @@ if (m->get_create_bitmaps() == DO_LOAD_BITMAPS) { - //bitmap_info* bi = NULL; - std::auto_ptr<image::rgb> im ( image::read_jpeg(in->get_underlying_stream()) ); - //bi = render::create_bitmap_info_rgb(im); - //delete im; - - //assert(bi->get_ref_count() == 0); + std::auto_ptr<tu_file> ad( StreamAdapter::getFile(*in) ); + std::auto_ptr<image::rgb> im ( image::read_jpeg(ad.get()) ); + //std::auto_ptr<image::rgb> im ( image::read_jpeg(in->get_underlying_stream()) ); if ( m->get_bitmap_character_def(character_id) ) { @@ -689,7 +746,9 @@ // // Read rgb data. - std::auto_ptr<image::rgba> im( image::read_swf_jpeg3(in->get_underlying_stream()) ); + std::auto_ptr<tu_file> ad( StreamAdapter::getFile(*in) ); + std::auto_ptr<image::rgba> im( image::read_swf_jpeg3(ad.get()) ); + //std::auto_ptr<image::rgba> im( image::read_swf_jpeg3(in->get_underlying_stream()) ); // Read alpha channel. in->set_position(alpha_position); _______________________________________________ Gnash-commit mailing list Gnash-commit@gnu.org http://lists.gnu.org/mailman/listinfo/gnash-commit