hooked up CLI input args to VipsFile
this now works woo $ vips copy babe.jpg{shrink=4} x2.v output args next
This commit is contained in:
parent
8ee5f36d4b
commit
d6240ac11a
8
TODO
8
TODO
@ -1,6 +1,10 @@
|
||||
- CLI stuff image->new_from_string() needs to use new system too, check this
|
||||
- test ref counting in vips_object_set_argument_from_string() VipsFile stuff
|
||||
|
||||
add path for output images, see vips_object_get_argument_to_string()
|
||||
|
||||
|
||||
|
||||
|
||||
savers need it too ... image->output_to_arg()
|
||||
|
||||
make compat wrappers for old im_jpeg2vips() and im_vips2jpeg()
|
||||
|
||||
|
@ -364,6 +364,77 @@ vips_file_load_print_class( VipsObjectClass *object_class, VipsBuf *buf )
|
||||
vips_buf_appends( buf, ", load" );
|
||||
}
|
||||
|
||||
/* Can this VipsFile open this file?
|
||||
*/
|
||||
static void *
|
||||
vips_file_load_new_from_file_sub( VipsFileLoadClass *load_class,
|
||||
const char *filename )
|
||||
{
|
||||
VipsFileClass *class = VIPS_FILE_CLASS( load_class );
|
||||
|
||||
if( load_class->is_a ) {
|
||||
if( load_class->is_a( filename ) )
|
||||
return( load_class );
|
||||
}
|
||||
else if( vips_filename_suffix_match( filename, class->suffs ) )
|
||||
return( load_class );
|
||||
|
||||
return( NULL );
|
||||
}
|
||||
|
||||
/**
|
||||
* vips_file_find_load:
|
||||
* @filename: file to find a file for
|
||||
*
|
||||
* Searches for an operation you could use to load a file.
|
||||
*
|
||||
* See also: vips_file_read().
|
||||
*
|
||||
* Returns: the nmae of an operation on success, %NULL on error
|
||||
*/
|
||||
const char *
|
||||
vips_file_find_load( const char *filename )
|
||||
{
|
||||
VipsFileLoadClass *load_class;
|
||||
|
||||
if( !vips_existsf( "%s", filename ) ) {
|
||||
vips_error( "VipsFileLoad",
|
||||
_( "file \"%s\" not found" ), filename );
|
||||
return( NULL );
|
||||
}
|
||||
|
||||
if( !(load_class = (VipsFileLoadClass *) vips_file_map(
|
||||
"VipsFileLoad",
|
||||
(VipsSListMap2Fn) vips_file_load_new_from_file_sub,
|
||||
(void *) filename, NULL )) ) {
|
||||
vips_error( "VipsFileLoad",
|
||||
_( "file \"%s\" not a known file" ), filename );
|
||||
return( NULL );
|
||||
}
|
||||
|
||||
return( G_OBJECT_CLASS_NAME( load_class ) );
|
||||
}
|
||||
|
||||
static VipsObject *
|
||||
vips_file_load_new_from_string( const char *string )
|
||||
{
|
||||
const char *file_op;
|
||||
GType type;
|
||||
VipsFileLoad *load;
|
||||
|
||||
if( !(file_op = vips_file_find_load( string )) )
|
||||
return( NULL );
|
||||
type = g_type_from_name( file_op );
|
||||
g_assert( type );
|
||||
|
||||
load = VIPS_FILE_LOAD( g_object_new( type, NULL ) );
|
||||
g_object_set( load,
|
||||
"filename", string,
|
||||
NULL );
|
||||
|
||||
return( VIPS_OBJECT( load ) );
|
||||
}
|
||||
|
||||
static size_t
|
||||
vips_get_disc_threshold( void )
|
||||
{
|
||||
@ -508,10 +579,11 @@ vips_file_load_class_init( VipsFileLoadClass *class )
|
||||
gobject_class->set_property = vips_object_set_property;
|
||||
gobject_class->get_property = vips_object_get_property;
|
||||
|
||||
object_class->build = vips_file_load_build;
|
||||
object_class->print_class = vips_file_load_print_class;
|
||||
object_class->new_from_string = vips_file_load_new_from_string;
|
||||
object_class->nickname = "fileload";
|
||||
object_class->description = _( "file loaders" );
|
||||
object_class->print_class = vips_file_load_print_class;
|
||||
object_class->build = vips_file_load_build;
|
||||
|
||||
VIPS_ARG_IMAGE( class, "out", 2,
|
||||
_( "Output" ),
|
||||
@ -541,57 +613,6 @@ vips_file_load_init( VipsFileLoad *load )
|
||||
load->disc = TRUE;
|
||||
}
|
||||
|
||||
/* Can this file open this file?
|
||||
*/
|
||||
static void *
|
||||
vips_file_load_new_from_file_sub( VipsFileLoadClass *load_class,
|
||||
const char *filename )
|
||||
{
|
||||
VipsFileClass *class = VIPS_FILE_CLASS( load_class );
|
||||
|
||||
if( load_class->is_a ) {
|
||||
if( load_class->is_a( filename ) )
|
||||
return( load_class );
|
||||
}
|
||||
else if( vips_filename_suffix_match( filename, class->suffs ) )
|
||||
return( load_class );
|
||||
|
||||
return( NULL );
|
||||
}
|
||||
|
||||
/**
|
||||
* vips_file_find_load:
|
||||
* @filename: file to find a file for
|
||||
*
|
||||
* Searches for an operation you could use to load a file.
|
||||
*
|
||||
* See also: vips_file_read().
|
||||
*
|
||||
* Returns: the nmae of an operation on success, %NULL on error
|
||||
*/
|
||||
const char *
|
||||
vips_file_find_load( const char *filename )
|
||||
{
|
||||
VipsFileLoadClass *load_class;
|
||||
|
||||
if( !vips_existsf( "%s", filename ) ) {
|
||||
vips_error( "VipsFileLoad",
|
||||
_( "file \"%s\" not found" ), filename );
|
||||
return( NULL );
|
||||
}
|
||||
|
||||
if( !(load_class = (VipsFileLoadClass *) vips_file_map(
|
||||
"VipsFileLoad",
|
||||
(VipsSListMap2Fn) vips_file_load_new_from_file_sub,
|
||||
(void *) filename, NULL )) ) {
|
||||
vips_error( "VipsFileLoad",
|
||||
_( "file \"%s\" not a known file" ), filename );
|
||||
return( NULL );
|
||||
}
|
||||
|
||||
return( G_OBJECT_CLASS_NAME( load_class ) );
|
||||
}
|
||||
|
||||
/* Abstract base class for image savers.
|
||||
*/
|
||||
|
||||
|
@ -578,13 +578,11 @@ vips_image_build( VipsObject *object )
|
||||
*/
|
||||
switch( mode[0] ) {
|
||||
case 'v':
|
||||
native:
|
||||
/* Used by 'r' for native open of vips, see below.
|
||||
*/
|
||||
if( vips_image_open_input( image ) )
|
||||
return( -1 );
|
||||
|
||||
if( mode[1] == 'w' )
|
||||
image->dtype = VIPS_IMAGE_MMAPINRW;
|
||||
|
||||
break;
|
||||
|
||||
case 'r':
|
||||
@ -594,11 +592,12 @@ vips_image_build( VipsObject *object )
|
||||
guint32 us = vips_amiMSBfirst() ?
|
||||
VIPS_MAGIC_INTEL : VIPS_MAGIC_SPARC;
|
||||
|
||||
if( magic == us )
|
||||
/* Native byte order .. open directly into
|
||||
* this image.
|
||||
if( magic == us ) {
|
||||
/* Native open.
|
||||
*/
|
||||
goto native;
|
||||
if( vips_image_open_input( image ) )
|
||||
return( -1 );
|
||||
}
|
||||
else {
|
||||
VipsImage *t;
|
||||
VipsImage *t2;
|
||||
|
@ -1231,19 +1231,51 @@ vips_object_set_argument_from_string( VipsObject *object,
|
||||
|
||||
g_assert( argument_class->flags & VIPS_ARGUMENT_INPUT );
|
||||
|
||||
if( g_type_is_a( otype, VIPS_TYPE_OBJECT ) &&
|
||||
(oclass = g_type_class_ref( otype )) ) {
|
||||
VipsObject *object;
|
||||
if( g_type_is_a( otype, VIPS_TYPE_IMAGE ) &&
|
||||
(oclass = g_type_class_ref( VIPS_TYPE_FILE_LOAD )) ) {
|
||||
VipsObject *new_object;
|
||||
VipsImage *out;
|
||||
|
||||
if( !(object = vips_object_new_from_string( oclass, value )) )
|
||||
/* Use VipsFile to build images, then pull 'out' from it and
|
||||
* set that to set the value.
|
||||
*/
|
||||
if( !(new_object =
|
||||
vips_object_new_from_string( oclass, value )) )
|
||||
return( -1 );
|
||||
|
||||
g_object_get( new_object, "out", &out, NULL );
|
||||
|
||||
/* Getting 'out' will have upped it's count and we want to
|
||||
* hold the only ref to it.
|
||||
*/
|
||||
g_object_unref( out );
|
||||
|
||||
/* 'out' holds a ref to new_object, we can drop ours.
|
||||
*/
|
||||
g_object_unref( new_object );
|
||||
|
||||
g_value_init( &gvalue, VIPS_TYPE_IMAGE );
|
||||
g_value_set_object( &gvalue, out );
|
||||
|
||||
/* Setting gvalue will have upped out's count again,
|
||||
* go back to 1 so that gvalue has the only ref.
|
||||
*/
|
||||
g_object_unref( out );
|
||||
}
|
||||
else if( g_type_is_a( otype, VIPS_TYPE_OBJECT ) &&
|
||||
(oclass = g_type_class_ref( otype )) ) {
|
||||
VipsObject *new_object;
|
||||
|
||||
if( !(new_object =
|
||||
vips_object_new_from_string( oclass, value )) )
|
||||
return( -1 );
|
||||
|
||||
g_value_init( &gvalue, G_TYPE_OBJECT );
|
||||
g_value_set_object( &gvalue, object );
|
||||
g_value_set_object( &gvalue, new_object );
|
||||
|
||||
/* The GValue now has a ref, we can drop ours.
|
||||
*/
|
||||
g_object_unref( object );
|
||||
g_object_unref( new_object );
|
||||
}
|
||||
else if( G_IS_PARAM_SPEC_BOOLEAN( pspec ) ) {
|
||||
gboolean b;
|
||||
|
Loading…
x
Reference in New Issue
Block a user