next up previous contents
Next: 6.15 Calling VIPS functions Up: 6. Programming Previous: 6.13 The _Object class   Contents


6.14 Optimisation

nip performs two useful optimisations on expressions. First, it finds and removes common sub-expressions in functions. So for example:

                                                             
  if a + b < 12 then a + b else b

will only evaluate a + b once. This can save a lot of time if a or b is a large image.

Second, nip detects arithmetic operations on unsigned char images, and replaces them with look-up tables. For example:

                                                             
  a = vips_image "campin.v"
  b = a * (a - 1) ** 0.5

Provided campin.v is an 8 bit image image, this expression will evaluate with a single call to im_maplut().


next up previous contents
Next: 6.15 Calling VIPS functions Up: 6. Programming Previous: 6.13 The _Object class   Contents
John Cupitt 2003-07-21