libvips / nip2

A spreadsheet-like GUI for libvips.
https://libvips.github.io/libvips/
GNU General Public License v2.0
360 stars 13 forks source link

Scripting docs? #43

Closed jcupitt closed 10 years ago

jcupitt commented 10 years ago

Even though I've read through all the documentation, I still can't figure out how to use the scripting within the UI. The syntax doesn't seem to work as expected in some cases so I'm confused between the commands I see when I use the menus vs. corresponding functions in the toolkit code being so different. Also, things like matrix vector multiplies, or selecting a channel of an image and multiplying the whole image with it, or creating a vector from selected numbers is not apparent at all.

jcupitt commented 10 years ago

nip2 is a functional language, along the lines of Haskell. If you've not used Haskell it'll be rather impenetrable :-( Have you found the Definition Browser? Click Toolkits / Edit to get a program window, then click View / Definition Browser. It'll show you some help as you type stuff, and you can use it to click about between definitions, it's rather handy.

You can have more than one program window open, so you can have one for reference and one for working.

Probably the big thing is that nip2 has primitive types, like number and list, and classes, like Matrix and Image. The primitive types do not support operator overloading, and the classes do. So:

[1, 2, 3] * 2

won't work, because that's two primitive types, list and number, being multiplied. But:

Vector [1, 2, 3] * 2

will work, because that's wrapping up a list as a Vector class, then the Vector class knows how to multiply against a number.

Also, check the F1 manual, there's a section on the programming language.

jcupitt commented 10 years ago

I missed your specific questions, sorry.

Matrix * vector:

Matrix [[1, 2, 3], [4, 5, 6], [7, 8, 9]] * Vector [1, 2, 3]

Extract band of image:

A1?1

to take band 1 (the middle band of a three-band image).

A1?1 * A1

To scale an image by the middle band.

A1 * Vector [1, 2, 3]

To multiply band 0 (red, typically) by 1, band 1 by 2, band 2 by 3.