X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fmisc%2Fimage.c;h=3ea118a6982ec961622171a44634e3e77498ed9c;hb=dfc2996565842dbf644557debc80cb7cc8c2b4f4;hp=da99798ac30b5c7e2c92dab4811dc8f560d461b8;hpb=8ca8d34604ec47d5ec63351755d1e049255a72e2;p=vlc diff --git a/src/misc/image.c b/src/misc/image.c index da99798ac3..3ea118a698 100644 --- a/src/misc/image.c +++ b/src/misc/image.c @@ -1,7 +1,7 @@ /***************************************************************************** * image.c : wrapper for image reading/writing facilities ***************************************************************************** - * Copyright (C) 2004 the VideoLAN team + * Copyright (C) 2004-2007 the VideoLAN team * $Id$ * * Author: Gildas Bazin @@ -30,12 +30,18 @@ * Preamble *****************************************************************************/ #include +#include +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + #include -#include +#include #include +#include #include #include -#include +#include static picture_t *ImageRead( image_handler_t *, block_t *, video_format_t *, video_format_t * ); @@ -97,6 +103,7 @@ void image_HandlerDelete( image_handler_t *p_image ) if( p_image->p_filter ) DeleteFilter( p_image->p_filter ); free( p_image ); + p_image = NULL; } /** @@ -205,48 +212,24 @@ static picture_t *ImageReadUrl( image_handler_t *p_image, const char *psz_url, { block_t *p_block; picture_t *p_pic; - FILE *file; stream_t *p_stream = NULL; int i_size; - file = utf8_fopen( psz_url, "rb" ); - if( file ) - { - fseek( file, 0, SEEK_END ); - i_size = ftell( file ); - fseek( file, 0, SEEK_SET ); - } - else + p_stream = stream_UrlNew( p_image->p_parent, psz_url ); + + if( !p_stream ) { - /*msg_Dbg( p_image->p_parent, "could not open file %s for reading", - psz_url );*/ - /* if file couldn't be opened, try to open the url with the stream - * functions. Any url can be thus be opened. */ - p_stream = stream_UrlNew( p_image->p_parent, psz_url ); - if( !p_stream ) - { - msg_Dbg( p_image->p_parent, "could not open %s for reading", - psz_url ); - return NULL; - } - else - { - i_size = stream_Size( p_stream ); - } + msg_Dbg( p_image->p_parent, "could not open %s for reading", + psz_url ); + return NULL; } + i_size = stream_Size( p_stream ); + p_block = block_New( p_image->p_parent, i_size ); - if( file ) - { - fread( p_block->p_buffer, sizeof(char), i_size, file ); - fclose( file ); - } - else - { - stream_Read( p_stream, p_block->p_buffer, i_size ); - stream_Delete( p_stream ); - } + stream_Read( p_stream, p_block->p_buffer, i_size ); + stream_Delete( p_stream ); if( !p_fmt_in->i_chroma ) { @@ -264,7 +247,7 @@ static picture_t *ImageReadUrl( image_handler_t *p_image, const char *psz_url, * */ -void PicRelease( picture_t *p_pic ){}; +static void PicRelease( picture_t *p_pic ) { (void)p_pic; } static block_t *ImageWrite( image_handler_t *p_image, picture_t *p_pic, video_format_t *p_fmt_in, @@ -373,22 +356,30 @@ static int ImageWriteUrl( image_handler_t *p_image, picture_t *p_pic, file = utf8_fopen( psz_url, "wb" ); if( !file ) { - msg_Dbg( p_image->p_parent, "could not open file %s for writing", - psz_url ); + msg_Err( p_image->p_parent, "%s: %m", psz_url ); return VLC_EGENERIC; } p_block = ImageWrite( p_image, p_pic, p_fmt_in, p_fmt_out ); + int err = 0; if( p_block ) { - fwrite( p_block->p_buffer, sizeof(char), p_block->i_buffer, file ); + if( fwrite( p_block->p_buffer, p_block->i_buffer, 1, file ) != 1 ) + err = errno; block_Release( p_block ); } - fclose( file ); + if( fclose( file ) && !err ) + err = errno; - return p_block ? VLC_SUCCESS : VLC_EGENERIC; + if( err ) + { + errno = err; + msg_Err( p_image->p_parent, "%s: %m", psz_url ); + } + + return err ? VLC_EGENERIC : VLC_SUCCESS; } /** @@ -432,7 +423,7 @@ static picture_t *ImageConvert( image_handler_t *p_image, picture_t *p_pic, { /* We need to restart a new filter */ DeleteFilter( p_image->p_filter ); - p_image->p_filter = 0; + p_image->p_filter = NULL; } /* Start a filter */ @@ -467,6 +458,7 @@ static picture_t *ImageConvert( image_handler_t *p_image, picture_t *p_pic, p_fmt_in->i_height == p_fmt_out->i_height ) { /* Duplicate image */ + p_pif->pf_release( p_pif ); /* XXX: Better fix must be possible */ p_pif = p_image->p_filter->pf_vout_buffer_new( p_image->p_filter ); if( p_pif ) vout_CopyPicture( p_image->p_parent, p_pif, p_pic ); } @@ -522,7 +514,7 @@ static picture_t *ImageFilter( image_handler_t *p_image, picture_t *p_pic, static struct { vlc_fourcc_t i_codec; - char *psz_ext; + const char *psz_ext; } ext_table[] = { @@ -585,9 +577,12 @@ static const char *Fourcc2Ext( vlc_fourcc_t i_codec ) static void video_release_buffer( picture_t *p_pic ) { - if( p_pic && p_pic->p_data_orig ) free( p_pic->p_data_orig ); - if( p_pic && p_pic->p_sys ) free( p_pic->p_sys ); - if( p_pic ) free( p_pic ); + if( p_pic ) + { + free( p_pic->p_data_orig ); + free( p_pic->p_sys ); + free( p_pic ); + } } static picture_t *video_new_buffer( decoder_t *p_dec ) @@ -616,17 +611,23 @@ static picture_t *video_new_buffer( decoder_t *p_dec ) static void video_del_buffer( decoder_t *p_dec, picture_t *p_pic ) { - if( p_pic && p_pic->p_data_orig ) free( p_pic->p_data_orig ); - if( p_pic && p_pic->p_sys ) free( p_pic->p_sys ); - if( p_pic ) free( p_pic ); + (void)p_dec; + if( p_pic ) + { + free( p_pic->p_data_orig ); + free( p_pic->p_sys ); + free( p_pic ); + } } static void video_link_picture( decoder_t *p_dec, picture_t *p_pic ) { + (void)p_dec; (void)p_pic; } static void video_unlink_picture( decoder_t *p_dec, picture_t *p_pic ) { + (void)p_dec; (void)p_pic; } static decoder_t *CreateDecoder( vlc_object_t *p_this, video_format_t *fmt ) @@ -677,7 +678,8 @@ static void DeleteDecoder( decoder_t * p_dec ) es_format_Clean( &p_dec->fmt_in ); es_format_Clean( &p_dec->fmt_out ); - vlc_object_destroy( p_dec ); + vlc_object_release( p_dec ); + p_dec = NULL; } static encoder_t *CreateEncoder( vlc_object_t *p_this, video_format_t *fmt_in, @@ -759,7 +761,8 @@ static void DeleteEncoder( encoder_t * p_enc ) es_format_Clean( &p_enc->fmt_in ); es_format_Clean( &p_enc->fmt_out ); - vlc_object_destroy( p_enc ); + vlc_object_release( p_enc ); + p_enc = NULL; } static filter_t *CreateFilter( vlc_object_t *p_this, es_format_t *p_fmt_in, @@ -780,8 +783,8 @@ static filter_t *CreateFilter( vlc_object_t *p_this, es_format_t *p_fmt_in, p_filter->fmt_out = *p_fmt_in; p_filter->fmt_out.i_codec = p_fmt_out->i_chroma; p_filter->fmt_out.video = *p_fmt_out; - p_filter->p_module = module_Need( p_filter, "video filter2", psz_module, - 0 ); + p_filter->p_module = module_Need( p_filter, "video filter2", + psz_module, 0 ); if( !p_filter->p_module ) { @@ -802,5 +805,6 @@ static void DeleteFilter( filter_t * p_filter ) es_format_Clean( &p_filter->fmt_in ); es_format_Clean( &p_filter->fmt_out ); - vlc_object_destroy( p_filter ); + vlc_object_release( p_filter ); + p_filter = NULL; }