Skip to content

Conversation

@ty-porter
Copy link
Contributor

@ty-porter ty-porter commented Oct 27, 2025

Supersedes #1817 and resolves #1769

Previous PR was broken -> image.im.getim() should have been image.getim()

Second, using PyCapsules means we need precise byte offsets into the image structs (in this case ImagingMemoryInstance they contain in order to access the image frame. get_unsafe_ptrs() did this for us previously.

https://github.com/python-pillow/Pillow/blob/e36e67081ae9d4162f5254ce6f3c1478fc342d9c/src/libImaging/Imaging.h#L80

Unfortunately it's not trivial, the first attribute mode specifically is not stable and is changing from char[] to struct* to enum value between Pillow 11 / 12, so the offsets are not stable.

Cython also cannot compile the header we need natively:

# doesn't work because Cython can't handle typedef *
cdef extern from "Imaging.h":
    cdef struct ImagingMemoryInstance:
        pass # Filled out from header

Instead, this PR creates a simple C shim that hides ImagingMemoryInstance and provides portable access to the image32 field needed for fast SetImage()

Retested this change on a fresh install of Pi OS Bookworm, I think the fact the previous PR worked was a competing installation.

@ty-porter ty-porter marked this pull request as ready for review October 27, 2025 14:32
@MikeRogers27
Copy link

Which version of pillow should I be installing? <12 or is 12 and above fine with this PR?

@ty-porter
Copy link
Contributor Author

<12 is compatible prior to this PR. After this, all versions should be

@MorganKryze
Copy link

Hi! I am facing this issue and am curious about when you think the PR could be merged?
Thanks for your time!

@WeegeeNumbuh1
Copy link

Also awaiting this PR merge. Recently built a new RGB matrix system using the latest Raspberry Pi OS and found out a part of one of my projects no longer works due to PIL 12.0.

This fix will also benefit the people that use the Adafruit guide for implementing this library with Python as PIL is now at 12 and the older commits that their build script pulls will no longer work moving forward.

@marcmerlin
Copy link
Collaborator

Just to put things in context, I didn't write this driver, and I do not use its python interface, at all. I wanted @hzeller to have a chance to look at this PR, but my understanding is that he doesn't really have time to work on this code, so I'm going to trust your work and merge this.

@marcmerlin marcmerlin merged commit 3a5d753 into hzeller:master Nov 8, 2025
2 checks passed
@marcmerlin
Copy link
Collaborator

Everyone affected, please confirm head now fixes your issues with this.

@WeegeeNumbuh1
Copy link

Everyone affected, please confirm head now fixes your issues with this.

@marcmerlin I just built it and can confirm this merge fixes the issue and it works on my end (to the extent that my project uses these bindings)

@marcmerlin
Copy link
Collaborator

Perfect, thank you both

@hzeller
Copy link
Owner

hzeller commented Nov 8, 2025

Thanks for merging @marcmerlin !
The Python code is an external contribution and I also have never used it, nor can I read Python code; so no need to wait for me for merging.

@marcmerlin
Copy link
Collaborator

@ty-porter since no one with commit access is actually using the python bindings, would you be interested in being the python binding maintainer for this project? We can also go in the commit logs and see how else submitted the original bindings and recent fixes.

@ty-porter
Copy link
Contributor Author

@marcmerlin Sure, I'm happy to help out.

@marcmerlin
Copy link
Collaborator

Thanks. Let's start with
#1753

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python bindings: Matrix.SetImage uses deprecated Pillow APIs

6 participants