GNOME Bugzilla – Bug 447388
pixbuf.get_pixels_array() doesn't correctly flag the array as non-contiguous
Last modified: 2018-08-17 13:43:39 UTC
Please describe the problem: If a pixbuf has padded rows (rowstride != width * nchannels) then the array returned by pixbuf.get_pixels_array() is constructed as not "contiguous" to use the Numeric term. The code that creates the array sets the correct stride, but doesn't a flag that is required to mark the array as not contiguous. Missing this flag means that some operations, like array.tostring() will get things wrong. Steps to reproduce: Given a PNG image without an alpha channel where (width * 3) % 4 is not zero: pixbuf = gtk.gdk.pixbuf_new_from_file('width=17.png') array = pixbuf.get_pixels_array() string = array.tostring() array1 = Numeric.fromstring(string, 'b') array1.shape = array.shape pixbuf1 = gtk.gdk.pixbuf_new_from_array(array1, gtk.gdk.COLORSPACE_RGB, 8) pixbuf1.save('output.png', 'png') Actual results: The output image will be sheared, with each line one pixel off from the previous one. Different widths will give different shears, and change colours. Expected results: The output image should be identical to the input. Does this happen every time? Yes. Other information: I'll attach a patch that fixes this bug.
Created attachment 89926 [details] [review] Patch against pygtk-2.10.4 that fixes this bug
(In reply to comment #1) > Created an attachment (id=89926) [edit] > Patch against pygtk-2.10.4 that fixes this bug > Looks good, could you integrate your small test case into the pygtk testsuite and include in the patch?
Created attachment 89984 [details] Test case, including two images that is uses Here is a test case for it. Couldn't make it a patch as I wanted to include a couple of test image files with it.
I have hit this problem too, is there any issue holding the fix off?
Thanks Tim, patch applied. We are going to change from Numeric to numpy, if you have some time could you update your test to numpy? Please reopen and attach a patch if you feel like it.
Sorry for reopening the bug but it doesn't work with Numpy, we had no releases after this was committed. I think it's more important to ship with numpy support instead of Numeric which is 6 years old and with no maintenance at all. Tim could you see what you can do to adapt the patch with numpy? I'll try to do it myself but I guess for you will be a lot easier... thanks!
Created attachment 220403 [details] [review] Patch against pygtk-2.24.0 that fixes this bug Better late than never? I didn't have a environment to build against numpy when this was reopened, and it slipped my mind to look into it.
Created attachment 220407 [details] Patch against pygtk-2.24.0 that fixes this bug Fixed the patch to make the returned array writeable.
pygtk is not under active development anymore and had its last code changes in 2013. Its codebase has been archived: https://gitlab.gnome.org/Archive/pygtk/commits/master PyGObject at https://gitlab.gnome.org/GNOME/pygobject is its successor. See https://pygobject.readthedocs.io/en/latest/guide/porting.html for porting info. Closing this report as WONTFIX as part of Bugzilla Housekeeping to reflect reality. Feel free to open a task in GNOME Gitlab if the issue described in this task still applies to a recent version of PyGObject. Thanks!