add vips_foreign_save_buffer()
This commit is contained in:
parent
1640f18bb7
commit
61891865bf
@ -23,7 +23,7 @@
|
||||
- support 16-bit palette TIFFs, plus palette TIFFs can have an alpha
|
||||
- add ".vips" as an alternative suffix for vips files
|
||||
- added vips_tiffload_buffer()
|
||||
- added vips_foreign_load_buffer()
|
||||
- added vips_foreign_load_buffer(), vips_foreign_save_buffer()
|
||||
|
||||
6/3/14 started 7.38.6
|
||||
- grey ramp minimum was wrong
|
||||
|
27
TODO
27
TODO
@ -1,23 +1,21 @@
|
||||
- need to be able to select savers by suffix, and set options
|
||||
- need to be able to set options for buffer save from the suffix
|
||||
|
||||
eg.
|
||||
vips_foreign_save_buffer() needs
|
||||
|
||||
vips_foreign_save_buffer( VipsImage *in, void **buf, size_t *len,
|
||||
const char *format, ... )
|
||||
- split suffix for match against class->suffs
|
||||
|
||||
format can be
|
||||
- set options from suffix
|
||||
|
||||
.jpg
|
||||
.jpg[Q=80]
|
||||
no. 2 needs something like:
|
||||
|
||||
opt can be passed in the ... as well, overriding things set in the format
|
||||
vips_object_set_options_from_string( object, "[a=12,b=13]" );
|
||||
|
||||
perhaps with the outermost brackets optional?
|
||||
|
||||
... but foreign_class->suffs is set for eg. jpegsave_file and is how we pick
|
||||
out savers from destination filenames, what can we use to pick buffer
|
||||
savers?
|
||||
maybe vips_object_set_from_string()?
|
||||
|
||||
read object.c and see how close we are to this model now
|
||||
|
||||
need some new class member to do the lookup on? .suffs_buffer?
|
||||
|
||||
- use this for dzsave_buffer
|
||||
|
||||
@ -27,6 +25,11 @@
|
||||
|
||||
deprecate this thing and stop ':' split
|
||||
|
||||
vips_foreign_find_save() should split on [], there's something to find the
|
||||
start of the rightmost [] pair, use that
|
||||
|
||||
see also vips_foreign_find_save_buffer()
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -1063,7 +1063,7 @@ vips_foreign_find_save_sub( VipsForeignSaveClass *save_class,
|
||||
* @filename may not contain embedded options. See
|
||||
* vips_foreign_find_save_options() if your filename may have options in.
|
||||
*
|
||||
* See also: vips_foreign_write().
|
||||
* See also: vips_foreign_save().
|
||||
*
|
||||
* Returns: the name of an operation on success, %NULL on error
|
||||
*/
|
||||
@ -1085,6 +1085,55 @@ vips_foreign_find_save( const char *filename )
|
||||
return( G_OBJECT_CLASS_NAME( save_class ) );
|
||||
}
|
||||
|
||||
/* Can we write this buffer with this file type?
|
||||
*/
|
||||
static void *
|
||||
vips_foreign_find_save_buffer_sub( VipsForeignSaveClass *save_class,
|
||||
const char *suffix )
|
||||
{
|
||||
VipsObjectClass *class = VIPS_OBJECT_CLASS( save_class );
|
||||
VipsForeignClass *class = VIPS_FOREIGN_CLASS( save_class );
|
||||
|
||||
if( class->suffs &&
|
||||
vips_ispostfix( class->nickname, "_buffer" ) &&
|
||||
vips_filename_suffix_match( suffix, class->suffs ) )
|
||||
return( save_class );
|
||||
|
||||
return( NULL );
|
||||
}
|
||||
|
||||
/**
|
||||
* vips_foreign_find_save_buffer:
|
||||
* @suffix: name to find a saver for
|
||||
*
|
||||
* Searches for an operation you could use to write to a buffer in @suffix
|
||||
* format.
|
||||
*
|
||||
* @filename may not contain embedded options. See
|
||||
* vips_foreign_find_save_options() if your filename may have options in.
|
||||
*
|
||||
* See also: vips_foreign_save_buffer().
|
||||
*
|
||||
* Returns: the name of an operation on success, %NULL on error
|
||||
*/
|
||||
const char *
|
||||
vips_foreign_find_save_buffer( const char *suffix )
|
||||
{
|
||||
VipsForeignSaveClass *save_class;
|
||||
|
||||
if( !(save_class = (VipsForeignSaveClass *) vips_foreign_map(
|
||||
"VipsForeignSave",
|
||||
(VipsSListMap2Fn) vips_foreign_find_save_sub,
|
||||
(void *) suffix, NULL )) ) {
|
||||
vips_error( "VipsForeignSave",
|
||||
_( "\"%s\" is not a known file format" ), suffix );
|
||||
|
||||
return( NULL );
|
||||
}
|
||||
|
||||
return( G_OBJECT_CLASS_NAME( save_class ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* vips_foreign_find_save_options:
|
||||
* @filename: name to find a saver for
|
||||
@ -1092,7 +1141,7 @@ vips_foreign_find_save( const char *filename )
|
||||
* Searches for an operation you could use to write to @filename.
|
||||
*
|
||||
* @filename may contain embedded options. See
|
||||
* vips_foreign_find_save() if your filename does not options in.
|
||||
* vips_foreign_find_save() if your filename does not have options in.
|
||||
*
|
||||
* See also: vips_foreign_write().
|
||||
*
|
||||
@ -1583,6 +1632,47 @@ vips_foreign_save( VipsImage *in, const char *filename, ... )
|
||||
return( result );
|
||||
}
|
||||
|
||||
/**
|
||||
* vips_foreign_save_buffer:
|
||||
* @in: image to write
|
||||
* @suffix: format to write
|
||||
* @buf: return buffer start here
|
||||
* @len: return buffer length here
|
||||
* @...: %NULL-terminated list of optional named arguments
|
||||
*
|
||||
* Saves @in to @filename using the saver recommended by
|
||||
* vips_foreign_find_save(). Options are not in @suffix but must be given
|
||||
* as a NULL-terminated list of name-value pairs.
|
||||
*
|
||||
* See also: vips_foreign_load_buffer().
|
||||
*
|
||||
* Returns: 0 on success, -1 on error
|
||||
*/
|
||||
int
|
||||
vips_foreign_save_buffer( VipsImage *in,
|
||||
const char *suffix, void **buf, size_t *len,
|
||||
... )
|
||||
{
|
||||
const char *operation;
|
||||
va_list ap;
|
||||
int result;
|
||||
|
||||
if( !(operation = vips_foreign_find_save_buffer( suffix )) )
|
||||
return( -1 );
|
||||
|
||||
/* We don't take a copy of the data or free it.
|
||||
*/
|
||||
area = vips_area_new_blob( NULL, buf, len );
|
||||
|
||||
va_start( ap, filename );
|
||||
result = vips_call_split( operation, ap, in, area );
|
||||
va_end( ap );
|
||||
|
||||
vips_area_unref( area );
|
||||
|
||||
return( result );
|
||||
}
|
||||
|
||||
/**
|
||||
* vips_foreign_load_options:
|
||||
* @filename: file to load
|
||||
|
@ -308,14 +308,13 @@ typedef struct _VipsForeignSaveClass {
|
||||
GType vips_foreign_save_get_type( void );
|
||||
|
||||
const char *vips_foreign_find_save( const char *filename );
|
||||
const char * vips_foreign_find_save_buffer( const char *suffix );
|
||||
const char *vips_foreign_find_save_options( const char *filename );
|
||||
|
||||
/* Read/write an image convenience functions.
|
||||
*/
|
||||
int vips_foreign_load( const char *filename, VipsImage **out, ... )
|
||||
__attribute__((sentinel));
|
||||
int vips_foreign_load_buffer( void *buf, size_t len, VipsImage **out, ... )
|
||||
__attribute__((sentinel));
|
||||
int vips_foreign_save( VipsImage *in, const char *filename, ... )
|
||||
__attribute__((sentinel));
|
||||
|
||||
@ -324,6 +323,12 @@ int vips_foreign_load_options( const char *filename, VipsImage **out, ... )
|
||||
int vips_foreign_save_options( VipsImage *in, const char *filename, ... )
|
||||
__attribute__((sentinel));
|
||||
|
||||
int vips_foreign_load_buffer( void *buf, size_t len, VipsImage **out, ... )
|
||||
__attribute__((sentinel));
|
||||
int vips_foreign_save_buffer( VipsImage *in,
|
||||
const char *suffix, void **buf, size_t *len, ... )
|
||||
__attribute__((sentinel));
|
||||
|
||||
int vips_openslideload( const char *filename, VipsImage **out, ... )
|
||||
__attribute__((sentinel));
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user