Skip to content

Commit 3bc8e84

Browse files
committed
update docs for new classes
1 parent 8e76133 commit 3bc8e84

10 files changed

+154
-40
lines changed

doc/gvalue.rst

+1
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ this class to get and set :class:`.GObject` properties.
88

99
.. automodule:: pyvips.gvalue
1010
:members:
11+

doc/index.rst

+5
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ Contents
2020
base
2121
error
2222
enums
23+
vconnection
24+
vsource
25+
vtarget
26+
vsourcecustom
27+
vtargetcustom
2328
vinterpolate
2429
gvalue
2530
gobject

doc/intro.rst

+104-31
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Reading this example line by line, we have::
2929

3030
image = pyvips.Image.new_from_file('some-image.jpg', access='sequential')
3131

32-
:meth:`.new_from_file` can load any image file supported by libvips. In
32+
:meth:`.Image.new_from_file` can load any image file supported by libvips. In
3333
this example, we will be accessing pixels top-to-bottom as we sweep through
3434
the image reading and writing, so `sequential` access mode is best for us.
3535

@@ -120,7 +120,7 @@ it.
120120
NumPy and PIL
121121
-------------
122122

123-
You can use :meth:`.write_to_memory` and :meth:`.new_from_memory` to pass
123+
You can use :meth:`.write_to_memory` and :meth:`.Image.new_from_memory` to pass
124124
buffers of pixels between PIL, NumPy and pyvips. For example::
125125

126126
import pyvips
@@ -276,18 +276,6 @@ Add these lines somewhere near the start of your program::
276276
logging.basicConfig(level=logging.WARNING)
277277

278278

279-
Automatic documentation
280-
-----------------------
281-
282-
The bulk of these API docs are generated automatically by
283-
:meth:`.Operation.generate_sphinx_all`. It examines libvips and writes a
284-
summary of each operation and the arguments and options that that operation
285-
expects.
286-
287-
Use the C API docs for more detail:
288-
289-
https://libvips.github.io/libvips/API/current
290-
291279
Exceptions
292280
----------
293281

@@ -301,23 +289,6 @@ The libvips enums, such as ``VipsBandFormat``, appear in pyvips as strings
301289
like ``'uchar'``. They are documented as a set of classes for convenience, see
302290
:class:`.Access`, for example.
303291

304-
Draw operations
305-
---------------
306-
307-
Paint operations like :meth:`.Image.draw_circle` and
308-
:meth:`.Image.draw_line` modify their input image. This makes them
309-
hard to use with the rest of libvips: you need to be very careful about
310-
the order in which operations execute or you can get nasty crashes.
311-
312-
The wrapper spots operations of this type and makes a private copy of the
313-
image in memory before calling the operation. This stops crashes, but it does
314-
make it inefficient. If you draw 100 lines on an image, for example, you'll
315-
copy the image 100 times. The wrapper does make sure that memory is recycled
316-
where possible, so you won't have 100 copies in memory.
317-
318-
If you want to avoid the copies, you'll need to call drawing operations
319-
yourself.
320-
321292
Overloads
322293
---------
323294

@@ -348,3 +319,105 @@ The wrapper defines a few extra useful utility functions:
348319
:meth:`.bandsplit`, :meth:`.maxpos`, :meth:`.minpos`,
349320
:meth:`.median`.
350321

