Repository navigation
Fill through pixels that already have the fill color when border is given - #10714
farisbasha wants to merge 2 commits into
Conversation
|
I verified the traversal fix at from PIL import Image, ImageDraw
im = Image.frombytes('L', (3, 1), bytes([0, 2, 0]))
ImageDraw.floodfill(im, (1, 0), 2, border=2)
print(list(im.tobytes()))
Tested patch. It handles alternate border color encodings while preserving scalar comparisons, exits for a border-colored seed, and normalizes the seed coordinates before traversal. The previous-frontier tracking still works. On Windows, 27 focused tests passed using the patched OpenAI Codex assisted with the patch and verification. |
|
Thanks, both are real regressions from my change. Fixed in 26d885c:
I added tests for both cases. |
Fixes #10712.
Changes proposed in this pull request:
border,floodfill()now treats a pixel that already has the fill color as part of the region, as the docs say ("pixels with a color different from the border color"). Before, such a pixel acted as a second border, and the area behind it was not filled.border, the early return when the seed pixel already has the fill color is skipped, so the fill still spreads from it. Withoutbordernothing changes.mainand pass with this change.About visiting pixels twice (mentioned in the issue): no extra set is needed. On a 4-connected grid, the neighbors of a pixel in the current edge are always in the previous edge (kept in
full_edge) or in the next one, so a pixel is not processed again. On the server I compared the new code with a simple BFS fill on 300 random images (0 differences), and an 800x800 image that is already all fill color takes about the same time as a plain one.Tests/test_imagedraw.pypasses (278 passed), andruff check/ruff format --checkare clean.This change was written with help from an AI coding assistant (Claude).