To show how much easier the VIPS C++ API is to use, consider the program shown in figure 1.1 (this is the second example from the VIPS Application Programmers' Guide). Figure 1.2 shows the same program, written with the C++ API.
A typical build line for the C++ program might be:
c++ invert.cc \ `pkg-config vipsCC-7.10 --cflags --libs`
The key points are:
<vips/vipscpp.h>
-- this then gets all of the
other includes you need.
IMAGE
becomes
VImage
and so on. The C++ API also includes VDisplay
,
VMask
and VError
.
VImage
class
-- here, VImage( argv[1] )
creates a new VImage
object using
the first argument to initialise it (the input filename). It then calls the
member function invert()
, which inverts the VImage
and returns a
new VImage
. Finally it calls the member function write()
, which
writes the result image to the named file.
VError
class is covered
later. If you run this program with a bad input file, for example, you get the
following output:
example% invert jim fred invert: VIPS error: im_open: \ "jim" is not readable