After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 447388 - pixbuf.get_pixels_array() doesn't correctly flag the array as non-contiguous
pixbuf.get_pixels_array() doesn't correctly flag the array as non-contiguous
Status: RESOLVED WONTFIX
Product: pygtk
Classification: Bindings
Component: gdk
2.10.x
Other All
: Normal normal
: ---
Assigned To: Nobody's working on this now (help wanted and appreciated)
Python bindings maintainers
gnome[unmaintained]
Depends on:
Blocks:
 
 
Reported: 2007-06-14 02:35 UTC by Tim Evans
Modified: 2018-08-17 13:43 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Patch against pygtk-2.10.4 that fixes this bug (938 bytes, patch)
2007-06-14 02:36 UTC, Tim Evans
needs-work Details | Review
Test case, including two images that is uses (6.59 KB, application/x-compressed-tar)
2007-06-15 01:54 UTC, Tim Evans
  Details
Patch against pygtk-2.24.0 that fixes this bug (1.43 KB, patch)
2012-08-05 23:55 UTC, Tim Evans
none Details | Review
Patch against pygtk-2.24.0 that fixes this bug (1.21 KB, application/octet-stream)
2012-08-06 00:49 UTC, Tim Evans
  Details

Description Tim Evans 2007-06-14 02:35:28 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.
Comment 1 Tim Evans 2007-06-14 02:36:44 UTC
Created attachment 89926 [details] [review]
Patch against pygtk-2.10.4 that fixes this bug
Comment 2 Johan (not receiving bugmail) Dahlin 2007-06-14 02:40:48 UTC
(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?
Comment 3 Tim Evans 2007-06-15 01:54:22 UTC
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.
Comment 4 Martin Renold 2008-10-25 15:05:33 UTC
I have hit this problem too, is there any issue holding the fix off?
Comment 5 Gian Mario Tagliaretti 2009-02-22 20:44:28 UTC
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.
Comment 6 Gian Mario Tagliaretti 2009-04-06 21:35:55 UTC
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!
Comment 7 Tim Evans 2012-08-05 23:55:19 UTC
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.
Comment 8 Tim Evans 2012-08-06 00:49:59 UTC
Created attachment 220407 [details]
Patch against pygtk-2.24.0 that fixes this bug

Fixed the patch to make the returned array writeable.
Comment 9 André Klapper 2018-08-17 13:43:39 UTC
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!