Thursday, 17 November 2011

vips8 progress

vips8 is coming along quite quickly now. The core was done (more or less) in the last stable release so now in git master we are working through the operations rewriting them as classes. We've done about 25% of the operations in the last couple of months.

One of the big new features is optional output arguments. For example, VipsMin is an operation that finds the minimum value of an image. You can run it from the command-line like this:
$ vips min fred.jpg
12
Very similar to the old im_min. But now there are also optional output arguments to get the position of the minimum:
$ vips min --x --y fred.jpg
12
2345
245
and you get the same API in Python, Ruby, Javascript, nip2, C and C++:
>> m = im.min()
>> print m
12
>> m, x, y = im.min("x", "y")

VipsImage *fred;
double m;
int x, y;

vips_min( fred, &m,
  "x", &x,
  "y", &y,
  NULL );
Args only need a few of lines of code to add to a class and everything else is generated for you automatically at runtime. For example, the optional --x arg for VipsMin is declared like this:
VIPS_ARG_INT( class, "x", 2,
  _( "x" ), _( "Horizontal position of minimum" ),
  VIPS_ARGUMENT_OPTIONAL_OUTPUT,
  G_STRUCT_OFFSET( VipsMin, x ),
  0, 1000000, 0 );
That binds an optional int arg with the range locked to 0 to 10000000 to the member x of the class VipsMin. Your bit of C just needs to assign that member and the value will appear in all languages and all interfaces.

VipsJoin has one of the fanciest ones. At a minimum it's:
$ vips join left.v right.v out.v horizontal
to join two images left-right, but there are also extra optional arguments, for example:
$ vips join --expand --background 0,255,0 --align centre --shim 50 left.v right.v out.v horizontal
to join left-right with a 50 pixel gap, the output expanded to hold all of both left and right, and the background painted green.

You can get a summary of the options by running with no args:
$ vips join
VipsJoin (join), join an image
  join in1 in2 out direction
where:
  in1 :: VipsImage (input)
  in2 :: VipsImage (input)
  out :: VipsImage (output)
  direction :: VipsDirection (input)
optional arguments:
  align :: VipsAlign (input)
  expand :: gboolean (input)
  shim :: gint (input)
  background :: VipsArrayDouble (input)

join: too few arguments
VipsObject: parameter in1 to VipsJoin not set
VipsObject: parameter in2 to VipsJoin not set
VipsObject: parameter direction to VipsJoin not set
vips8 includes full vips7 compatibility. The old interface:
$ vips im_lrjoin left.v right.v out.v
is still there and still works well.

No comments:

Post a Comment