Repository navigation
Stop using Pillow's deprecated getdata() in tile maps - #2927
Merged
Merged
Conversation
An image layer's transparent color was applied by reading every pixel with Image.getdata(), which Pillow 14 removes (it warns now), and writing them back with putdata(). Arcade still supports Pillow 11.3, which doesn't have the suggested get_flattened_data(), so use Pillow operations instead: a mask of the pixels matching the color in all three bands, and a paste of transparent white through it. The result is byte for byte the same as before, and it's faster: a 1024x600 image went from 76 ms to 4 ms. Adds a test map with a transparent color, since no test covered this. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.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.
Summary
Removes Arcade's only use of Pillow's deprecated
Image.getdata(), which Pillow 14 removes (October 2027). Pillow 12.2 already warns:It was in
TileMap, applying an image layer'stransparentcolor: it read every pixel into a Python list, replaced the matching ones, and wrote them all back withputdata().The fix
Arcade supports
pillow>=11.3.0, which doesn't have the suggestedget_flattened_data(), so I used Pillow operations instead. The new helper_make_color_transparent():Image.pointto mode"1"per band, thenImageChops.logical_and);These calls are much older than Pillow 11.3. As before, the alpha of the matching pixels doesn't matter, and the image is changed in place.
Same result, faster: I compared old and new on three images: the JPEG background used by the image-layer test map, a PNG sprite sheet, and a tile. I tried each with its most common color, white, and a color that never appears. The output is byte-for-byte identical in every case. Times:
abstract_1.jpg, 1024×600grassMid.png, 128×128number_sheet.png, 48×32The two imports only the old loop used (
Sequence,RGBA255) are removed.Tests
No test covered this code, so I added:
tests/fixtures/tilemaps/image_layer_transparent.json: an image layer showingnumber_sheet.pngwith"transparentcolor": "#ffffff".test_image_layer_transparent_color: the loaded layer's white pixels (1375 of them) become(255, 255, 255, 0), and every other pixel is unchanged.test_make_color_transparent: a 4-pixel image covering a match, a match with partial alpha, a color with one band off by one, and a color that doesn't match.With warnings turned into errors, loading the new map raises the
DeprecationWarningondevelopmentand loads cleanly with this PR.Full suite: 1573 passed, no warnings, plus the 3 render tests that fail only on my machine. #2926 fixes those, and this branch doesn't include it yet. mypy has no new errors, and ruff is clean.
The changelog has an entry under Unreleased → Misc Changes.
🤖 Generated with Claude Code