lopcode / vips-ffm

libvips bindings for JVM projects, using JDK 22's FFM and Class-File APIs to generate complete, safe, and fast APIs for image manipulation
Apache License 2.0
11 stars 0 forks source link

Docs, parameter naming or type for vector lengths #82

Open JohannesBeranek opened 1 day ago

JohannesBeranek commented 1 day ago

For some vips operations it's needed to provide a List, e.g. the "background" parameter for the flatten operation. I couldn't really find out via libvips documentation what format that parameter should have, so I tried with the following:

VipsOption.ArrayDouble("background", List.of(1.0, 1.0, 1.0, 1.0))

which got me an error message about the length of the "vector" supposed to be 1 or 3 elements. Also, I couldn't find what kind of range the values are supposed to have - currently I would guess it's 0.0-255.0 for color channels and 0.0-1.0 for alpha.

It would be good if you could force this in a type safe manner - e.g. create a wrapper class with 2 "of(...)" methods (1 parameter version and 3 parameter version) and a private constructor. Won't be that easy though, because the number of list entries depends on the channel count of the target image, so could be 1, 3, or 4 as far as I got it (I don't think vips supports more channels, but not sure). For flatten though it could only be 1 or 3, because a flattened image won't have an alpha channel, so maybe it could take an VipsRGBColor (in contrast to a VipsRGBAColor or the more abstract VipsColor - just an idea).

Other option would be to add docs about that somewhere, though I'd assume you'd like to keep the docs auto generated as much as possible to not go out of date and not manually replicate any libvips docs, so not sure what the best way would be. Type safety would definitely have advantages though.

lopcode commented 1 day ago

I think I might be able to improve this with #45 - the GIR stuff is what the website is built from (eg https://www.libvips.org/API/current/libvips-conversion.html#vips-flatten), so the docs could be much more comprehensive