This chapter describes the C++ API for the VIPS image processing library. The C++ API is as efficient as the C interface to VIPS, but is far easier to use: almost all creation, destruction and error handling issues are handled for you automatically.
The Python interface is a very simple wrapping of this C++ API generated automatically with SWIG. The two interfaces are identical, except for language syntax.
To show how much easier the VIPS C++ API is to use, compare Figure 2.2.5 to Figure 1.1. Figure 1.2 is the same thing in Python.
A typical build line for the C++ program might be:
The key points are:
#include <iostream>
#include <vips/vips> int main (int argc, char ⋆⋆argv) { if (argc != 3) { std::cerr << "usage: " << argv[0] << " infile outfile\n"; exit (1); } try { vips::VImage fred (argv[1]); fred.invert ().write (argv[2]); } catch (vips::VError e) { e.perror (argv[0]); } return (0); }
|
#!/usr/bin/python
import sys from vipsCC import ⋆ try: a = VImage.VImage (sys.argv[1]) a.invert ().write (sys.argv[2]) except VError.VError, e: e.perror (sys.argv[0])
|