more docs work

This commit is contained in:
John Cupitt 2015-02-23 12:32:56 +00:00
parent 78acd9b7a0
commit cce569cdb7
8 changed files with 185 additions and 96 deletions

View File

@ -15,7 +15,7 @@
<refpurpose>How to write bindings for libvips</refpurpose>
</refnamediv>
<refsect1 id="binding-goi">
<refsect3 id="binding-goi">
<title>Binding and gobject-introspection</title>
<para>
The C source code
@ -89,6 +89,6 @@ $ yelp-build html .
</para>
</refsect1>
</refsect3>
</refentry>

View File

@ -14,13 +14,29 @@
<refpurpose>How to add operations to VIPS</refpurpose>
</refnamediv>
<refsect1 id="extending-pointtopoint">
<title>A simple point-to-point operation</title>
<refsect3 id="extending-intro">
<title>Introduction</title>
<para>
This section runs quickly through adding a simple operator to VIPS.
For more information, see #VipsOperation and #VipsRegion. A good
starting point for a new operation is a similar one in the VIPS library.
</para>
<para>
All operations are subclasses of #VipsOperation, which in turn
subclasses #VipsObject and then %GObject. You need to define a new
instance struct and a new class struct.
All VIPS operations are subclasses of #VipsOperation, which in turn
subclasses #VipsObject and then %GObject. You add an operation to VIPS
by defining a new subclass of #VipsOperation and arranging for its
<code>class_init()</code> to be called, perhaps by calling its get_type()
function.
</para>
</refsect3>
<refsect3 id="extending-classstruct">
<title>The class and object structures</title>
<para>
First you need to define a new
object struct and a new class struct.
<programlisting language="C">
typedef struct _Negative {
@ -48,8 +64,8 @@ typedef struct _NegativeClass {
8-bit image, optionally letting you specify the value which the pixels
"pivot" about. It doesn't need any class members (ie. values common
to all operations of this type), so the second struct is empty. See
vips_invert() for a more complete version of this operation that's
actually in the library.
the source to vips_invert() for a more complete version of this
operation that's actually in the library.
</para>
<para>
@ -59,16 +75,19 @@ typedef struct _NegativeClass {
G_DEFINE_TYPE( Negative, negative, VIPS_TYPE_OPERATION );
</programlisting>
This defines a function called negative_get_type(),
G_DEFINE_TYPE() defines a function called negative_get_type(),
which registers this new class and returns its %GType (a
pointer-sized integer). negative_get_type() in turn needs two
functions, negative_init(), to initialise a new instance, and
negative_class_init(), to initialise a new class.
</para>
</refsect3>
<refsect3 id="extending-init">
<title>Class and object initialisation</title>
<para>
negative_init() is very simple, it just sets the default value for
our optional class parameter.
our optional parameter.
<programlisting language="C">
static void
@ -81,7 +100,7 @@ negative_init( Negative *negative )
<para>
negative_class_init() is more complicated: it has to set various
fields in various superclasses.
fields in various superclasses and define the operation's parameters.
<programlisting language="C">
static void
@ -133,8 +152,13 @@ negative_class_init( NegativeClass *class )
</para>
<para>
Finally, it needs to set the arguments this class constructor
takes. There are a set of handy macros for doing this. The first few
Finally, it needs to define the arguments the constructor for this class
takes. There are a set of handy macros for doing this, see
VIPS_ARG_INT() and friends.
</para>
<para>
The first few
parameters are always the same and mean: class pointer for argument,
argument name, argument priority (bindings expect required arguments in
order of priority), long argument name (this one is internationalised
@ -147,11 +171,15 @@ negative_class_init( NegativeClass *class )
Integer arguments take three more values: the minimum, maximum and
default value for the argument.
</para>
</refsect3>
<refsect3 id="extending-build">
<title>The build() function</title>
<para>
The build function is the thing #VipsObject calls after supplying
arguments. It checks that all required arguments have been set and are
valid and constructs the object. After build, the object is expected
The build function is the thing #VipsObject calls during object
construction, after all arguments have been supplied and before the
object is used. It has two roles: to verify that arguments are correct,
and then to construct the object. After build(), the object is expected
to be ready for use.
<programlisting language="C">
@ -193,7 +221,8 @@ negative_build( VipsObject *object )
<para>
Next, it adds its own checks. This is a demo operation, so we just
work for uncoded, unsigned 8-bit images.
work for uncoded, unsigned 8-bit images. There are a lot of
convenience functions like vips_check_format(), see the docs.
</para>
<para>
@ -204,18 +233,35 @@ negative_build( VipsObject *object )
<para>
vips_image_pipelinev() links our new image onto the input image and
notes that this operation prefers to work in lines.
notes that this operation prefers to work in lines. You can request
other input geometries, see #VipsDemandStyle.
</para>
<para>
The geometry hint is just a hint, an operation needs to be able to
supply any size
#VipsRegion on request. If you must have a certain size request, you can
put a cache in the pipeline after your operation, see vips_linecache()
and vips_tilecache(). You can also make requests to your operation
ordered, see vips_sequential().
</para>
<para>
Finally, vips_image_generate() attaches a set of callbacks to the
output image to generate chunks of it on request. vips_start_one()
and vips_stop_one() are convenience functions that make the input
region for you.
region for you, see below.
</para>
</refsect3>
<refsect3 id="extending-gen">
<title>The generate() function</title>
<para>
And then the actual image processing.
The generate() function does the actual image processing.
negative_generate() (of type #VipsGenerateFn, supplied to
vips_image_generate() above) is
called whenever some pixels of our output image are required.
<programlisting language="C">
static int
@ -230,6 +276,7 @@ negative_generate( VipsRegion *or,
*/
VipsRegion *ir = (VipsRegion *) vseq;
VipsImage *in = (VipsImage *) a;
Negative *negative = (Negative *) b;
int line_size = r-&gt;width * negative-&gt;in-&gt;Bands;
@ -258,14 +305,57 @@ negative_generate( VipsRegion *or,
<para>
This has to calculate a section of the output image. The output
#VipsRegion, @or, contains a #VipsRect called @valid which is the
area needing calculation. negative_generate() asks for the
corresponding pixels from the input region, then loops over the
area. VIPS_REGION_ADDR() is a simple macro that does pointer arithmetic
for you: you need to stay within the valid area.
area needing calculation. This call to negative_generate() must
somehow make this part of @or contain pixel data.
</para>
<para>
To add the operation to vips, just call negative_get_type(). You
@vseq is the sequence value. This is the
per-thread state for this generate, created (in this example) by
vips_start_one(). In this simple case it's just a #VipsRegion defined on
the input image. If you need more per-thread state you can write your
own start and stop functions and have a struct you create and pass as a
sequence value. There are plenty of examples in the VIPS source code,
see vips_rank().
</para>
<para>
@a and @b are the last two arguments to vips_image_generate() above.
@stop is a bool pointer you can set to stop computation early. vips_min()
on an unsigned int image, for example, will set @stop as soon as it sees
a zero, and will not scan the entire image.
</para>
<para>
The first thing negative_generate() does is
use vips_region_prepare() to
ask for the corresponding pixels from the input image. Operations which
do coordinate transforms or which need an area of input for each output
point will need to calculate a new rect before calling
vips_region_prepare().
</para>
<para>
Finally, it can calculate some pixels. negative_generate() loops
over the valid area of the output and calls VIPS_REGION_ADDR() for each
line. This macro is reasonaly quick, but it's best not to call it for
each pixel. Once per line is fine though.
</para>
</refsect3>
<refsect3 id="extending-add">
<title>Adding to VIPS</title>
<para>
To add the operation to vips, just call negative_get_type(). You can
include the source in your program, or use %GModule to make a binary
plugin that will be loaded by libvips at startup. There are some <ulink
role="online-location"
url="https://github.com/jcupitt/vips-gmic">example
plugins available</ulink>.
</para>
<para>
You
can then use @negative from any of the vips interfaces. For example,
in Python you'd use it like this:
@ -324,10 +414,9 @@ if( negative( in, &amp;out, "image_max", 128, NULL ) )
and it's at least a bit safer.
</para>
</refsect3>
</refsect1>
<refsect1 id="extending-othertypes">
<refsect3 id="extending-othertypes">
<title>Other types of operation</title>
<para>
Change the _build() function to make other types of operation.
@ -368,6 +457,6 @@ if( negative( in, &amp;out, "image_max", 128, NULL ) )
Make zero-copy operations, like vips_insert(), with vips_region_region().
</para>
</refsect1>
</refsect3>
</refentry>

View File

@ -15,7 +15,7 @@
<refpurpose>The VIPS file format</refpurpose>
</refnamediv>
<refsect1 id="vips-format">
<refsect3 id="vips-format">
<title>Introduction</title>
<para>
VIPS has a simple, native file format. It's very fast, there is no image
@ -50,9 +50,9 @@ $ vips gamma t.v output.tif
Finally, after the pixel data comes an optional block of XML containing
any extra metadata, such as an ICC profile or the EXIF data.
</para>
</refsect1>
</refsect3>
<refsect1 id="vips-format-header">
<refsect3 id="vips-format-header">
<title>The header</title>
<para>
The fields in the VIPS header are always stored least-significant byte
@ -186,9 +186,9 @@ $ vips gamma t.v output.tif
</table>
</para>
</refsect1>
</refsect3>
<refsect1 id="vips-format-data">
<refsect3 id="vips-format-data">
<title>The image data</title>
<para>
If <code>coding</code> is set to #VIPS_CODING_NONE, pixels are stored in
@ -223,9 +223,9 @@ $ vips gamma t.v output.tif
section.
</para>
</refsect1>
</refsect3>
<refsect1 id="vips-format-metadata">
<refsect3 id="vips-format-metadata">
<title>The metadata</title>
<para>
Following the image data is a chunk of XML holding a simple list of
@ -240,6 +240,6 @@ $ vips gamma t.v output.tif
replace the XML.
</para>
</refsect1>
</refsect3>
</refentry>

View File

@ -15,7 +15,7 @@
<refpurpose>List of VIPS functions and operators</refpurpose>
</refnamediv>
<refsect1 id="function-list">
<refsect3 id="function-list">
<title>Function list</title>
<para>
VIPS has a set of operators, each of which computes some useful image
@ -1103,6 +1103,6 @@
</table>
</para>
</refsect1>
</refsect3>
</refentry>

View File

@ -15,7 +15,7 @@
<refpurpose>How to use the VIPS library from C</refpurpose>
</refnamediv>
<refsect1 id="using-C-intro">
<refsect3 id="using-C-intro">
<title>Introduction</title>
<para>
VIPS comes with a convenient, high-level C API. You should read the API
@ -23,9 +23,9 @@
overview. The <command>vips</command> program is handy for getting a
summary of an operation's parameters.
</para>
</refsect1>
</refsect3>
<refsect1 id="using-C-startup">
<refsect3 id="using-C-startup">
<title>Library startup</title>
<para>
When your program starts, use VIPS_INIT()
@ -40,9 +40,9 @@
You can add the VIPS flags to your %GObject command-line processing
with vips_add_option_entries(), see below.
</para>
</refsect1>
</refsect3>
<refsect1 id="using-C-vipsimage">
<refsect3 id="using-C-vipsimage">
<title>The #VipsImage class</title>
<para>
The basic data object is the #VipsImage. You can create an
@ -62,9 +62,9 @@
See <link linkend="libvips-header">VIPS Header</link> to read about
image properties.
</para>
</refsect1>
</refsect3>
<refsect1 id="using-C-ref">
<refsect3 id="using-C-ref">
<title>Reference counting</title>
<para>
VIPS is based on the %GObject library and is therefore reference counted.
@ -80,9 +80,9 @@
See #VipsOperation for more detail on VIPS
reference counting conventions.
</para>
</refsect1>
</refsect3>
<refsect1 id="using-C-operations">
<refsect3 id="using-C-operations">
<title>VIPS operations</title>
<para>
Use things like vips_invert() to manipulate your images. See
@ -92,9 +92,9 @@
the final image to a disc file, to a formatted memory buffer, or to
C-style memory array. See vips_image_write_to_file() and friends.
</para>
</refsect1>
</refsect3>
<refsect1 id="using-C-pixels">
<refsect3 id="using-C-pixels">
<title>Getting pixels</title>
<para>
Use #VipsRegion to read pixels out of images. You can use
@ -102,9 +102,9 @@
memory to work. See <link linkend="extending">extending</link>
for an introduction to writing your own operations.
</para>
</refsect1>
</refsect3>
<refsect1 id="using-C-errors">
<refsect3 id="using-C-errors">
<title>Error handling</title>
<para>
@ -112,9 +112,9 @@
linkend="libvips-error">VIPS Error</link> to find out how to get and
clear the error log.
</para>
</refsect1>
</refsect3>
<refsect1 id="using-C-example">
<refsect3 id="using-C-example">
<title>Example</title>
<example>
@ -184,6 +184,6 @@ main( int argc, char **argv )
</programlisting>
</example>
</refsect1>
</refsect3>
</refentry>

View File

@ -15,7 +15,7 @@
<refpurpose>How to use the VIPS library from the command-line</refpurpose>
</refnamediv>
<refsect1 id="using-command-line-intro">
<refsect3 id="using-command-line-intro">
<title>Introduction</title>
<para>
Use the <command>vips</command> command to execute VIPS operations from
@ -46,9 +46,9 @@ where:
There's a straightforward relationship with the C API: compare this to
the API docs for vips_rot(), for example.
</para>
</refsect1>
</refsect3>
<refsect1 id="using-command-line-list">
<refsect3 id="using-command-line-list">
<title>Listing all operations</title>
<para>
You can list all classes with:
@ -71,9 +71,9 @@ VipsOperation (operation), operations
<literal>VipsForeign</literal> will show some of the extra flags
supported by the file load/save operations.
</para>
</refsect1>
</refsect3>
<refsect1 id="using-command-line-options">
<refsect3 id="using-command-line-options">
<title>Optional arguments</title>
<para>
Many operations take optional arguments. You can supply these as
@ -109,9 +109,9 @@ $ vips gamma k2.jpg x.jpg --exponent 0.42
This will read file <literal>k2.jpg</literal>, un-gamma it, and
write the result to file <literal>x.jpg</literal>.
</para>
</refsect1>
</refsect3>
<refsect1 id="using-command-line-array">
<refsect3 id="using-command-line-array">
<title>Array arguments</title>
<para>
Some operations take arrays of values as arguments, for example,
@ -131,9 +131,9 @@ $ vips affine k2.jpg x.jpg "2 0 0 1"
$ vips bandjoin "k2.jpg k4.jpg" x.tif
</programlisting>
</para>
</refsect1>
</refsect3>
<refsect1 id="using-command-line-conversion">
<refsect3 id="using-command-line-conversion">
<title>Implicit file format conversion</title>
<para>
<command>vips</command> will automatically convert between image file
@ -163,9 +163,9 @@ vips affine k2.jpg x.jpg[Q=90,strip] "2 0 0 1"
Will write <literal>x.jpg</literal> at quality level 90 and will
strip all metadata from the image.
</para>
</refsect1>
</refsect3>
<refsect1 id="using-command-line-other">
<refsect3 id="using-command-line-other">
<title>Other features</title>
<para>
@ -195,6 +195,6 @@ vips affine k2.jpg x.jpg[Q=90,strip] "2 0 0 1"
images. <command>vipsthumbnail</command> can make image thumbnails
quickly.
</para>
</refsect1>
</refsect3>
</refentry>

View File

@ -15,7 +15,7 @@
<refpurpose>How to use the VIPS library from C++</refpurpose>
</refnamediv>
<refsect1 id="using-cpp">
<refsect3 id="using-cpp">
<title>Introduction</title>
<para>
VIPS comes with a convenient C++ API. It is a very thin wrapper over the
@ -219,9 +219,9 @@ VImage VImage::add( VImage right, VOption *options = 0 );
you can write to a memory array, to a formatted image in memory, or to
another image.
</para>
</refsect1>
</refsect3>
<refsect1 id="cpp-expansion">
<refsect3 id="cpp-expansion">
<title>Automatic constant expansion</title>
<para>
@ -256,9 +256,9 @@ VImage a = (a &lt; 128).ifthenelse( 128, a );
The C++ API includes the usual range of arithmetic operator overloads.
You can mix constants, vectors and images freely.
</para>
</refsect1>
</refsect3>
<refsect1 id="cpp-enum">
<refsect3 id="cpp-enum">
<title>Enum expansion</title>
<para>
@ -284,9 +284,9 @@ VImage VImage::sin( VOption *options = 0 );
</programlisting>
</para>
</refsect1>
</refsect3>
<refsect1 id="cpp-extend">
<refsect3 id="cpp-extend">
<title>Extending the C++ interface</title>
<para>
@ -326,5 +326,5 @@ VImage VImage::add(VImage right, VOption *options)
Where VImage::call() is the generic call-a-vips8-operation function.
</para>
</refsect1>
</refsect3>
</refentry>

View File

@ -15,7 +15,7 @@
<refpurpose>How to use the VIPS library from Python</refpurpose>
</refnamediv>
<refsect1 id="python-intro">
<refsect3 id="python-intro">
<title>Introduction</title>
<para>
VIPS comes with a convenient, high-level Python API based
@ -97,9 +97,9 @@ im = im.similarity(scale = 0.9, interpolate = Vips.Interpolate.new("bicubic"))
string containing the formatted image, and <code>.write()</code> to
write to another image.
</para>
</refsect1>
</refsect3>
<refsect1 id="python-basics">
<refsect3 id="python-basics">
<title><code>pyvips8</code> basics</title>
<para>
The Python interface comes in two main parts. First, the C source code
@ -126,9 +126,9 @@ from gi.repository import Vips
seem more pythonesque, vips includes a set of overrides which form a
layer over the bare functions created by gobject-introspection.
</para>
</refsect1>
</refsect3>
<refsect1 id="python-wrapping">
<refsect3 id="python-wrapping">
<title>Automatic wrapping</title>
<para>
The overrides intercept member lookup
@ -275,9 +275,9 @@ result_image = image1.bandjoin([image2, 255])
and so on.
</para>
</refsect1>
</refsect3>
<refsect1 id="python-doc">
<refsect3 id="python-doc">
<title>Automatic docstrings</title>
<para>
Try <code>help(Vips)</code> for everything,
@ -299,9 +299,9 @@ help(image.add)
And you'll get a summary of the operator's behaviour and how the
arguments are represented in Python. Use the C API docs for more detail.
</para>
</refsect1>
</refsect3>
<refsect1 id="python-exceptions">
<refsect3 id="python-exceptions">
<title>Exceptions</title>
<para>
The wrapper spots errors from vips operations and raises the
@ -309,9 +309,9 @@ help(image.add)
usual way. The <code>.detail</code> member gives the detailed
error message.
</para>
</refsect1>
</refsect3>
<refsect1 id="python-modify">
<refsect3 id="python-modify">
<title>Draw operations</title>
<para>
Paint operations like <code>draw_circle</code> and <code>draw_line</code>
@ -333,9 +333,9 @@ help(image.add)
If you want to avoid the copies, you'll need to call drawing
operations yourself.
</para>
</refsect1>
</refsect3>
<refsect1 id="python-overloads">
<refsect3 id="python-overloads">
<title>Overloads</title>
<para>
The wrapper defines the usual set of arithmetic, boolean and
@ -347,9 +347,9 @@ help(image.add)
result_image = ((image * [1, 2, 3]).abs() &lt; 128) | 4
</programlisting>
</para>
</refsect1>
</refsect3>
<refsect1 id="python-expansions">
<refsect3 id="python-expansions">
<title>Expansions</title>
<para>
Some vips operators take an enum to select an action, for example
@ -369,9 +369,9 @@ result_image = image.sin()
See <code>help(Vips.Image)</code> for a list.
</para>
</refsect1>
</refsect3>
<refsect1 id="python-utility">
<refsect3 id="python-utility">
<title>Convenience functions</title>
<para>
The wrapper defines a few extra useful utility functions:
@ -383,9 +383,9 @@ result_image = image.sin()
<code>.median()</code>.
Again, see <code>help(Vips.Image)</code> for a list.
</para>
</refsect1>
</refsect3>
<refsect1 id="python-args">
<refsect3 id="python-args">
<title>Command-line option parsing</title>
<para>
GLib includes a command-line option parser, and Vips defines a set of
@ -405,6 +405,6 @@ context.parse(sys.argv)
</programlisting>
</para>
</refsect1>
</refsect3>
</refentry>