pyvips icon indicating copy to clipboard operation
pyvips copied to clipboard

GLib-ERROR - gmem.c - failed to allocate n bytes

Open petoor opened this issue 5 years ago • 5 comments

Hi.

Im trying to save a large image into tile format. I'm using python 3.6.9 and the code : x = pyvips.Image.new_from_file("test.ndpi", access="sequential") x.dzsave("test_folder")

Which works fine in verison 8.4.5.

But in the latest version 8.9.1: GLib-ERROR **: 12:00:36.791: ../../../../glib/gmem.c:135: failed to allocate 32105299968 bytes when trying to use dzsave.

The image is : <pyvips.Image 110592x96768 uchar, 4 bands, rgb>

petoor avatar Jan 20 '20 11:01 petoor

Hello @petoor,

I think it's trying to open your NDPI image with libtiff instead of openslide. Try:

x = pyvips.Image.openslideload("something.ndpi")

jcupitt avatar Jan 20 '20 12:01 jcupitt

Can confirm. Opening the image with openslideload fixes the problem.

Is there a rule of thumb as to when which loader should be used? For the diffrent formats supported by vips.

petoor avatar Jan 20 '20 15:01 petoor

It was a bug in 8.9.0, it should be fixed in 8.9.1. I see:

$ python3
Python 3.7.5 (default, Nov 20 2019, 09:21:52) 
[GCC 9.2.1 20191008] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pyvips
>>> x = pyvips.Image.new_from_file("bild.ndpi")
>>> x.get("vips-loader")
'openslideload'

jcupitt avatar Jan 20 '20 16:01 jcupitt

Actually I'm not sure pyvips had this bug, I think it was just the vips CLI. I tried:

$ git checkout v8.9.0
$ CFLAGS="-g -Wall" CXXFLAGS="-g -Wall" ./autogen.sh --prefix=/home/john/vips
$ make install > fred
$ pip3 uninstall pyvips
Skipping pyvips as it is not installed.
$ pip3 install pyvips --no-cache
Collecting pyvips
  Downloading https://files.pythonhosted.org/packages/f2/1d/69450110de9295f6fb4a9cb03602d954c05ca55618d9c88e6dc88d333050/pyvips-2.1.11.tar.gz
Requirement already satisfied: cffi>=1.0.0 in /home/john/.local/lib/python3.7/site-packages (from pyvips) (1.12.3)
Requirement already satisfied: pkgconfig in /home/john/.local/lib/python3.7/site-packages (from pyvips) (1.5.1)
Requirement already satisfied: pycparser in /home/john/.local/lib/python3.7/site-packages (from cffi>=1.0.0->pyvips) (2.19)
Installing collected packages: pyvips
  Running setup.py install for pyvips ... done
Successfully installed pyvips-2.1.11
$ python3
Python 3.7.5 (default, Nov 20 2019, 09:21:52) 
[GCC 9.2.1 20191008] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pyvips
>>> x = pyvips.Image.new_from_file("bild.ndpi")
>>> x.get("vips-loader")
'openslideload'

So I think (with Python) it ought to work with 8.9.0 too. Perhaps your libvips 8.9 has been built without openslide support?

The 8.9.0 bug was vipsheader not selecting openslideload correctly. With 8.9.0 you'll see:

$ vipsheader bild.ndpi 
bild.ndpi: 126976x98304 uchar, 3 bands, srgb, tiffload_source

Though pyvips should work correctly. But with 8.9.1 you see:

$ vipsheader bild.ndpi 
bild.ndpi: 126976x98304 uchar, 4 bands, srgb, openslideload

ie. the CLI picks the loader correctly.

jcupitt avatar Jan 20 '20 16:01 jcupitt

The problem seemed to be that the initial build did not have libopenslide-dev installed while building. (It is optionallyin : https://github.com/libvips/libvips/wiki/Build-for-Ubuntu)

So, no, i dont think there was a problem in nither 8.9.1 or 8.9.0.

In this case, it would make sense to throw an exception / warning to the user when trying to use openslideload without libopenslide installed.

Thank you for the help

petoor avatar Jan 20 '20 16:01 petoor