Skip to content

Commit

Permalink
Merge pull request python-pillow#6278 from radarhere/polygon
Browse files Browse the repository at this point in the history
Fixed drawing translucent 1px high polygons
  • Loading branch information
hugovk authored Jun 4, 2022
2 parents b43cfce + c824ab0 commit 38931c1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions Tests/test_imagedraw.py
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,20 @@ def test_polygon_1px_high():
assert_image_equal_tofile(im, expected)


def test_polygon_1px_high_translucent():
# Test drawing a translucent 1px high polygon
# Arrange
im = Image.new("RGB", (4, 3))
draw = ImageDraw.Draw(im, "RGBA")
expected = "Tests/images/imagedraw_polygon_1px_high_translucent.png"

# Act
draw.polygon([(1, 1), (1, 1), (3, 1), (3, 1)], (255, 0, 0, 127))

# Assert
assert_image_equal_tofile(im, expected)


def test_polygon_translucent():
# Arrange
im = Image.new("RGB", (W, H))
Expand Down
4 changes: 2 additions & 2 deletions src/libImaging/Draw.c
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ draw_horizontal_lines(
if (e[i].ymin == y && e[i].ymin == e[i].ymax) {
int xmax;
int xmin = e[i].xmin;
if (*x_pos < xmin) {
if (*x_pos != -1 && *x_pos < xmin) {
// Line would be after the current position
continue;
}
Expand Down Expand Up @@ -542,7 +542,7 @@ polygon_generic(Imaging im, int n, Edge *e, int ink, int eofill, hline_handler h
}
qsort(xx, j, sizeof(float), x_cmp);
if (hasAlpha == 1) {
int x_pos = 0;
int x_pos = j == 0 ? -1 : 0;
for (i = 1; i < j; i += 2) {
int x_end = ROUND_DOWN(xx[i]);
if (x_end < x_pos) {
Expand Down

0 comments on commit 38931c1

Please sign in to comment.