322+
Tracking and interrupting computation
323+
-------------------------------------
324+
325+
You can attach progress handlers to images to watch the progress of
326+
computation.
327+
328+
For example::
329+
330+
image = pyvips.Image.black(1, 500)
331+
image.set_progress(True)
332+
image.signal_connect('preeval', preeval_handler)
333+
image.signal_connect('eval', eval_handler)
334+
image.signal_connect('posteval', posteval_handler)
335+
image.avg()
336+
337+
Handlers are given a `progress` object containing a number of useful fields.
338+
For example::
339+
340+
def eval_handler(image, progress):
341+
print('run time so far (secs) = {}'.format(progress.run))
342+
print('estimated time of arrival (secs) = {}'.format(progress.eta))
343+
print('total number of pels to process = {}'.format(progress.tpels))
344+
print('number of pels processed so far = {}'.format(progress.npels))
345+
print('percent complete = {}'.format(progress.percent))
346+
347+
Use :meth:`.Image.set_kill` on the image to stop computation early.
348+
349+
For example::
350+
351+
def eval_handler(image, progress):
352+
if progress.percent > 50:
353+
image.set_kill(True)
354+
355+
Custom sources and targets
356+
--------------------------
357+
358+
You can load and save images to and from :class:`.Source` and
359+
:class:`.Target`.
360+
361+
For example::
362+
363+
source = pyvips.Source.new_from_file("some/file/name")
364+
image = pyvips.Image.new_from_source(source, "", access="sequential")
365+
target = pyvips.Target.new_to_file("some/file/name")
366+
image.write_to_target(target, ".png")
367+
368+
Sources and targets can be files, descriptors (eg. pipes) and areas of memory.
369+
370+
You can define :class:`.SourceCustom` and :class:`.TargetCustom` too.
371+
372+
For example::
373+
374+
input_file = open(sys.argv[1], "rb")
375+
376+
def read_handler(size):
377+
return input_file.read(size)
378+
379+
source = pyvips.SourceCustom()
380+
source.on_read(read_handler)
381+
382+
output_file = open(sys.argv[2], "wb")
383+
384+
def write_handler(chunk):
385+
return output_file.write(chunk)
386+
387+
target = pyvips.TargetCustom()
388+
target.on_write(write_handler)
389+
390+
image = pyvips.Image.new_from_source(source, '', access='sequential')
391+
image.write_to_target(target, '.png')
392+
393+
You can also define seek and finish handlers, see the docs.
394+
395+
Automatic documentation
396+
-----------------------
397+
398+
The bulk of these API docs are generated automatically by
399+
:meth:`.Operation.generate_sphinx_all`. It examines libvips and writes a
400+
summary of each operation and the arguments and options that that operation
401+
expects.
402+
403+
Use the C API docs for more detail:
404+
405+
https://libvips.github.io/libvips/API/current
406+
407+
Draw operations
408+
---------------
409+
410+
Paint operations like :meth:`.Image.draw_circle` and
411+
:meth:`.Image.draw_line` modify their input image. This makes them
412+
hard to use with the rest of libvips: you need to be very careful about
413+
the order in which operations execute or you can get nasty crashes.
414+
415+
The wrapper spots operations of this type and makes a private copy of the
416+
image in memory before calling the operation. This stops crashes, but it does
417+
make it inefficient. If you draw 100 lines on an image, for example, you'll
418+
copy the image 100 times. The wrapper does make sure that memory is recycled
419+
where possible, so you won't have 100 copies in memory.
420+
421+
If you want to avoid the copies, you'll need to call drawing operations
422+
yourself.
423+

doc/vconnection.rst

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.. include global.rst
2+
3+
``Connection``
4+
==============
5+
6+
.. automodule:: pyvips.vconnection
7+
:members:

doc/vsource.rst

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.. include global.rst
2+
3+
``Source``
4+
==========
5+
6+
.. automodule:: pyvips.vsource
7+
:members:

doc/vsourcecustom.rst

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.. include global.rst
2+
3+
``SourceCustom``
4+
================
5+
6+
.. automodule:: pyvips.vsourcecustom
7+
:members:

doc/vtarget.rst

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.. include global.rst
2+
3+
``Target``
4+
==========
5+
6+
.. automodule:: pyvips.vtarget
7+
:members:

doc/vtargetcustom.rst

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.. include global.rst
2+
3+
``TargetCustom``
4+
================
5+
6+
.. automodule:: pyvips.vtargetcustom
7+
:members:

examples/stream.py renamed to examples/connection.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ def seek_handler(offset, whence):
1515
return input_file.tell()
1616

1717

18-
input_stream = pyvips.Streamiu()
19-
input_stream.on_read(read_handler)
20-
input_stream.on_seek(seek_handler)
18+
source = pyvips.SourceCustom()
19+
source.on_read(read_handler)
20+
source.on_seek(seek_handler)
2121

2222
output_file = open(sys.argv[2], "wb")
2323

@@ -30,9 +30,9 @@ def finish_handler():
3030
output_file.close()
3131

3232

33-
output_stream = pyvips.Streamou()
34-
output_stream.on_write(write_handler)
35-
output_stream.on_finish(finish_handler)
33+
target = pyvips.TargetCustom()
34+
target.on_write(write_handler)
35+
target.on_finish(finish_handler)
3636

37-
image = pyvips.Image.new_from_stream(input_stream, '', access='sequential')
38-
image.write_to_stream(output_stream, '.png')
37+
image = pyvips.Image.new_from_source(source, '', access='sequential')
38+
image.write_to_target(target, '.png')

pyvips/vimage.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,7 @@ def set_kill(self, kill):
704704
"""Kill processing of an image.
705705
706706
Use this to kill evaluation of an image. You can call it from one of
707-
the progress signals, for example. See :method:`set_progress`.
707+
the progress signals, for example. See :meth:`.set_progress`.
708708
709709
"""
710710
vips_lib.vips_image_set_kill(self.pointer, kill)

0 commit comments

Comments
 (0)