Fix Pillow examples using frombuffer#535
Merged
Merged
Conversation
The Pillow docs recommend always using the decoder arguments when using frombuffer; see https://pillow.readthedocs.io/en/stable/reference/Image.html
jholveck
marked this pull request as ready for review
June 2, 2026 03:54
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Updates Pillow usage across tests, docs examples, and demos to follow Pillow’s recommended Image.frombuffer raw decoder argument form, and adjusts v11.0.0 release notes around ScreenShot.raw.
Changes:
- Add explicit raw decoder args (
..., "BGRX", 0, 1) toPIL.Image.frombufferusage in tests, docs examples, and demos. - Update v11.0.0 release notes to describe
ScreenShot.rawas deprecated (not removed) and add a documentation highlights section.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/tests/third_party/test_pil.py | Makes Image.frombuffer call explicit about raw decoder args in tests. |
| docs/source/release-history/v11.0.0.md | Adjusts ScreenShot.raw lifecycle wording; adds documentation highlights entry about Pillow decoder args. |
| docs/source/examples/pil.py | Updates documented Pillow example to pass explicit raw decoder args (incl. commented alternative). |
| demos/video-capture-simple.py | Updates demo conversion from MSS BGRA to Pillow image with explicit raw decoder args. |
| demos/tinytv-stream.py | Updates stream generator to create Pillow image with explicit raw decoder args. |
| demos/tinytv-stream-simple.py | Updates simple TinyTV demo to create Pillow image with explicit raw decoder args. |
| demos/cat-detector.py | Updates demo image conversion step to use explicit raw decoder args. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Contributor
Author
|
Sorry, accidentally turned on the switch to automatically have Copilot check all my PRs. |
jholveck
added a commit
to jholveck/python-mss
that referenced
this pull request
Jun 2, 2026
In the release notes, one change was accidentally in PR BoboTiG#535 instead, and one change was omitted entirely. Fix.
BoboTiG
pushed a commit
that referenced
this pull request
Jun 26, 2026
* Make the data views writable. Previously (while working on 11.0), we changed the .bgra and .rgb attributes to be read-only memoryviews. We also removed the .raw attribute. The main reason we made the memoryviews read-only is so that we don't have to worry about cached values of .pixels and .rgb being in-sync with the underlying buffer, if users mutated the pixel data. However, I now realize that this takes away a possible valuable use case: ctypes. ctypes can only create an array (or pointer) from a buffer if it's writable; it doesn't support a read-only version. Previously, users could make a ctypes pointer using the .raw attribute. The new API doesn't give them that ability, without copying the data (or using ctypes' from_address, which is perilous). Read-only buffers also trigger a warning from PyTorch, although it's clearly-written and only is printed once. This PR, as it stands, makes the `.bgra` and `.rgb` properties return writable memoryviews. (It also restores `.raw`, this time as a deprecated alias of bgra, since there's no pressing need to remove the name entirely.) It also documents that, while these memoryviews are writable, actually modifying the data may cause undefined behavior. There's alternatives, of course. Instead of what I've got here, ChatGPT instead suggests that we leave .bgra and .rgb read-only (as they were in 10.2, since they were `bytes` objects), and to add a property like `.writable_bgra` or something. Its argument is as follows: > The problem with making .bgra writable and saying “mutating is UB > [undefined behavior]” is that Python users will absolutely see > writable buffer and think “cool, in-place image editing.” That’s > not UB in the fun C sense; it’s more like “congratulations, you have > a weird cache-invalidation footgun.” The API shape would be lying a > little. I'm making this PR for discussion and consensus on the best way to go. * Update release notes In the release notes, one change was accidentally in PR #535 instead, and one change was omitted entirely. Fix. * Apply suggestions from code review Co-authored-by: Halldor Fannar <halldorfannar@users.noreply.github.com> --------- Co-authored-by: Halldor Fannar <halldorfannar@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The Pillow docs recommend always using the decoder arguments when using frombuffer; see
https://pillow.readthedocs.io/en/stable/reference/Image.html
Changes proposed in this PR
./check.shpassed