add FLAGS args

This commit is contained in:
John Cupitt 2012-02-20 21:02:37 +00:00
parent 8c6e3738dd
commit 9ea1387a68
7 changed files with 44 additions and 12 deletions

2
TODO
View File

@ -3,7 +3,7 @@
- add ore sequential mode readers
- add more sequential mode readers
$ grep -l write_line *.c
csv.c

View File

@ -904,7 +904,7 @@ vips_foreign_load_class_init( VipsForeignLoadClass *class )
VIPS_ARGUMENT_REQUIRED_OUTPUT,
G_STRUCT_OFFSET( VipsForeignLoad, out ) );
VIPS_ARG_ENUM( class, "flags", 6,
VIPS_ARG_FLAGS( class, "flags", 6,
_( "Flags" ),
_( "Flags for this file" ),
VIPS_ARGUMENT_OPTIONAL_OUTPUT,
@ -943,7 +943,8 @@ vips_foreign_tilecache( VipsImage *in, VipsImage **out, int strip_height )
vips_get_tile_size( in, &tile_width, &tile_height, &nlines );
/* We need two buffers, each with enough strips to make a complete
* buffer. And double to be safe.
* buffer. And double to be safe, since input buffers must be larger
* than output, and our buffers may not align exactly.
*/
nstrips = 2 * (1 + nlines / strip_height);

View File

@ -86,12 +86,12 @@ void *vips_foreign_map( const char *base,
/* Image file load properties.
*/
typedef enum {
typedef enum /*< flags >*/ {
VIPS_FOREIGN_NONE = 0, /* No flags set */
VIPS_FOREIGN_PARTIAL = 1, /* Lazy read OK (eg. tiled tiff) */
VIPS_FOREIGN_SEQUENTIAL = 2, /* Top-to-bottom lazy read OK */
VIPS_FOREIGN_BIGENDIAN = 3, /* Most-significant byte first */
VIPS_FOREIGN_ALL = 4 /* All flags set */
VIPS_FOREIGN_BIGENDIAN = 4, /* Most-significant byte first */
VIPS_FOREIGN_ALL = 7 /* All flags set */
} VipsForeignFlags;
#define VIPS_TYPE_FOREIGN_LOAD (vips_foreign_load_get_type())

View File

@ -66,7 +66,7 @@ typedef struct _VipsObjectClass VipsObjectClass;
* member of struct _VipsImage. We default its 'assigned' to TRUE
* since the field is always set directly by C.
*/
typedef enum {
typedef enum /*< flags >*/ {
VIPS_ARGUMENT_NONE = 0,
VIPS_ARGUMENT_REQUIRED = 1,
VIPS_ARGUMENT_CONSTRUCT = 2,
@ -201,6 +201,19 @@ extern int _vips__argument_id;
pspec, (FLAGS), (PRIORITY), (OFFSET) ); \
}
#define VIPS_ARG_FLAGS( CLASS, NAME, PRIORITY, LONG, DESC, \
FLAGS, OFFSET, TYPE, VALUE ) { \
GParamSpec *pspec; \
\
pspec = g_param_spec_flags( (NAME), (LONG), (DESC), \
(TYPE), (VALUE), \
G_PARAM_READWRITE );\
g_object_class_install_property( G_OBJECT_CLASS( CLASS ), \
_vips__argument_id++, pspec ); \
vips_object_class_install_argument( VIPS_OBJECT_CLASS( CLASS ), \
pspec, (FLAGS), (PRIORITY), (OFFSET) ); \
}
#define VIPS_ARG_STRING( CLASS, NAME, PRIORITY, LONG, DESC, FLAGS, OFFSET, \
VALUE ) { \
GParamSpec *pspec; \

View File

@ -11,7 +11,7 @@ vips_foreign_flags_get_type( void )
static GType etype = 0;
if( etype == 0 ) {
static const GEnumValue values[] = {
static const GFlagsValue values[] = {
{VIPS_FOREIGN_NONE, "VIPS_FOREIGN_NONE", "none"},
{VIPS_FOREIGN_PARTIAL, "VIPS_FOREIGN_PARTIAL", "partial"},
{VIPS_FOREIGN_SEQUENTIAL, "VIPS_FOREIGN_SEQUENTIAL", "sequential"},
@ -20,7 +20,7 @@ vips_foreign_flags_get_type( void )
{0, NULL, NULL}
};
etype = g_enum_register_static( "VipsForeignFlags", values );
etype = g_flags_register_static( "VipsForeignFlags", values );
}
return( etype );
@ -499,7 +499,7 @@ vips_argument_flags_get_type( void )
static GType etype = 0;
if( etype == 0 ) {
static const GEnumValue values[] = {
static const GFlagsValue values[] = {
{VIPS_ARGUMENT_NONE, "VIPS_ARGUMENT_NONE", "none"},
{VIPS_ARGUMENT_REQUIRED, "VIPS_ARGUMENT_REQUIRED", "required"},
{VIPS_ARGUMENT_CONSTRUCT, "VIPS_ARGUMENT_CONSTRUCT", "construct"},
@ -510,7 +510,7 @@ vips_argument_flags_get_type( void )
{0, NULL, NULL}
};
etype = g_enum_register_static( "VipsArgumentFlags", values );
etype = g_flags_register_static( "VipsArgumentFlags", values );
}
return( etype );

View File

@ -998,6 +998,12 @@ vips_object_set_property( GObject *gobject,
*member = g_value_get_enum( value );
}
else if( G_IS_PARAM_SPEC_FLAGS( pspec ) ) {
int *member = &G_STRUCT_MEMBER( int, object,
argument_class->offset );
*member = g_value_get_flags( value );
}
else if( G_IS_PARAM_SPEC_POINTER( pspec ) ) {
gpointer *member = &G_STRUCT_MEMBER( gpointer, object,
argument_class->offset );
@ -1104,6 +1110,12 @@ vips_object_get_property( GObject *gobject,
g_value_set_enum( value, *member );
}
else if( G_IS_PARAM_SPEC_FLAGS( pspec ) ) {
int *member = &G_STRUCT_MEMBER( int, object,
argument_class->offset );
g_value_set_flags( value, *member );
}
else if( G_IS_PARAM_SPEC_POINTER( pspec ) ) {
gpointer *member = &G_STRUCT_MEMBER( gpointer, object,
argument_class->offset );
@ -1497,6 +1509,12 @@ 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_FLAGS( pspec ) ) {
/* Hard to set from a symbolic name. Just take an int.
*/
g_value_init( &gvalue, otype );
g_value_set_flags( &gvalue, atoi( value ) );
}
else {
g_value_init( &gvalue, G_TYPE_STRING );
g_value_set_string( &gvalue, value );

View File

@ -68,8 +68,8 @@
/*
#define DEBUG
*/
#define DEBUG_FATAL
*/
/* Need to disable these sometimes.
#undef DEBUG_FATAL