0

I am working on a Java binding for the excellent libvips

Using this function all is fine:

VipsImage *in;

in = vips_image_new_from_file( test.jpg, NULL )
vips_image_write_to_file( in, "out.jpg", NULL )

So mapped in Java:

Pointer vips_image_new_from_file(String filename,String params);

But I have a problem when the parameter like this:

VipsImage *in;
VipsImage *out;

vips_invert( in, &out, NULL )
vips_image_write_to_file( out, "out.jpg", NULL ) 

I have tried:

int vips_resize(Pointer in, PointerByReference out, Double scale, String params);

Pointer in = vips_image_new_from_file("file.png",null);

PointerByReference ptr1 = new PointerByReference();

vips_invert(in, ptr1, null);
vips_image_write_to_file( ptr1.getValue(), "fileout.png", null);

But doesn't work. The ptr1.getValue() does not contains the expected result.

How can I do it?

Thanks

Nurjan
  • 5,889
  • 5
  • 34
  • 54

1 Answers1

0

I'm the libvips maintainer, a Java binding would be great!

But I think you might be taking the wrong approach. I think you are trying a straight wrap of the C API, but that's going to be tricky to do well, since it makes use of a lot of C-isms that don't map well to Java. For example, in C you can write:

VipsImage *image;

if (!(image = vips_image_new_from_file("somefile.jpg",
    "shrink", 2,
    "autorotate", TRUE,
    NULL)))
    error ...;

ie. the final NULL marks the end of a varargs name / value list. Here I'm asking the jpeg loader to do a x2 shrink during load, and to apply any Orientation tags it finds in the EXIF.

libvips has a lower-level API based on GObject which is much easier to bind to. There's some discussion and example code in this issue, where someone is making a C# binding using p/invoke.

https://github.com/jcupitt/libvips/issues/558

The code for the C++ and PHP bindings might be a useful reference:

https://github.com/jcupitt/libvips/tree/master/cplusplus

https://github.com/jcupitt/php-vips-ext

That's a PHP binding for the entire library in 1800 lines of C.

I'd be very happy to help if I can. Open an issue on the libvips tracker:

https://github.com/jcupitt/libvips/issues

jcupitt
  • 10,213
  • 2
  • 23
  • 39