get the new arg system working
This commit is contained in:
John Cupitt 2011-10-16 17:48:28 +01:00
parent 8dfb3056ac
commit 26792ed4e1
10 changed files with 70 additions and 99 deletions

60
TODO
View File

@ -1,52 +1,16 @@
- embed args are in the wrong order - try
$ vips embed $ vips max
vips_embed_class_init im_max (max), maximum value of image, from package "arithmetic"
VipsEmbed (embed), embed an image in a larger image max in
embed input type x y width height out
where: where:
input :: VipsImage (input) in :: VipsImage (input)
type :: gint (input) from package "arithmetic"
x :: gint (input) flags: (PIO function) (no coordinate transformation) (area
y :: gint (input) operation) (result can be cached)
width :: gint (input)
height :: gint (input)
out :: VipsImage (output)
how can we fix this? no output arg?
need to give an extra arg to vips_object_class_install_argument() to
specify 'argument priority' ... show args in priority order
- try some macros for arg specification
pspec = g_param_spec_int( "y", "Y",
_( "Top edge of input in output" ),
0, 1000000, 0,
G_PARAM_READWRITE );
g_object_class_install_property( gobject_class, PROP_Y, pspec );
vips_object_class_install_argument( vobject_class, pspec,
VIPS_ARGUMENT_REQUIRED_INPUT,
G_STRUCT_OFFSET( VipsEmbed, y ) );
could become
VIPS_ARG_INT( class, "y", "Y",
_( "Top edge of input in output" ),
0, 1000000, 0,
VIPS_ARGUMENT_REQUIRED_INPUT,
G_STRUCT_OFFSET( VipsEmbed, y ) );
could get rid of PROP_ enums as well
doing binary.c next
- make 'type' field to embed an enum?
@ -64,9 +28,11 @@
- do clip/embed etc. in new style, good to get everything that VipsAdd uses in - do clip etc. in new style, good to get everything that VipsAdd uses in
the new stack the new stack
embed needs flip* *join extract_area replicate insert

View File

@ -94,20 +94,20 @@ vips_arithmetic_class_init( VipsArithmeticClass *class )
vobject_class->description = _( "arithmetic operations" ); vobject_class->description = _( "arithmetic operations" );
vobject_class->build = vips_arithmetic_build; vobject_class->build = vips_arithmetic_build;
VIPS_ARG_IMAGE( class, "out", 1, VIPS_ARG_IMAGE( class, "out", 100,
_( "Output" ), _( "Output" ),
_( "Output image" ), _( "Output image" ),
VIPS_ARGUMENT_REQUIRED_OUTPUT, VIPS_ARGUMENT_REQUIRED_OUTPUT,
G_STRUCT_OFFSET( VipsArithmetic, output ) ); G_STRUCT_OFFSET( VipsArithmetic, output ) );
VIPS_ARG_BOOL( class, "booltest", 2, VIPS_ARG_BOOL( class, "booltest", 1,
_( "Bool test" ), _( "Bool test" ),
_( "Test optional boolean argument" ), _( "Test optional boolean argument" ),
VIPS_ARGUMENT_OPTIONAL_INPUT, VIPS_ARGUMENT_OPTIONAL_INPUT,
G_STRUCT_OFFSET( VipsArithmetic, booltest ), G_STRUCT_OFFSET( VipsArithmetic, booltest ),
FALSE ); FALSE );
VIPS_ARG_IMAGE( class, "imtest", 3, VIPS_ARG_IMAGE( class, "imtest", 2,
_( "Image test" ), _( "Image test" ),
_( "Test optional image argument" ), _( "Test optional image argument" ),
VIPS_ARGUMENT_OPTIONAL_INPUT, VIPS_ARGUMENT_OPTIONAL_INPUT,

View File

@ -349,17 +349,19 @@ vips_binary_class_init( VipsBinaryClass *class )
/* Create properties. /* Create properties.
*/ */
VIPS_ARG_IMAGE( class, "right", 1,
VIPS_ARG_IMAGE( class, "left", 1,
_( "Left" ),
_( "Left-hand image argument" ),
VIPS_ARGUMENT_REQUIRED_INPUT,
G_STRUCT_OFFSET( VipsBinary, left ) );
VIPS_ARG_IMAGE( class, "right", 2,
_( "Right" ), _( "Right" ),
_( "Right-hand image argument" ), _( "Right-hand image argument" ),
VIPS_ARGUMENT_REQUIRED_INPUT, VIPS_ARGUMENT_REQUIRED_INPUT,
G_STRUCT_OFFSET( VipsBinary, right ) ); G_STRUCT_OFFSET( VipsBinary, right ) );
VIPS_ARG_IMAGE( class, "left", 2,
_( "Left" ),
_( "Left-hand image argument" ),
VIPS_ARGUMENT_REQUIRED_INPUT,
G_STRUCT_OFFSET( VipsBinary, left ) );
} }
static void static void

