When we image_new_from_source, the source object has some of the loader
state: it tracks the current read position of the load library. This
means that we mustn't keep source loaders in the operation cache, since
a second call could give a different result because the source object
read position might have changed.
Also: add a rewind to get_flags_source in spngload, and jp2k needs to
tag its load region as having no thread ownership or you'll get assert
fails in the test suite with debug enabled.
This patch makes "insert" issue minimise signals for inputs in sequential
mode. This can drop memory use in some programs, for example:
```python
import sys
import random
import pyvips
image = pyvips.Image.black(20000, 20000)
for filename in sys.argv[2:]:
tile = pyvips.Image.new_from_file(filename, access='sequential')
x = random.randint(0, image.width - tile.width)
y = random.randint(0, image.height - tile.height)
image = image.insert(tile, x, y)
image.write_to_file(sys.argv[1])
```
Before this patch:
```
$ for i in {0..1000}; do cp ~/pics/k2.jpg $i.jpg; done
$ /usr/bin/time -f %M:%e ../manyjoin.py ../x.jpg *.jpg
5456256:4.34
```
With this patch:
```
$ /usr/bin/time -f %M:%e ../manyjoin.py ../x.jpg *.jpg
2475324:3.38
```
This patch makes arrayjoin leave a bigger margin off the end of each
input image. This can help some loaders which have large output caches.
See https://github.com/libvips/libvips/issues/2440
Instead of a simple fail/don't-fail boolean switch, add fail-on, an enum which sets the sensitivity of loaders to errors.
There's a new sensitivity level which tries to detect truncated images, but ignores other types of error.
tell buffer and target savers the file format
Currently, buffer and target savers are not told the format they should
write.
This is usually OK (the JPEG saver already knows it should write JPEG),
but some savers can write several formats, and these currently need an
extra parameter.
For example:
```ruby
buf = x.write_to_buffer ".bmp", format: "bmp"
```
The first ".bmp" gets libvips to pick magicksave, the second
`format:` param is necessary to tell magicksave to write BMP.
This patch adds stub subclasses so that the savers know the exact format. It also improves PPM save.