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

Only draw each polygon pixel once #4333

Merged
merged 1 commit into from Feb 15, 2020
Merged

Conversation

radarhere
Copy link
Member

Helps #4277

When Pillow draws an ellipse, it considers it to be a 360-sided shape. Expressing that within an ordinary width and height means that those edges overlap.

In such a situation, the polygon_generic function will draw pixels more than once. This is usually unnoticed, since a solid pixel on top of another solid pixel is still just a solid pixel. However, if the pixels drawn have a partial opacity, then repeated drawing of a pixel changes the final opacity.

from PIL import Image, ImageDraw
im = Image.new('RGB', (45, 45), (255, 255, 255))
d = ImageDraw.Draw(im, 'RGBA')
d.ellipse([(0, 0), (45, 45)], (0, 0, 255, 100))
im.save('out.png')

out

As background, the polygon_generic function uses a scanline algorithm, drawing each row in turn,. Within each row, it starts drawing a line at the edge of a polygon, stops at the next edge, starts at the following edge, and so on.

This PR updates the function to only draw each pixel once.

out

@hugovk
Copy link
Member

hugovk commented Feb 15, 2020

Thanks!

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.

None yet

2 participants