start hacking in better new from file
This commit is contained in:
parent
527f8ff2cc
commit
b394948cd1
9
TODO
9
TODO
@ -2,10 +2,17 @@
|
|||||||
|
|
||||||
implement it using vips_foreign_load()?
|
implement it using vips_foreign_load()?
|
||||||
|
|
||||||
|
foreign/vipsload.c uses vips_image_new_from_file() ... instead it should use
|
||||||
|
the _mode thing
|
||||||
|
|
||||||
|
|
||||||
- likewise, vips_image_write_to_file() should take options. Implement in terms
|
- likewise, vips_image_write_to_file() should take options. Implement in terms
|
||||||
of vips_foreign_save()?
|
of vips_foreign_save()?
|
||||||
|
|
||||||
both need to allow options in the filename too
|
- also new_from_memory() (new from buffer?)
|
||||||
|
|
||||||
|
see vips_foreign_load_buffer() for API
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -72,8 +72,8 @@
|
|||||||
* functions, vips_foreign_load() and vips_foreign_save(), automate the
|
* functions, vips_foreign_load() and vips_foreign_save(), automate the
|
||||||
* process, loading an image from a file or saving an image to a file. These
|
* process, loading an image from a file or saving an image to a file. These
|
||||||
* functions let you give load or save options as name - value pairs in the C
|
* functions let you give load or save options as name - value pairs in the C
|
||||||
* argument list. You can use vips_foreign_load_options() and
|
* argument list. You can also
|
||||||
* vips_foreign_save_options() to include options in the file name.
|
* include options in the file name.
|
||||||
*
|
*
|
||||||
* For example:
|
* For example:
|
||||||
*
|
*
|
||||||
@ -87,7 +87,7 @@
|
|||||||
* the file name extension) with JPEG compression.
|
* the file name extension) with JPEG compression.
|
||||||
*
|
*
|
||||||
* |[
|
* |[
|
||||||
* vips_foreign_save_options (my_image, "frank.tiff[compression=jpeg]", NULL);
|
* vips_foreign_save (my_image, "frank.tiff[compression=jpeg]", NULL);
|
||||||
* ]|
|
* ]|
|
||||||
*
|
*
|
||||||
* Is the same thing, but with the option in the filename. You can put
|
* Is the same thing, but with the option in the filename. You can put
|
||||||
@ -549,7 +549,10 @@ vips_foreign_find_load( const char *name )
|
|||||||
* Loads @filename into @out using the loader recommended by
|
* Loads @filename into @out using the loader recommended by
|
||||||
* vips_foreign_find_load().
|
* vips_foreign_find_load().
|
||||||
*
|
*
|
||||||
* See also: vips_foreign_save(), vips_foreign_load_options().
|
* Load options may be appended to @filename as "[name=value,...]" or given as
|
||||||
|
* a NULL-terminated list of name-value pairs at the end of the arguments.
|
||||||
|
*
|
||||||
|
* See also: vips_foreign_save().
|
||||||
*
|
*
|
||||||
* Returns: 0 on success, -1 on error
|
* Returns: 0 on success, -1 on error
|
||||||
*/
|
*/
|
||||||
@ -627,7 +630,7 @@ vips_foreign_find_load_buffer( void *buf, size_t len )
|
|||||||
* vips_foreign_find_load_buffer(). @option_string can be used to give an
|
* vips_foreign_find_load_buffer(). @option_string can be used to give an
|
||||||
* extra set of load options.
|
* extra set of load options.
|
||||||
*
|
*
|
||||||
* See also: vips_foreign_save(), vips_foreign_load_options().
|
* See also: vips_foreign_save().
|
||||||
*
|
*
|
||||||
* Returns: 0 on success, -1 on error
|
* Returns: 0 on success, -1 on error
|
||||||
*/
|
*/
|
||||||
@ -1510,8 +1513,10 @@ vips_foreign_find_save( const char *name )
|
|||||||
* @...: %NULL-terminated list of optional named arguments
|
* @...: %NULL-terminated list of optional named arguments
|
||||||
*
|
*
|
||||||
* Saves @in to @filename using the saver recommended by
|
* Saves @in to @filename using the saver recommended by
|
||||||
* vips_foreign_find_save(). Options are not in @filename but must be given
|
* vips_foreign_find_save().
|
||||||
* as a NULL-terminated list of name-value pairs.
|
*
|
||||||
|
* Save options may be appended to @filename as "[name=value,...]" or given as
|
||||||
|
* a NULL-terminated list of name-value pairs at the end of the arguments.
|
||||||
*
|
*
|
||||||
* See also: vips_foreign_load().
|
* See also: vips_foreign_load().
|
||||||
*
|
*
|
||||||
|
@ -91,6 +91,8 @@ vips_foreign_load_vips_header( VipsForeignLoad *load )
|
|||||||
VipsImage *out;
|
VipsImage *out;
|
||||||
VipsImage *out2;
|
VipsImage *out2;
|
||||||
|
|
||||||
|
vips_image_new_mode( filename, "r" ) );
|
||||||
|
|
||||||
if( !(out2 = vips_image_new_from_file( vips->filename )) )
|
if( !(out2 = vips_image_new_from_file( vips->filename )) )
|
||||||
return( -1 );
|
return( -1 );
|
||||||
|
|
||||||
|
@ -1674,19 +1674,46 @@ vips_image_new_buffer( void )
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* vips_image_new_from_file:
|
* vips_image_new_from_file:
|
||||||
* @filename: file to open
|
* @name: file to open
|
||||||
|
* @...: %NULL-terminated list of optional named arguments
|
||||||
*
|
*
|
||||||
* vips_image_new_from_file() opens @filename for reading in mode "r". See
|
* vips_image_new_from_file() opens @name for reading. It can load files
|
||||||
* vips_image_new_mode() for details.
|
* in many image formats, including VIPS, TIFF, PNG, JPEG, FITS, Matlab,
|
||||||
|
* OpenEXR, CSV, WebP, Radiance, RAW, PPM and others.
|
||||||
*
|
*
|
||||||
* See also: vips_image_new_mode().
|
* Load options may be appended to @filename as "[name=value,...]" or given as
|
||||||
|
* a NULL-terminated list of name-value pairs at the end of the arguments.
|
||||||
|
* Options given in the function call override options given in the filename.
|
||||||
|
*
|
||||||
|
* See also: vips_foreign_load(), vips_image_write_to_file().
|
||||||
*
|
*
|
||||||
* Returns: the new #VipsImage, or %NULL on error.
|
* Returns: the new #VipsImage, or %NULL on error.
|
||||||
*/
|
*/
|
||||||
VipsImage *
|
VipsImage *
|
||||||
vips_image_new_from_file( const char *filename )
|
vips_image_new_from_file( const char *name, ... )
|
||||||
{
|
{
|
||||||
return( vips_image_new_mode( filename, "r" ) );
|
char filename[VIPS_PATH_MAX];
|
||||||
|
char option_string[VIPS_PATH_MAX];
|
||||||
|
const char *operation_name;
|
||||||
|
va_list ap;
|
||||||
|
VipsImage *out;
|
||||||
|
int result;
|
||||||
|
|
||||||
|
/* Sniff the file type and select a load operation.
|
||||||
|
*/
|
||||||
|
vips__filename_split8( name, filename, option_string );
|
||||||
|
if( !(operation_name = vips_foreign_find_load( filename )) )
|
||||||
|
return( -1 );
|
||||||
|
|
||||||
|
va_start( ap, out );
|
||||||
|
result = vips_call_split_option_string( operation_name, option_string,
|
||||||
|
ap, filename, &out );
|
||||||
|
va_end( ap );
|
||||||
|
|
||||||
|
if( !result )
|
||||||
|
return( NULL );
|
||||||
|
|
||||||
|
return( out );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1973,28 +2000,39 @@ vips_image_write( VipsImage *image, VipsImage *out )
|
|||||||
/**
|
/**
|
||||||
* vips_image_write_to_file:
|
* vips_image_write_to_file:
|
||||||
* @image: image to write
|
* @image: image to write
|
||||||
* @filename: write to this file
|
* @name: write to this file
|
||||||
|
* @...: %NULL-terminated list of optional named arguments
|
||||||
*
|
*
|
||||||
* A convenience function to write @image to a file.
|
* Writes @in to @name using the saver recommended by
|
||||||
|
* vips_foreign_find_save().
|
||||||
|
*
|
||||||
|
* Save options may be appended to @name as "[name=value,...]" or given as
|
||||||
|
* a NULL-terminated list of name-value pairs at the end of the arguments.
|
||||||
|
*
|
||||||
|
* See also: vips_image_new_from_file().
|
||||||
*
|
*
|
||||||
* Returns: 0 on success, or -1 on error.
|
* Returns: 0 on success, or -1 on error.
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
vips_image_write_to_file( VipsImage *image, const char *filename )
|
vips_image_write_to_file( VipsImage *image, const char *name, ... )
|
||||||
{
|
{
|
||||||
VipsImage *out;
|
char filename[VIPS_PATH_MAX];
|
||||||
|
char option_string[VIPS_PATH_MAX];
|
||||||
|
const char *operation_name;
|
||||||
|
va_list ap;
|
||||||
|
int result;
|
||||||
|
|
||||||
g_assert( filename );
|
vips__filename_split8( name, filename, option_string );
|
||||||
|
|
||||||
if( !(out = vips_image_new_mode( filename, "w" )) )
|
if( !(operation_name = vips_foreign_find_save( filename )) )
|
||||||
return( -1 );
|
return( -1 );
|
||||||
if( vips_image_write( image, out ) ) {
|
|
||||||
g_object_unref( out );
|
|
||||||
return( -1 );
|
|
||||||
}
|
|
||||||
g_object_unref( out );
|
|
||||||
|
|
||||||
return( 0 );
|
va_start( ap, name );
|
||||||
|
result = vips_call_split_option_string( operation_name, option_string,
|
||||||
|
ap, in, filename );
|
||||||
|
va_end( ap );
|
||||||
|
|
||||||
|
return( result );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user