Next: 2. The VIPS file Up: 1. Introduction Previous: 1. Introduction Contents

# 1.1 If you've used the C API

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 -lvipsCC \
      `vips-config --cflags --libs`

The key points are:

- You just include `<vips/vipscpp.h>` -- this then gets all of the other includes you need.

- The C++ API replaces all of the VIPS C types -- `IMAGE` becomes `VImage` and so on. The C++ API also includes `VDisplay`, `VMask` and `VError`.

- Image processing operations are member functions of the `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.

- The VIPS C++ API uses exceptions -- the `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

Figure 1.1: `invert` program in C

Figure 1.2: `invert` program in C++

Next: 2. The VIPS file Up: 1. Introduction Previous: 1. Introduction Contents