VipsInsert is working

but array_double from CLI still needs work, see TODO
This commit is contained in:
John Cupitt 2011-10-23 22:05:21 +01:00
parent 2c4cbedc70
commit a5b8a21a54
6 changed files with 90 additions and 44 deletions

20
TODO
View File

@ -1,3 +1,23 @@
- at the moment background is VIPS_TYPE_ARRAY_DOUBLE (a type created with
g_boxed_type_register_static()) stored in a paramspec created with
g_param_spec_boxed()
this means we will need a lot of
if( G_IS_PARAM_SPEC_BOXED( pspec ) &&
(G_PARAM_SPEC_VALUE_TYPE( pspec ) == VIPS_TYPE_ARRAY_DOUBLE ||
G_PARAM_SPEC_VALUE_TYPE( pspec ) == VIPS_TYPE_ARRAY_INT ||
...
to spot vector args, since we don't have the idea of generic vector in the
type system
instead, perhaps derive from G_TYPE_PARAM_BOXED to create
VIPS_TYPE_PARAM_ARRAY, a boxed param that can only be a VipsArea array ...
would this work?

View File

@ -142,6 +142,18 @@ typedef VipsConversionClass VipsInsertClass;
G_DEFINE_TYPE( VipsInsert, vips_insert, VIPS_TYPE_CONVERSION );
static void
vips_insert_dispose( GObject *gobject )
{
VipsInsert *insert = (VipsInsert *) gobject;
VIPS_DEBUG_MSG( "vips_insert_dispose: " );
VIPS_FREEF( vips_area_unref, insert->background );
G_OBJECT_CLASS( vips_insert_parent_class )->dispose( gobject );
}
/* Trivial case: we just need pels from one of the inputs.
*/
static int
@ -253,7 +265,7 @@ vips__vector_to_ink( const char *domain, VipsImage *im, double *vec, int n )
if( vips_check_vector( domain, n, im ) )
return( NULL );
if( vips_image_new_array( VIPS_OBJECT( im ), t, 3 ) ||
if( im_open_local_array( im, t, 3, "vtoi", "t" ) ||
!(zeros = VIPS_ARRAY( im, n, double )) )
return( NULL );
for( i = 0; i < n; i++ )
@ -268,7 +280,7 @@ vips__vector_to_ink( const char *domain, VipsImage *im, double *vec, int n )
}
/* xy range we sanity check on ... just to stop crazy numbers from 1/0 etc.
* causing assert() failures later.
* causing g_assert() failures later.
*/
#define RANGE (100000000)
@ -374,6 +386,7 @@ vips_insert_class_init( VipsInsertClass *class )
VIPS_DEBUG_MSG( "vips_insert_class_init\n" );
gobject_class->dispose = vips_insert_dispose;
gobject_class->set_property = vips_object_set_property;
gobject_class->get_property = vips_object_get_property;
@ -427,6 +440,9 @@ vips_insert_init( VipsInsert *insert )
{
/* Init our instance fields.
*/
insert->background =
vips_area_new_array( G_TYPE_DOUBLE, sizeof( double ), 1 );
((double *) (insert->background->data))[0] = 0.0;
}
int

View File

@ -167,6 +167,9 @@ void vips_save_string_setf( GValue *value, const char *fmt, ... )
*/
#define VIPS_TYPE_AREA (vips_area_get_type())
GType vips_area_get_type( void );
VipsArea *vips_area_new_array( GType type, size_t sizeof_type, int n );
void vips_area_unref( VipsArea *area );
VipsArea *vips_area_copy( VipsArea *area );
/**
* VIPS_TYPE_REF_STRING:

View File

@ -49,8 +49,9 @@
*/
/*
#define VIPS_DEBUG
*/
#define VIPS_DEBUG
#define DEBUG
#ifdef HAVE_CONFIG_H
#include <config.h>
@ -1059,29 +1060,48 @@ area_new_blob( VipsCallbackFn free_fn, void *blob, size_t blob_length )
return( area );
}
static VipsArea *
area_copy( VipsArea *area )
/* An area which holds a copy of an array of elements of some GType.
*/
VipsArea *
vips_area_new_array( GType type, size_t sizeof_type, int n )
{
VipsArea *area;
void *array;
array = g_malloc( n * sizeof_type );
if( !(area = area_new( (VipsCallbackFn) g_free, array )) )
return( NULL );
area->n = n;
area->length = n * sizeof_type;
area->type = G_TYPE_DOUBLE;
area->sizeof_type = sizeof_type;
return( area );
}
VipsArea *
vips_area_copy( VipsArea *area )
{
g_assert( area->count >= 0 );
area->count += 1;
#ifdef DEBUG
printf( "area_copy: %p count = %d\n", area, area->count );
printf( "vips_area_copy: %p count = %d\n", area, area->count );
#endif /*DEBUG*/
return( area );
}
static void
area_unref( VipsArea *area )
void
vips_area_unref( VipsArea *area )
{
g_assert( area->count > 0 );
area->count -= 1;
#ifdef DEBUG
printf( "area_unref: %p count = %d\n", area, area->count );
printf( "vips_area_unref: %p count = %d\n", area, area->count );
#endif /*DEBUG*/
if( area->count == 0 && area->free_fn ) {
@ -1091,7 +1111,7 @@ area_unref( VipsArea *area )
#ifdef DEBUG
area_number -= 1;
printf( "area_unref: free .. total = %d\n", area_number );
printf( "vips_area_unref: free .. total = %d\n", area_number );
#endif /*DEBUG*/
}
}
@ -1117,8 +1137,8 @@ vips_area_get_type( void )
if( !type ) {
type = g_boxed_type_register_static( "vips_area",
(GBoxedCopyFunc) area_copy,
(GBoxedFreeFunc) area_unref );
(GBoxedCopyFunc) vips_area_copy,
(GBoxedFreeFunc) vips_area_unref );
g_value_register_transform_func(
type,
G_TYPE_STRING,
@ -1140,7 +1160,7 @@ value_set_area( VipsCallbackFn free_fn, void *data, GValue *value )
g_value_init( value, VIPS_TYPE_AREA );
g_value_set_boxed( value, area );
area_unref( area );
vips_area_unref( area );
return( 0 );
}
@ -1298,7 +1318,7 @@ vips_ref_string_set( GValue *value, const char *str )
area->length = strlen( str );
g_value_set_boxed( value, area );
area_unref( area );
vips_area_unref( area );
return( 0 );
}
@ -1339,8 +1359,8 @@ vips_ref_string_get_type( void )
if( !type ) {
type = g_boxed_type_register_static( "vips_ref_string",
(GBoxedCopyFunc) area_copy,
(GBoxedFreeFunc) area_unref );
(GBoxedCopyFunc) vips_area_copy,
(GBoxedFreeFunc) vips_area_unref );
g_value_register_transform_func( type, G_TYPE_STRING,
transform_ref_string_g_string );
g_value_register_transform_func( G_TYPE_STRING, type,
@ -1433,8 +1453,8 @@ vips_blob_get_type( void )
if( !type ) {
type = g_boxed_type_register_static( "vips_blob",
(GBoxedCopyFunc) area_copy,
(GBoxedFreeFunc) area_unref );
(GBoxedCopyFunc) vips_area_copy,
(GBoxedFreeFunc) vips_area_unref );
g_value_register_transform_func( type, G_TYPE_STRING,
transform_blob_g_string );
g_value_register_transform_func( type, VIPS_TYPE_SAVE_STRING,
@ -1477,30 +1497,11 @@ vips_blob_set( GValue *value,
return( -1 );
g_value_set_boxed( value, area );
area_unref( area );
vips_area_unref( area );
return( 0 );
}
/* An area which holds a copy of an array of GType.
*/
static VipsArea *
area_new_array( GType type, size_t sizeof_type, int n )
{
VipsArea *area;
void *array;
array = g_malloc( n * sizeof_type );
if( !(area = area_new( (VipsCallbackFn) g_free, array )) )
return( NULL );
area->n = n;
area->length = n * sizeof_type;
area->type = G_TYPE_DOUBLE;
area->sizeof_type = sizeof_type;
return( area );
}
/* Set value to be an array of things. Don't initialise the contents: get the
* pointer and write instead.
*/
@ -1509,10 +1510,10 @@ vips_array_set( GValue *value, GType type, size_t sizeof_type, int n )
{
VipsArea *area;
if( !(area = area_new_array( type, sizeof_type, n )) )
if( !(area = vips_area_new_array( type, sizeof_type, n )) )
return( -1 );
g_value_set_boxed( value, area );
area_unref( area );
vips_area_unref( area );
return( 0 );
}
@ -1589,8 +1590,8 @@ vips_array_double_get_type( void )
if( !type ) {
type = g_boxed_type_register_static( "vips_array_double",
(GBoxedCopyFunc) area_copy,
(GBoxedFreeFunc) area_unref );
(GBoxedCopyFunc) vips_area_copy,
(GBoxedFreeFunc) vips_area_unref );
g_value_register_transform_func( type, G_TYPE_STRING,
transform_array_g_string );
}

View File

@ -1261,6 +1261,10 @@ vips_object_set_argument_from_string( VipsObject *object,
g_value_init( &gvalue, otype );
g_value_set_enum( &gvalue, enum_value->value );
}
else if( G_IS_PARAM_SPEC_BOXED( pspec ) &&
G_PARAM_SPEC_VALUE_TYPE( pspec ) == VIPS_TYPE_ARRAY_DOUBLE ) {
printf( "init double array from %s\n", value );
}
else {
g_value_init( &gvalue, G_TYPE_STRING );
g_value_set_string( &gvalue, value );

View File

@ -774,19 +774,21 @@ vips_call_argv_input( VipsObject *object,
*/
if( (argument_class->flags & VIPS_ARGUMENT_REQUIRED) &&
(argument_class->flags & VIPS_ARGUMENT_CONSTRUCT) ) {
const char *name = g_param_spec_get_name( pspec );
if( (argument_class->flags & VIPS_ARGUMENT_INPUT) ) {
const char *arg;
if( !(arg = vips_call_get_arg( call, call->i )) ||
vips_object_set_argument_from_string( object,
g_param_spec_get_name( pspec ), arg ) )
name, arg ) )
return( pspec );
call->i += 1;
}
else if( (argument_class->flags & VIPS_ARGUMENT_OUTPUT) ) {
if( vips_object_get_argument_needs_string( object,
g_param_spec_get_name( pspec ) ) )
name ) )
call->i += 1;
}
}