Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed drawing translucent 1px high polygons #6278

Merged
merged 1 commit into from Jun 4, 2022

Conversation

radarhere
Copy link
Member

@radarhere radarhere commented May 6, 2022

Resolves #6275. It doesn't change the behaviour of the code from that issue, but it addresses a concern raised there.

Background

PR #4333 adjusted polygon_generic to only draw each pixel once, so that repeated translucent pixels do not combine to produce a different final opacity.
PR #5835 limited this new approach to only run when there was translucency involved, for the sake of performance.

Issue #6275 has found a situation where #4333 changed not just the final opacity, but which pixels were drawn. Because #6275 doesn't involve translucency, #5835 changed it back, but the missing pixels are still missing when there is translucency involved.


This PR fixes that unexpected change.

The scanline algorithm detects where edges intersect with each row of an image, storing them in xx.
It works its way along each row, keeping track with x_pos of the current position, so that pixels are not redrawn.
Horizontal lines do not contribute to the intersections, so it draws them separately as it goes, both partway through the row and at the end.
However, if there are no intersections (if j is zero), then when it goes to draw those end lines, they are skipped, as it thinks they are still to come.
So this PR instead sets x_pos to a special value if there are no intersections. If there are no intersections in this row, then the horizontal lines should just be drawn.

@radarhere radarhere changed the title Always draw first segment in each translucent polygon line Fixed drawing translucent 1px high polygons May 6, 2022
@hugovk hugovk merged commit 38931c1 into python-pillow:main Jun 4, 2022
@radarhere radarhere deleted the polygon branch June 4, 2022 06:39
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.

ImageDraw.polygon regression if polygon is a line
2 participants