View File

@ -147,7 +147,7 @@ vips_statistic_class_init( VipsStatisticClass *class )
vobject_class->description = _( "VIPS statistic operations" ); vobject_class->description = _( "VIPS statistic operations" );
vobject_class->build = vips_statistic_build; vobject_class->build = vips_statistic_build;
VIPS_ARG_IMAGE( class, "in", 1, VIPS_ARG_IMAGE( class, "in", 0,
_( "Input" ), _( "Input" ),
_( "Input image" ), _( "Input image" ),
VIPS_ARGUMENT_REQUIRED_INPUT, VIPS_ARGUMENT_REQUIRED_INPUT,

View File

@ -348,70 +348,70 @@ vips_copy_class_init( VipsCopyClass *class )
G_STRUCT_OFFSET( VipsCopy, swap ), G_STRUCT_OFFSET( VipsCopy, swap ),
FALSE ); FALSE );
VIPS_ARG_INT( class, "width", 2, VIPS_ARG_INT( class, "width", 3,
_( "Width" ), _( "Width" ),
_( "Image width in pixels" ), _( "Image width in pixels" ),
VIPS_ARGUMENT_OPTIONAL_INPUT, VIPS_ARGUMENT_OPTIONAL_INPUT,
G_STRUCT_OFFSET( VipsCopy, width ), G_STRUCT_OFFSET( VipsCopy, width ),
0, 1000000, 0 ); 0, 1000000, 0 );
VIPS_ARG_INT( class, "height", 3, VIPS_ARG_INT( class, "height", 4,
_( "Height" ), _( "Height" ),
_( "Image height in pixels" ), _( "Image height in pixels" ),
VIPS_ARGUMENT_OPTIONAL_INPUT, VIPS_ARGUMENT_OPTIONAL_INPUT,
G_STRUCT_OFFSET( VipsCopy, height ), G_STRUCT_OFFSET( VipsCopy, height ),
0, 1000000, 0 ); 0, 1000000, 0 );
VIPS_ARG_INT( class, "bands", 4, VIPS_ARG_INT( class, "bands", 5,
_( "Bands" ), _( "Bands" ),
_( "Number of bands in image" ), _( "Number of bands in image" ),
VIPS_ARGUMENT_OPTIONAL_INPUT, VIPS_ARGUMENT_OPTIONAL_INPUT,
G_STRUCT_OFFSET( VipsCopy, bands ), G_STRUCT_OFFSET( VipsCopy, bands ),
0, 1000000, 0 ); 0, 1000000, 0 );
VIPS_ARG_ENUM( class, "format", 5, VIPS_ARG_ENUM( class, "format", 6,
_( "Format" ), _( "Format" ),
_( "Pixel format in image" ), _( "Pixel format in image" ),
VIPS_ARGUMENT_OPTIONAL_INPUT, VIPS_ARGUMENT_OPTIONAL_INPUT,
G_STRUCT_OFFSET( VipsCopy, format ), G_STRUCT_OFFSET( VipsCopy, format ),
VIPS_TYPE_BAND_FORMAT, VIPS_FORMAT_UCHAR ); VIPS_TYPE_BAND_FORMAT, VIPS_FORMAT_UCHAR );
VIPS_ARG_ENUM( class, "coding", 6, VIPS_ARG_ENUM( class, "coding", 7,
_( "Coding" ), _( "Coding" ),
_( "Pixel coding" ), _( "Pixel coding" ),
VIPS_ARGUMENT_OPTIONAL_INPUT, VIPS_ARGUMENT_OPTIONAL_INPUT,
G_STRUCT_OFFSET( VipsCopy, coding ), G_STRUCT_OFFSET( VipsCopy, coding ),
VIPS_TYPE_CODING, VIPS_CODING_NONE ); VIPS_TYPE_CODING, VIPS_CODING_NONE );
VIPS_ARG_ENUM( class, "interpretation", 7, VIPS_ARG_ENUM( class, "interpretation", 8,
_( "Interpretation" ), _( "Interpretation" ),
_( "Pixel interpretation" ), _( "Pixel interpretation" ),
VIPS_ARGUMENT_OPTIONAL_INPUT, VIPS_ARGUMENT_OPTIONAL_INPUT,
G_STRUCT_OFFSET( VipsCopy, interpretation ), G_STRUCT_OFFSET( VipsCopy, interpretation ),
VIPS_TYPE_INTERPRETATION, VIPS_INTERPRETATION_MULTIBAND ); VIPS_TYPE_INTERPRETATION, VIPS_INTERPRETATION_MULTIBAND );
VIPS_ARG_DOUBLE( class, "xres", 8, VIPS_ARG_DOUBLE( class, "xres", 9,
_( "Xres" ), _( "Xres" ),
_( "Horizontal resolution in pixels/mm" ), _( "Horizontal resolution in pixels/mm" ),
VIPS_ARGUMENT_OPTIONAL_INPUT, VIPS_ARGUMENT_OPTIONAL_INPUT,
G_STRUCT_OFFSET( VipsCopy, xres ), G_STRUCT_OFFSET( VipsCopy, xres ),
0, 1000000, 0 ); 0, 1000000, 0 );
VIPS_ARG_DOUBLE( class, "yres", 9, VIPS_ARG_DOUBLE( class, "yres", 10,
_( "Yres" ), _( "Yres" ),
_( "Vertical resolution in pixels/mm" ), _( "Vertical resolution in pixels/mm" ),
VIPS_ARGUMENT_OPTIONAL_INPUT, VIPS_ARGUMENT_OPTIONAL_INPUT,
G_STRUCT_OFFSET( VipsCopy, yres ), G_STRUCT_OFFSET( VipsCopy, yres ),
0, 1000000, 0 ); 0, 1000000, 0 );
VIPS_ARG_INT( class, "xoffset", 10, VIPS_ARG_INT( class, "xoffset", 11,
_( "Xoffset" ), _( "Xoffset" ),
_( "Horizontal offset of origin" ), _( "Horizontal offset of origin" ),
VIPS_ARGUMENT_OPTIONAL_INPUT, VIPS_ARGUMENT_OPTIONAL_INPUT,
G_STRUCT_OFFSET( VipsCopy, xoffset ), G_STRUCT_OFFSET( VipsCopy, xoffset ),
-1000000, 1000000, 0 ); -1000000, 1000000, 0 );
VIPS_ARG_INT( class, "yoffset", 11, VIPS_ARG_INT( class, "yoffset", 12,
_( "Yoffset" ), _( "Yoffset" ),
_( "Vertical offset of origin" ), _( "Vertical offset of origin" ),
VIPS_ARGUMENT_OPTIONAL_INPUT, VIPS_ARGUMENT_OPTIONAL_INPUT,

View File

@ -75,13 +75,14 @@
* VipsEmbed: * VipsEmbed:
* @in: input image * @in: input image
* @out: output image * @out: output image
* @type: how to generate the edge pixels * @extend: how to generate the edge pixels
* @x: place @in at this x position in @out * @x: place @in at this x position in @out
* @y: place @in at this y position in @out * @y: place @in at this y position in @out
* @width: @out should be this many pixels across * @width: @out should be this many pixels across
* @height: @out should be this many pixels down * @height: @out should be this many pixels down
* *
* The opposite of im_extract(): embed an image within a larger image. @type * The opposite of im_extract(): embed @in within an image of size @width by
* @height at position @x, @y. @extend
* controls what appears in the new pels, see #VipsExtend. * controls what appears in the new pels, see #VipsExtend.
* *
* See also: im_extract_area(), im_insert(). * See also: im_extract_area(), im_insert().
@ -96,7 +97,7 @@ typedef struct _VipsEmbed {
*/ */
VipsImage *input; VipsImage *input;
VipsExtend type; VipsExtend extend;
int x; int x;
int y; int y;
int width; int width;
@ -104,13 +105,13 @@ typedef struct _VipsEmbed {
/* Geometry calculations. /* Geometry calculations.
*/ */
Rect rout; /* Whole output area */ VipsRect rout; /* Whole output area */
Rect rsub; /* Rect occupied by image */ VipsRect rsub; /* Rect occupied by image */
/* The 8 border pieces. The 4 borders strictly up/down/left/right of /* The 8 border pieces. The 4 borders strictly up/down/left/right of
* the main image, and the 4 corner pieces. * the main image, and the 4 corner pieces.
*/ */
Rect border[8]; VipsRect border[8];
} VipsEmbed; } VipsEmbed;
typedef VipsConversionClass VipsEmbedClass; typedef VipsConversionClass VipsEmbedClass;
@ -267,17 +268,17 @@ vips_embed_gen( VipsRegion *or, void *seq, void *a, void *b, gboolean *stop )
ovl.top += embed->y; ovl.top += embed->y;
} }
switch( embed->type ) { switch( embed->extend ) {
case 0: case VIPS_EXTEND_BLACK:
case 4: case VIPS_EXTEND_WHITE:
/* Paint the borders a solid value. /* Paint the borders a solid value.
*/ */
for( i = 0; i < 8; i++ ) for( i = 0; i < 8; i++ )
vips_region_paint( or, &embed->border[i], vips_region_paint( or, &embed->border[i],
embed->type == 0 ? 0 : 255 ); embed->extend == 0 ? 0 : 255 );
break; break;
case 1: case VIPS_EXTEND_COPY:
/* Extend the borders. /* Extend the borders.
*/ */
for( i = 0; i < 8; i++ ) { for( i = 0; i < 8; i++ ) {
@ -338,8 +339,8 @@ vips_embed_build( VipsObject *object )
if( vips_image_pio_input( embed->input ) || if( vips_image_pio_input( embed->input ) ||
vips_image_pio_output( conversion->output ) ) vips_image_pio_output( conversion->output ) )
return( -1 ); return( -1 );
if( embed->type < 0 || embed->type > 4 ) { if( embed->extend < 0 || embed->extend >= VIPS_EXTEND_LAST ) {
vips_error( "VipsEmbed", "%s", _( "unknown type" ) ); vips_error( "VipsEmbed", "%s", _( "unknown VipsExtend" ) );
return( -1 ); return( -1 );
} }
@ -351,8 +352,8 @@ vips_embed_build( VipsObject *object )
embed->height == embed->input->Ysize ) embed->height == embed->input->Ysize )
return( vips_image_write( embed->input, conversion->output ) ); return( vips_image_write( embed->input, conversion->output ) );
switch( embed->type ) { switch( embed->extend ) {
case 2: case VIPS_EXTEND_REPEAT:
{ {
/* Clock arithmetic: we want negative x/y to wrap around /* Clock arithmetic: we want negative x/y to wrap around
* nicely. * nicely.
@ -377,7 +378,7 @@ vips_embed_build( VipsObject *object )
} }
break; break;
case 3: case VIPS_EXTEND_MIRROR:
{ {
/* As case 2, but the tiles are twice the size because of /* As case 2, but the tiles are twice the size because of
* mirroring. * mirroring.
@ -586,11 +587,11 @@ vips_embed_class_init( VipsEmbedClass *class )
G_STRUCT_OFFSET( VipsEmbed, y ), G_STRUCT_OFFSET( VipsEmbed, y ),
-1000000, 1000000, 0 ); -1000000, 1000000, 0 );
VIPS_ARG_ENUM( class, "type", 6, VIPS_ARG_ENUM( class, "extend", 6,
_( "type" ), _( "Extend" ),
_( "How to generate the extra pixels" ), _( "How to generate the extra pixels" ),
VIPS_ARGUMENT_OPTIONAL_INPUT, VIPS_ARGUMENT_OPTIONAL_INPUT,
G_STRUCT_OFFSET( VipsEmbed, type ), G_STRUCT_OFFSET( VipsEmbed, extend ),
VIPS_TYPE_EXTEND, VIPS_EXTEND_BLACK ); VIPS_TYPE_EXTEND, VIPS_EXTEND_BLACK );
} }

View File

@ -72,7 +72,8 @@ typedef enum {
VIPS_EXTEND_COPY = 1, VIPS_EXTEND_COPY = 1,
VIPS_EXTEND_REPEAT = 2, VIPS_EXTEND_REPEAT = 2,
VIPS_EXTEND_MIRROR = 3, VIPS_EXTEND_MIRROR = 3,
VIPS_EXTEND_WHITE = 4 VIPS_EXTEND_WHITE = 4,
VIPS_EXTEND_LAST = 5
} VipsExtend; } VipsExtend;
int vips_copy( VipsImage *in, VipsImage **out, ... ) int vips_copy( VipsImage *in, VipsImage **out, ... )

View File

@ -17,6 +17,7 @@ vips_extend_get_type( void )
{VIPS_EXTEND_REPEAT, "VIPS_EXTEND_REPEAT", "repeat"}, {VIPS_EXTEND_REPEAT, "VIPS_EXTEND_REPEAT", "repeat"},
{VIPS_EXTEND_MIRROR, "VIPS_EXTEND_MIRROR", "mirror"}, {VIPS_EXTEND_MIRROR, "VIPS_EXTEND_MIRROR", "mirror"},
{VIPS_EXTEND_WHITE, "VIPS_EXTEND_WHITE", "white"}, {VIPS_EXTEND_WHITE, "VIPS_EXTEND_WHITE", "white"},
{VIPS_EXTEND_LAST, "VIPS_EXTEND_LAST", "last"},
{0, NULL, NULL} {0, NULL, NULL}
}; };

View File

@ -952,70 +952,70 @@ vips_image_class_init( VipsImageClass *class )
VIPS_ARG_INT( class, "width", 2, VIPS_ARG_INT( class, "width", 2,
_( "Width" ), _( "Width" ),
_( "Image width in pixels" ), _( "Image width in pixels" ),
VIPS_ARGUMENT_OPTIONAL_INPUT, VIPS_ARGUMENT_SET_ONCE,
G_STRUCT_OFFSET( VipsImage, Xsize ), G_STRUCT_OFFSET( VipsImage, Xsize ),
0, 1000000, 0 ); 0, 1000000, 0 );
VIPS_ARG_INT( class, "height", 3, VIPS_ARG_INT( class, "height", 3,
_( "Height" ), _( "Height" ),
_( "Image height in pixels" ), _( "Image height in pixels" ),
VIPS_ARGUMENT_OPTIONAL_INPUT, VIPS_ARGUMENT_SET_ONCE,
G_STRUCT_OFFSET( VipsImage, Ysize ), G_STRUCT_OFFSET( VipsImage, Ysize ),
0, 1000000, 0 ); 0, 1000000, 0 );
VIPS_ARG_INT( class, "bands", 4, VIPS_ARG_INT( class, "bands", 4,
_( "Bands" ), _( "Bands" ),
_( "Number of bands in image" ), _( "Number of bands in image" ),
VIPS_ARGUMENT_OPTIONAL_INPUT, VIPS_ARGUMENT_SET_ONCE,
G_STRUCT_OFFSET( VipsImage, Bands ), G_STRUCT_OFFSET( VipsImage, Bands ),
0, 1000000, 0 ); 0, 1000000, 0 );
VIPS_ARG_ENUM( class, "format", 5, VIPS_ARG_ENUM( class, "format", 5,
_( "Format" ), _( "Format" ),
_( "Pixel format in image" ), _( "Pixel format in image" ),
VIPS_ARGUMENT_OPTIONAL_INPUT, VIPS_ARGUMENT_SET_ONCE,
G_STRUCT_OFFSET( VipsImage, BandFmt ), G_STRUCT_OFFSET( VipsImage, BandFmt ),
VIPS_TYPE_BAND_FORMAT, VIPS_FORMAT_UCHAR ); VIPS_TYPE_BAND_FORMAT, VIPS_FORMAT_UCHAR );
VIPS_ARG_ENUM( class, "coding", 6, VIPS_ARG_ENUM( class, "coding", 6,
_( "Coding" ), _( "Coding" ),
_( "Pixel coding" ), _( "Pixel coding" ),
VIPS_ARGUMENT_OPTIONAL_INPUT, VIPS_ARGUMENT_SET_ONCE,
G_STRUCT_OFFSET( VipsImage, Coding ), G_STRUCT_OFFSET( VipsImage, Coding ),
VIPS_TYPE_CODING, VIPS_CODING_NONE ); VIPS_TYPE_CODING, VIPS_CODING_NONE );
VIPS_ARG_ENUM( class, "interpretation", 7, VIPS_ARG_ENUM( class, "interpretation", 7,
_( "Interpretation" ), _( "Interpretation" ),
_( "Pixel interpretation" ), _( "Pixel interpretation" ),
VIPS_ARGUMENT_OPTIONAL_INPUT, VIPS_ARGUMENT_SET_ONCE,
G_STRUCT_OFFSET( VipsImage, Type ), G_STRUCT_OFFSET( VipsImage, Type ),
VIPS_TYPE_INTERPRETATION, VIPS_INTERPRETATION_MULTIBAND ); VIPS_TYPE_INTERPRETATION, VIPS_INTERPRETATION_MULTIBAND );
VIPS_ARG_DOUBLE( class, "xres", 8, VIPS_ARG_DOUBLE( class, "xres", 8,
_( "Xres" ), _( "Xres" ),
_( "Horizontal resolution in pixels/mm" ), _( "Horizontal resolution in pixels/mm" ),
VIPS_ARGUMENT_OPTIONAL_INPUT, VIPS_ARGUMENT_SET_ONCE,
G_STRUCT_OFFSET( VipsImage, Xres ), G_STRUCT_OFFSET( VipsImage, Xres ),
0, 1000000, 0 ); 0, 1000000, 0 );
VIPS_ARG_DOUBLE( class, "yres", 9, VIPS_ARG_DOUBLE( class, "yres", 9,
_( "Yres" ), _( "Yres" ),
_( "Vertical resolution in pixels/mm" ), _( "Vertical resolution in pixels/mm" ),
VIPS_ARGUMENT_OPTIONAL_INPUT, VIPS_ARGUMENT_SET_ONCE,
G_STRUCT_OFFSET( VipsImage, Yres ), G_STRUCT_OFFSET( VipsImage, Yres ),
0, 1000000, 0 ); 0, 1000000, 0 );
VIPS_ARG_INT( class, "xoffset", 10, VIPS_ARG_INT( class, "xoffset", 10,
_( "Xoffset" ), _( "Xoffset" ),
_( "Horizontal offset of origin" ), _( "Horizontal offset of origin" ),
VIPS_ARGUMENT_OPTIONAL_INPUT, VIPS_ARGUMENT_SET_ONCE,
G_STRUCT_OFFSET( VipsImage, Xoffset ), G_STRUCT_OFFSET( VipsImage, Xoffset ),
-1000000, 1000000, 0 ); -1000000, 1000000, 0 );
VIPS_ARG_INT( class, "yoffset", 11, VIPS_ARG_INT( class, "yoffset", 11,
_( "Yoffset" ), _( "Yoffset" ),
_( "Vertical offset of origin" ), _( "Vertical offset of origin" ),
VIPS_ARGUMENT_OPTIONAL_INPUT, VIPS_ARGUMENT_SET_ONCE,
G_STRUCT_OFFSET( VipsImage, Yoffset ), G_STRUCT_OFFSET( VipsImage, Yoffset ),
-1000000, 1000000, 0 ); -1000000, 1000000, 0 );
@ -1030,7 +1030,7 @@ vips_image_class_init( VipsImageClass *class )
_( "Mode" ), _( "Mode" ),
_( "Open mode" ), _( "Open mode" ),
VIPS_ARGUMENT_CONSTRUCT, VIPS_ARGUMENT_CONSTRUCT,
G_STRUCT_OFFSET( VipsImage, filename ), G_STRUCT_OFFSET( VipsImage, mode ),
"p" ); "p" );
VIPS_ARG_BOOL( class, "kill", 14, VIPS_ARG_BOOL( class, "kill", 14,

View File

@ -64,7 +64,7 @@ static GMutex *vips__object_all_lock = NULL;
static guint vips_object_signals[SIG_LAST] = { 0 }; static guint vips_object_signals[SIG_LAST] = { 0 };
int _vips__argument_id = 0; int _vips__argument_id = 1;
G_DEFINE_ABSTRACT_TYPE( VipsObject, vips_object, G_TYPE_OBJECT ); G_DEFINE_ABSTRACT_TYPE( VipsObject, vips_object, G_TYPE_OBJECT );