add wrap7

add a thing to wrap vips7 functions as vips8 classes

in and in use, but not yet working
This commit is contained in:
John Cupitt 2011-07-15 14:37:20 +01:00
parent 5b97d5210a
commit a9dc321afd
8 changed files with 318 additions and 209 deletions

View File

@ -72,6 +72,7 @@
- im_falsecolour() converts to mono 8-bit for you - im_falsecolour() converts to mono 8-bit for you
- im_icc_import*/export*() cast inputs for you - im_icc_import*/export*() cast inputs for you
- im_vips2tiff() uses im__temp_name() for intermediates - im_vips2tiff() uses im__temp_name() for intermediates
- added vips_wrap7 ... wrap up vips7 operations as vips8 classes
30/11/10 started 7.24.0 30/11/10 started 7.24.0
- bump for new stable - bump for new stable

7
TODO
View File

@ -1,11 +1,4 @@
- can we call vips7 funcs from the vips8 interface? we already have vips8 from
vips7
we'd have to make fake classes to wrap each operation I guesso
try wrapping for fun
- revisit orc conv - revisit orc conv

View File

@ -356,9 +356,6 @@ vips_binary_class_init( VipsBinaryClass *class )
GParamSpec *pspec; GParamSpec *pspec;
gobject_class->set_property = vips_object_set_property;
gobject_class->get_property = vips_object_get_property;
vobject_class->build = vips_binary_build; vobject_class->build = vips_binary_build;
/* Create properties. /* Create properties.

View File

@ -2,6 +2,7 @@ noinst_LTLIBRARIES = libdeprecated.la
libdeprecated_la_SOURCES = \ libdeprecated_la_SOURCES = \
deprecated_dispatch.c \ deprecated_dispatch.c \
wrapvips7.c \
im_dif_std.c \ im_dif_std.c \
im_simcontr.c \ im_simcontr.c \
im_spatres.c \ im_spatres.c \

View File

@ -31,10 +31,10 @@
*/ */
/* /*
*/
#define DEBUG #define DEBUG
#define VIPS_DEBUG #define VIPS_DEBUG
#define DEBUG_REF #define DEBUG_REF
*/
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
#include <config.h> #include <config.h>
@ -54,11 +54,15 @@
#include <dmalloc.h> #include <dmalloc.h>
#endif /*WITH_DMALLOC*/ #endif /*WITH_DMALLOC*/
#define VIPS7_PREFIX "Vips7_" #define VIPS_WRAP7_PREFIX "VipsWrap7_"
static GHashTable *vips7_types = NULL; static GHashTable *vips_wrap7_subclass_types = NULL;
typedef struct _Vips7 { /* VipsWrap7 is an abstract type ... subclass for each operation we wrap with
* no extra members.
*/
typedef struct _VipsWrap7 {
VipsOperation parent_object; VipsOperation parent_object;
/* vips7 dispatch spine we build. /* vips7 dispatch spine we build.
@ -69,9 +73,9 @@ typedef struct _Vips7 {
*/ */
gboolean error; gboolean error;
} Vips7; } VipsWrap7;
typedef struct _Vips7Class { typedef struct _VipsWrap7Class {
VipsOperationClass parent_class; VipsOperationClass parent_class;
/* Look this up from the class name. /* Look this up from the class name.
@ -82,25 +86,37 @@ typedef struct _Vips7Class {
*/ */
gboolean not_supported; gboolean not_supported;
} Vips7Class; } VipsWrap7Class;
#define VIPS_TYPE_WRAP7 (vips_wrap7_get_type())
#define VIPS_WRAP7( obj ) \
(G_TYPE_CHECK_INSTANCE_CAST( (obj), VIPS_TYPE_WRAP7, VipsWrap7 ))
#define VIPS_WRAP7_CLASS( klass ) \
(G_TYPE_CHECK_CLASS_CAST( (klass), VIPS_TYPE_WRAP7, VipsWrap7Class))
#define VIPS_IS_WRAP7( obj ) \
(G_TYPE_CHECK_INSTANCE_TYPE( (obj), VIPS_TYPE_WRAP7 ))
#define VIPS_IS_WRAP7_CLASS( klass ) \
(G_TYPE_CHECK_CLASS_TYPE( (klass), VIPS_TYPE_WRAP7 ))
#define VIPS_WRAP7_GET_CLASS( obj ) \
(G_TYPE_INSTANCE_GET_CLASS( (obj), VIPS_TYPE_WRAP7, VipsWrap7Class ))
typedef enum { typedef enum {
VIPS7_NONE = -1, VIPS_WRAP7_NONE = -1,
VIPS7_DOUBLE = 0, VIPS_WRAP7_DOUBLE = 0,
VIPS7_INT, VIPS_WRAP7_INT,
VIPS7_COMPLEX, VIPS_WRAP7_COMPLEX,
VIPS7_STRING, VIPS_WRAP7_STRING,
VIPS7_IMAGE, VIPS_WRAP7_IMAGE,
VIPS7_DOUBLEVEC, VIPS_WRAP7_DOUBLEVEC,
VIPS7_DMASK, VIPS_WRAP7_DMASK,
VIPS7_IMASK, VIPS_WRAP7_IMASK,
VIPS7_IMAGEVEC, VIPS_WRAP7_IMAGEVEC,
VIPS7_INTVEC, VIPS_WRAP7_INTVEC,
VIPS7_GVALUE, VIPS_WRAP7_GVALUE,
VIPS7_INTERPOLATE VIPS_WRAP7_INTERPOLATE
} Vips7Type; } VipsWrap7Type;
static char *vips7_supported[] = { static char *vips_wrap7_supported[] = {
IM_TYPE_DOUBLE, IM_TYPE_DOUBLE,
IM_TYPE_INT, IM_TYPE_INT,
IM_TYPE_COMPLEX, IM_TYPE_COMPLEX,
@ -117,36 +133,24 @@ static char *vips7_supported[] = {
/* Turn a vips7 type name to an enum. /* Turn a vips7 type name to an enum.
*/ */
static Vips7Type static VipsWrap7Type
vips7_lookup_type( im_arg_type type ) vips_wrap7_lookup_type( im_arg_type type )
{ {
int i; int i;
for( i = 0; i < IM_NUMBER( vips7_supported ); i++ ) for( i = 0; i < VIPS_NUMBER( vips_wrap7_supported ); i++ )
if( strcmp( type, vips7_supported[i] ) == 0 ) if( strcmp( type, vips_wrap7_supported[i] ) == 0 )
return( (Vips7Type) i ); return( (VipsWrap7Type) i );
return( VIPS7_NONE ); return( VIPS_WRAP7_NONE );
} }
static void G_DEFINE_ABSTRACT_TYPE( VipsWrap7, vips_wrap7, VIPS_TYPE_OPERATION );
vips7_dispose( GObject *gobject )
{
Vips7 *vips7 = VIPS7( gobject );
#ifdef DEBUG /* Drop any refs vargv may hold.
printf( "vips7_dispose: " );
vips_object_print_name( object );
printf( "\n" );
#endif /*DEBUG*/
G_OBJECT_CLASS( parent_class )->dispose( gobject );
}
/* Junk stuff we may have attached to vargv.
*/ */
static void static void
vips7_vargv_free( im_function *fn, im_object *vargv ) vips_wrap7_vargv_dispose( im_function *fn, im_object *vargv )
{ {
int i; int i;
@ -155,44 +159,38 @@ vips7_vargv_free( im_function *fn, im_object *vargv )
im_type_desc *type = arg->desc; im_type_desc *type = arg->desc;
im_arg_type vt = type->type; im_arg_type vt = type->type;
switch( vips7_lookup_type( vt ) ) { switch( vips_wrap7_lookup_type( vt ) ) {
case CALL_NONE: /* IM_TYPE_DISPLAY */ case VIPS_WRAP7_NONE: /* IM_TYPE_DISPLAY */
case CALL_DOUBLE: case VIPS_WRAP7_DOUBLE:
case CALL_INT: case VIPS_WRAP7_INT:
case CALL_COMPLEX: case VIPS_WRAP7_COMPLEX:
case CALL_GVALUE: case VIPS_WRAP7_DOUBLEVEC:
case CALL_INTERPOLATE: case VIPS_WRAP7_INTVEC:
case CALL_IMAGE: case VIPS_WRAP7_DMASK:
case VIPS_WRAP7_IMASK:
/* Do nothing. /* Do nothing.
*/ */
break; break;
case CALL_STRING: case VIPS_WRAP7_INTERPOLATE:
VIPS_FREE( obj ); case VIPS_WRAP7_IMAGE:
if( vargv[i] )
VIPS_UNREF( vargv[i] );
break; break;
case CALL_IMAGEVEC: case VIPS_WRAP7_IMAGEVEC:
VIPS_FREE( ((im_imagevec_object *) obj)->vec ); {
im_imagevec_object *iv = vargv[i];
int j;
for( j = 0; j < iv->n; j++ )
if( iv->vec[j] )
VIPS_UNREF( iv->vec[j] );
}
break; break;
case CALL_DOUBLEVEC: case VIPS_WRAP7_GVALUE:
VIPS_FREE( ((im_doublevec_object *) obj)->vec ); g_value_unset( vargv[i] );
break;
case CALL_INTVEC:
VIPS_FREE( ((im_intvec_object *) obj)->vec );
break;
case CALL_DMASK:
VIPS_FREE( ((im_mask_object *) obj)->name );
VIPS_FREEF( im_free_dmask,
((im_mask_object *) obj)->mask );
break;
case CALL_IMASK:
VIPS_FREE( ((im_mask_object *) obj)->name );
VIPS_FREEF( im_free_imask,
((im_mask_object *) obj)->mask );
break; break;
default: default:
@ -202,28 +200,106 @@ vips7_vargv_free( im_function *fn, im_object *vargv )
} }
static void static void
vips7_finalize( GObject *gobject ) vips_wrap7_dispose( GObject *gobject )
{ {
Vips7 *vips7 = VIPS7( gobject ); VipsWrap7 *wrap7 = VIPS_WRAP7( gobject );
Vips7Class *class = VIPS7_GET_CLASS( vips7 ); VipsWrap7Class *class = VIPS_WRAP7_GET_CLASS( wrap7 );
#ifdef DEBUG #ifdef DEBUG
printf( "vips7_finalize: " ); printf( "vips_wrap7_dispose: " );
vips_object_print_name( object ); vips_object_print_name( VIPS_OBJECT( wrap7 ) );
printf( "\n" ); printf( "\n" );
#endif /*DEBUG*/ #endif /*DEBUG*/
if( vips7->vargv ) { vips_wrap7_vargv_dispose( class->fn, wrap7->vargv );
vips7_vargv_free( class->fn, vips7->vargv )
im_free_vargv( class->fn, vips7->vargv );
VIPS_FREE( vips7->vargv );
}
G_OBJECT_CLASS( parent_class )->finalize( gobject ); G_OBJECT_CLASS( vips_wrap7_parent_class )->dispose( gobject );
}
/* Junk stuff we may have attached to vargv.
*/
static void
vips_wrap7_vargv_finalize( im_function *fn, im_object *vargv )
{
int i;
for( i = 0; i < fn->argc; i++ ) {
im_arg_desc *arg = &fn->argv[i];
im_type_desc *type = arg->desc;
im_arg_type vt = type->type;
switch( vips_wrap7_lookup_type( vt ) ) {
case VIPS_WRAP7_NONE: /* IM_TYPE_DISPLAY */
case VIPS_WRAP7_DOUBLE:
case VIPS_WRAP7_INT:
case VIPS_WRAP7_COMPLEX:
case VIPS_WRAP7_GVALUE:
case VIPS_WRAP7_INTERPOLATE:
case VIPS_WRAP7_IMAGE:
/* Do nothing.
*/
break;
case VIPS_WRAP7_STRING:
VIPS_FREE( vargv[i] );
break;
case VIPS_WRAP7_IMAGEVEC:
VIPS_FREE( ((im_imagevec_object *) vargv[i])->vec );
break;
case VIPS_WRAP7_DOUBLEVEC:
VIPS_FREE( ((im_doublevec_object *) vargv[i])->vec );
break;
case VIPS_WRAP7_INTVEC:
VIPS_FREE( ((im_intvec_object *) vargv[i])->vec );
break;
case VIPS_WRAP7_DMASK:
VIPS_FREE( ((im_mask_object *) vargv[i])->name );
VIPS_FREEF( im_free_dmask,
((im_mask_object *) vargv[i])->mask );
break;
case VIPS_WRAP7_IMASK:
VIPS_FREE( ((im_mask_object *) vargv[i])->name );
VIPS_FREEF( im_free_imask,
((im_mask_object *) vargv[i])->mask );
break;
default:
g_assert( FALSE );
}
}
} }
static void static void
vips7_object_set_property( GObject *gobject, vips_wrap7_finalize( GObject *gobject )
{
VipsWrap7 *wrap7 = VIPS_WRAP7( gobject );
VipsWrap7Class *class = VIPS_WRAP7_GET_CLASS( wrap7 );
#ifdef DEBUG
printf( "vips_wrap7_finalize: " );
vips_object_print_name( VIPS_OBJECT( wrap7 ) );
printf( "\n" );
#endif /*DEBUG*/
if( wrap7->vargv ) {
vips_wrap7_vargv_finalize( class->fn, wrap7->vargv );
im_free_vargv( class->fn, wrap7->vargv );
VIPS_FREE( wrap7->vargv );
}
G_OBJECT_CLASS( vips_wrap7_parent_class )->finalize( gobject );
}
/* Like the one in object.c, but write to vargv instead. Use offset to record
* the index in vargv we set.
*/
static void
vips_wrap7_object_set_property( GObject *gobject,
guint property_id, const GValue *value, GParamSpec *pspec ) guint property_id, const GValue *value, GParamSpec *pspec )
{ {
VipsObject *object = VIPS_OBJECT( gobject ); VipsObject *object = VIPS_OBJECT( gobject );
@ -233,8 +309,8 @@ vips7_object_set_property( GObject *gobject,
VipsArgumentInstance *argument_instance = VipsArgumentInstance *argument_instance =
vips__argument_get_instance( argument_class, object ); vips__argument_get_instance( argument_class, object );
Vips7 *vips7 = VIPS7( gobject ); VipsWrap7 *wrap7 = VIPS_WRAP7( gobject );
Vips7Class *class = VIPS7_GET_CLASS( vips7 ); VipsWrap7Class *class = VIPS_WRAP7_GET_CLASS( wrap7 );
int i = argument_class->offset; int i = argument_class->offset;
im_arg_desc *arg = &class->fn->argv[i]; im_arg_desc *arg = &class->fn->argv[i];
im_type_desc *type = arg->desc; im_type_desc *type = arg->desc;
@ -286,30 +362,38 @@ vips7_object_set_property( GObject *gobject,
return; return;
} }
switch( vips7_lookup_type( vt ) ) { switch( vips_wrap7_lookup_type( vt ) ) {
case VIPS7_DOUBLE: case VIPS_WRAP7_DOUBLE:
*((double*)vi->vargv[i]) = g_value_get_double( value ); *((double*)wrap7->vargv[i]) = g_value_get_double( value );
break; break;
case VIPS7_INT: case VIPS_WRAP7_INT:
*((int*)vi->vargv[i]) = g_value_get_int( value ); *((int*)wrap7->vargv[i]) = g_value_get_int( value );
break; break;
case VIPS7_STRING: case VIPS_WRAP7_STRING:
VIPS_SETSTR( vi->vargv[i], g_value_get_string( value ) ); VIPS_SETSTR( wrap7->vargv[i], g_value_get_string( value ) );
break; break;
case VIPS7_GVALUE: case VIPS_WRAP7_GVALUE:
vi->vargv[i] = value; g_value_init( wrap7->vargv[i], G_VALUE_TYPE( value ) );
g_value_copy( value, wrap7->vargv[i] );
break; break;
case VIPS7_IMAGE: case VIPS_WRAP7_IMAGE:
case VIPS7_INTERPOLATE: case VIPS_WRAP7_INTERPOLATE:
vi->vargv[i] = g_value_get_object( value ); /* This does not add a ref to object.
*/
wrap7->vargv[i] = g_value_get_object( value );
/* Now ref the object this operation refs. Drop this ref in
* _dispose(), see above.
*/
g_object_ref( g_value_get_object( value ) );
break; break;
default: default:
vips7->error = TRUE; wrap7->error = TRUE;
break; break;
} }
@ -319,18 +403,20 @@ vips7_object_set_property( GObject *gobject,
} }
static void static void
vips7_object_get_property( GObject *gobject, vips_wrap7_object_get_property( GObject *gobject,
guint property_id, GValue *value, GParamSpec *pspec ) guint property_id, GValue *value, GParamSpec *pspec )
{ {
VipsObject *object = VIPS_OBJECT( gobject ); VipsObject *object = VIPS_OBJECT( gobject );
VipsObjectClass *class = VIPS_OBJECT_GET_CLASS( gobject ); VipsObjectClass *class = VIPS_OBJECT_GET_CLASS( gobject );
VipsArgumentClass *argument_class = (VipsArgumentClass *) VipsArgumentClass *argument_class = (VipsArgumentClass *)
vips__argument_table_lookup( class->argument_table, pspec ); vips__argument_table_lookup( class->argument_table, pspec );
VipsArgumentInstance *argument_instance =
vips__argument_get_instance( argument_class, object );
Vips7 *vips7 = VIPS7( gobject ); VipsWrap7 *wrap7 = VIPS_WRAP7( gobject );
Vips7Class *class = VIPS7_GET_CLASS( vips7 ); VipsWrap7Class *wclass = VIPS_WRAP7_GET_CLASS( wrap7 );
int i = argument_class->offset; int i = argument_class->offset;
im_arg_desc *arg = &class->fn->argv[i]; im_arg_desc *arg = &wclass->fn->argv[i];
im_type_desc *type = arg->desc; im_type_desc *type = arg->desc;
im_arg_type vt = type->type; im_arg_type vt = type->type;
@ -350,23 +436,23 @@ vips7_object_get_property( GObject *gobject,
return; return;
} }
switch( vips7_lookup_type( vt ) ) { switch( vips_wrap7_lookup_type( vt ) ) {
case VIPS7_DOUBLE: case VIPS_WRAP7_DOUBLE:
g_value_set_double( value, *((double*)vi->vargv[i]) ); g_value_set_double( value, *((double*)wrap7->vargv[i]) );
break; break;
case VIPS7_INT: case VIPS_WRAP7_INT:
g_value_set_int( value, *((int*)vi->vargv[i]) ); g_value_set_int( value, *((int*)wrap7->vargv[i]) );
break; break;
case VIPS7_STRING: case VIPS_WRAP7_STRING:
g_value_set_string( value, vi->vargv[i] ); g_value_set_string( value, wrap7->vargv[i] );
break; break;
case VIPS7_IMAGE: case VIPS_WRAP7_IMAGE:
case VIPS7_INTERPOLATE: case VIPS_WRAP7_INTERPOLATE:
case VIPS7_GVALUE: case VIPS_WRAP7_GVALUE:
g_value_set_object( value, vi->vargv[i] ); g_value_set_object( value, wrap7->vargv[i] );
break; break;
default: default:
@ -379,59 +465,58 @@ vips7_object_get_property( GObject *gobject,
} }
static int static int
vips7_build( VipsObject *object ) vips_wrap7_build( VipsObject *object )
{ {
Vips7 *vips7 = VIPS_VIPS7( object ); VipsWrap7 *wrap7 = VIPS_WRAP7( object );
Vips7Class *class = VIPS7_GET_CLASS( vips7 ); VipsWrap7Class *class = VIPS_WRAP7_GET_CLASS( wrap7 );
im_function *fn = class->fn; VipsObjectClass *oclass = VIPS_OBJECT_CLASS( class );
if( vips7->error ) { if( wrap7->error ) {
vips_error( "vips7", vips_error( "wrap7",
_( "error constructing vips7 operation %s" ), _( "error constructing vips7 operation %s" ),
class->nickname ); oclass->nickname );
return( -1 ); return( -1 );
} }
if( class->not_supported ) { if( class->not_supported ) {
vips_error( "vips7", _( "unable to call vips7 operation " vips_error( "wrap7", _( "unable to call vips7 operation "
"%s from vips8" ), class->nickname ); "%s from vips8" ), oclass->nickname );
return( -1 ); return( -1 );
} }
if( VIPS_OBJECT_CLASS( parent_class )->build( object ) ) if( VIPS_OBJECT_CLASS( vips_wrap7_parent_class )->build( object ) )
return( -1 ); return( -1 );
if( fn->disp( vips7->vargv ) ) if( class->fn->disp( wrap7->vargv ) )
return( -1 ); return( -1 );
return( 0 ); return( 0 );
} }
static void static void
vips7_class_init( VipsVips7Class *class ) vips_wrap7_class_init( VipsWrap7Class *class )
{ {
GObjectClass *gobject_class = (GObjectClass *) class;
VipsObjectClass *vobject_class = (VipsObjectClass *) class;
/* The name of the vips operation we wrap is hidden in our class name. /* The name of the vips operation we wrap is hidden in our class name.
*/ */
const char *name = G_OBJECT_CLASS_NAME( class ) + const char *name = G_OBJECT_CLASS_NAME( class ) +
strlen( VIPS7_PREFIX ); strlen( VIPS_WRAP7_PREFIX );
VipsObjectClass *object_class = (VipsObjectClass *) class;
VipsOperationClass *oclass = VIPS_OPERATION_CLASS( class );
im_function *fn = im_find_function( name ); im_function *fn = im_find_function( name );
int i; int i;
g_assert( fn ); g_assert( fn );
gobject_class->dispose = vips7_dispose; gobject_class->dispose = vips_wrap7_dispose;
gobject_class->finalize = vips7_finalize; gobject_class->finalize = vips_wrap7_finalize;
gobject_class->set_property = vips7_object_set_property; gobject_class->set_property = vips_wrap7_object_set_property;
gobject_class->get_property = vips7_object_get_property; gobject_class->get_property = vips_wrap7_object_get_property;
object_class->build = vips7_build; vobject_class->build = vips_wrap7_build;
object_class->nickname = name; vobject_class->nickname = name;
object_class->description = fn->desc; vobject_class->description = fn->desc;
class->fn = fn; class->fn = fn;
@ -442,26 +527,26 @@ vips7_class_init( VipsVips7Class *class )
GParamSpec *pspec; GParamSpec *pspec;
switch( vips7_lookup_type( vt ) ) { switch( vips_wrap7_lookup_type( vt ) ) {
case VIPS7_DOUBLEVEC: case VIPS_WRAP7_DOUBLEVEC:
case VIPS7_DMASK: case VIPS_WRAP7_DMASK:
case VIPS7_IMASK: case VIPS_WRAP7_IMASK:
case VIPS7_IMAGEVEC: case VIPS_WRAP7_IMAGEVEC:
case VIPS7_INTVEC: case VIPS_WRAP7_INTVEC:
case VIPS7_GVALUE: case VIPS_WRAP7_GVALUE:
case VIPS7_INTERPOLATE: case VIPS_WRAP7_INTERPOLATE:
case VIPS7_DOUBLE: case VIPS_WRAP7_DOUBLE:
case VIPS7_INT: case VIPS_WRAP7_INT:
case VIPS7_COMPLEX: case VIPS_WRAP7_COMPLEX:
case VIPS7_STRING: case VIPS_WRAP7_STRING:
case VIPS7_NONE: case VIPS_WRAP7_NONE:
/* Can't wrap this function. class_init can't fail, so /* Can't wrap this function. class_init can't fail, so
* set a flag to block _build(). * set a flag to block _build().
*/ */
class->not_supported = TRUE; class->not_supported = TRUE;
break; break;
case VIPS7_IMAGE: case VIPS_WRAP7_IMAGE:
pspec = g_param_spec_object( arg->name, pspec = g_param_spec_object( arg->name,
arg->name, arg->name,
arg->name, arg->name,
@ -484,11 +569,10 @@ vips7_class_init( VipsVips7Class *class )
} }
static void static void
vips7_arg_close( GObject *argument, vips_wrap7_arg_close( GObject *argument,
VipsArgumentInstance *argument_instance ) VipsArgumentInstance *argument_instance )
{ {
VipsObject *object = argument_instance->object; VipsObject *object = argument_instance->object;
GParamSpec *pspec = ((VipsArgument *) argument_instance)->pspec;
g_object_unref( object ); g_object_unref( object );
} }
@ -496,14 +580,14 @@ vips7_arg_close( GObject *argument,
/* Init an output slot in vargv. /* Init an output slot in vargv.
*/ */
static void * static void *
vips7_build_output( VipsObject *object, vips_wrap7_build_output( VipsObject *object,
GParamSpec *pspec, GParamSpec *pspec,
VipsArgumentClass *argument_class, VipsArgumentClass *argument_class,
VipsArgumentInstance *argument_instance, VipsArgumentInstance *argument_instance,
void *a, void *b ) void *a, void *b )
{ {
Vips7 *vips7 = VIPS7( object ); VipsWrap7 *wrap7 = VIPS_WRAP7( object );
Vips7Class *class = VIPS7_GET_CLASS( vips7 ); VipsWrap7Class *class = VIPS_WRAP7_GET_CLASS( wrap7 );
int i = argument_class->offset; int i = argument_class->offset;
im_arg_desc *arg = &class->fn->argv[i]; im_arg_desc *arg = &class->fn->argv[i];
im_type_desc *type = arg->desc; im_type_desc *type = arg->desc;
@ -519,31 +603,31 @@ vips7_build_output( VipsObject *object,
/* Provide output objects for the operation to write to. /* Provide output objects for the operation to write to.
*/ */
switch( vips7_lookup_type( vt ) ) { switch( vips_wrap7_lookup_type( vt ) ) {
case VIPS7_DOUBLE: case VIPS_WRAP7_DOUBLE:
case VIPS7_INT: case VIPS_WRAP7_INT:
case VIPS7_COMPLEX: case VIPS_WRAP7_COMPLEX:
case VIPS7_STRING: case VIPS_WRAP7_STRING:
break; break;
case VIPS7_IMAGE: case VIPS_WRAP7_IMAGE:
/* Output objects ref this operation. /* Output objects ref this operation.
*/ */
vips7->vargv[i] = vips_image_new(); wrap7->vargv[i] = vips_image_new();
g_object_ref( vips7 ); g_object_ref( wrap7 );
/* vipsobject will handle close_id disconnect for us. /* vipsobject will handle close_id disconnect for us.
*/ */
argument_instance->close_id = argument_instance->close_id =
g_signal_connect( *member, "close", g_signal_connect( wrap7->vargv[i], "close",
G_CALLBACK( vips7_arg_close ), G_CALLBACK( vips_wrap7_arg_close ),
argument_instance ); argument_instance );
break; break;
case VIPS7_DMASK: case VIPS_WRAP7_DMASK:
case VIPS7_IMASK: case VIPS_WRAP7_IMASK:
{ {
im_mask_object *mo = vips7->vargv[i]; im_mask_object *mo = wrap7->vargv[i];
mo->mask = NULL; mo->mask = NULL;
mo->name = im_strdup( NULL, "" ); mo->name = im_strdup( NULL, "" );
@ -551,21 +635,21 @@ vips7_build_output( VipsObject *object,
break; break;
} }
case VIPS7_GVALUE: case VIPS_WRAP7_GVALUE:
{ {
GValue *value = vips7->vargv[i]; GValue *value = wrap7->vargv[i];
memset( value, 0, sizeof( GValue ) ); memset( value, 0, sizeof( GValue ) );
break; break;
} }
case VIPS7_DOUBLEVEC: case VIPS_WRAP7_DOUBLEVEC:
case VIPS7_INTVEC: case VIPS_WRAP7_INTVEC:
{ {
/* intvec is also int + pointer. /* intvec is also int + pointer.
*/ */
im_doublevec_object *dv = vips7->vargv[i]; im_doublevec_object *dv = wrap7->vargv[i];
dv->n = 0; dv->n = 0;
dv->vec = NULL; dv->vec = NULL;
@ -574,7 +658,7 @@ vips7_build_output( VipsObject *object,
} }
default: default:
vips7->error = TRUE; wrap7->error = TRUE;
break; break;
} }
@ -582,60 +666,85 @@ vips7_build_output( VipsObject *object,
} }
static void static void
vips7_init( VipsVips7 *vips7 ) vips_wrap7_init( VipsWrap7 *wrap7 )
{ {
Vips7Class *class = VIPS7_GET_CLASS( vips7 ); VipsWrap7Class *class = VIPS_WRAP7_GET_CLASS( wrap7 );
im_function *fn = class->fn; im_function *fn = class->fn;
if( !(vips7->vargv = IM_ARRAY( NULL, fn->argc + 1, im_object )) || if( !(wrap7->vargv = IM_ARRAY( NULL, fn->argc + 1, im_object )) ||
im_allocate_vargv( vi->fn, vi->vargv ) ) { im_allocate_vargv( fn, wrap7->vargv ) ) {
vips7->error = TRUE; wrap7->error = TRUE;
return; return;
} }
/* Init all the output args. /* Init all the output args.
*/ */
(void) vips_argument_map( VIPS_OBJECT( vips7 ), (void) vips_argument_map( VIPS_OBJECT( wrap7 ),
vips_call_char_option, vips_wrap7_build_output,
(void *) name, (void *) value ); NULL, NULL );
}
/* Build a subclass of vips7 for every vips7 operation.
*/
static void
vips_wrap7_subclass_class_init( VipsWrap7Class *class )
{
}
static void
vips_wrap7_subclass_init( VipsWrap7 *wrap7 )
{
} }
static GType static GType
vips7_get_type( im_function *fn ) vips_wrap7_subclass_get_type( im_function *fn )
{ {
static const GTypeInfo info = { static const GTypeInfo info = {
sizeof( VipsVips7Class ), sizeof( VipsWrap7Class ),
NULL, /* base_init */ NULL, /* base_init */
NULL, /* base_finalize */ NULL, /* base_finalize */
(GClassInitFunc) vips_vips7_class_init, (GClassInitFunc) vips_wrap7_subclass_class_init,
NULL, /* class_finalize */ NULL, /* class_finalize */
NULL, /* class_data */ NULL, /* class_data */
sizeof( VipsVips7 ), sizeof( VipsWrap7 ),
32, /* n_preallocs */ 32, /* n_preallocs */
(GInstanceInitFunc) vips_vips7_init, (GInstanceInitFunc) vips_wrap7_subclass_init,
}; };
char name[256]; char name[256];
GType type; GType type;
if( !vips7_types ) if( !vips_wrap7_subclass_types )
vips7_types = g_hash_table_new( g_direct_hash, g_direct_equal ); vips_wrap7_subclass_types =
g_hash_table_new( g_direct_hash, g_direct_equal );
if( (type = g_hash_table_lookup( vips7_types, fn )) ) if( (type = (GType)
g_hash_table_lookup( vips_wrap7_subclass_types, fn )) )
return( type ); return( type );
im_snprintf( name, 256, VIPS7_PREFIX "%s", fn->name ); im_snprintf( name, 256, VIPS_WRAP7_PREFIX "%s", fn->name );
type = g_type_register_static( VIPS_OPERATION, name, &info, 0 ); type = g_type_register_static( VIPS_TYPE_WRAP7, name, &info, 0 );
g_hash_table_insert( vips7_types, fn, type ); g_hash_table_insert( vips_wrap7_subclass_types, fn, (gpointer) type );
return( type ); return( type );
} }
static void *
vips_wrap7_build_package( im_package *package )
{
int i;
for( i = 0; i < package->nfuncs; i++ )
(void) vips_wrap7_subclass_get_type( package->table[i] );
/* Walk the whole of the vips7 operation table building classes. return( NULL );
}
/* Walk the whole of the vips7 operation table building classes.
*/ */
void void
vips__init_vips7_classes( void ) vips__init_wrap7_classes( void )
{ {
(void) im_map_packages( (VSListMap2Fn) vips_wrap7_build_package, NULL );
} }

View File

@ -261,6 +261,10 @@ VipsImage *im__inplace_base( const char *domain,
*/ */
void vips__interpolate_init( void ); void vips__interpolate_init( void );
/* Register wrappers for all the vips7 operations.
*/
void vips__init_wrap7_classes( void );
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif /*__cplusplus*/ #endif /*__cplusplus*/

View File

@ -36,7 +36,7 @@ extern "C" {
/* Handy! /* Handy!
*/ */
#define VIPS_UNREF( O ) VIPS_FREEF( g_object_unref, (O) ) #define VIPS_UNREF( X ) VIPS_FREEF( g_object_unref, (X) )
typedef struct _VipsObject VipsObject; typedef struct _VipsObject VipsObject;
typedef struct _VipsObjectClass VipsObjectClass; typedef struct _VipsObjectClass VipsObjectClass;

View File

@ -245,6 +245,10 @@ vips_init( const char *argv0 )
vips_error_clear(); vips_error_clear();
} }
/* Build classes which wrap old vips7 operations.
*/
vips__init_wrap7_classes();
/* Start up the buffer cache. /* Start up the buffer cache.
*/ */
vips__buffer_init(); vips__buffer_init();