From 1e3a1116eeb6410dc513637e55a8dfcf2d9252f3 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Fri, 6 May 2022 21:28:25 +1000 Subject: [PATCH] Always draw first segment in each translucent polygon line --- .../imagedraw_polygon_1px_high_translucent.png | Bin 0 -> 76 bytes Tests/test_imagedraw.py | 14 ++++++++++++++ src/libImaging/Draw.c | 4 ++-- 3 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 Tests/images/imagedraw_polygon_1px_high_translucent.png diff --git a/Tests/images/imagedraw_polygon_1px_high_translucent.png b/Tests/images/imagedraw_polygon_1px_high_translucent.png new file mode 100644 index 0000000000000000000000000000000000000000..8bbf9397c72a4352cf74c16b0fdae378d56065f3 GIT binary patch literal 76 zcmeAS@N?(olHy`uVBq!ia0vp^EI`c6!2~3&r&&$}Qo^1tjv*Cuk`o-5dU$wvzVh5) ZVBpqfXcTz0dNNR&!PC{xWt~$(69E385JCU| literal 0 HcmV?d00001 diff --git a/Tests/test_imagedraw.py b/Tests/test_imagedraw.py index 6755d94b895..7f4a18c47bf 100644 --- a/Tests/test_imagedraw.py +++ b/Tests/test_imagedraw.py @@ -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)) diff --git a/src/libImaging/Draw.c b/src/libImaging/Draw.c index 86cd6c3a058..543651f7fa6 100644 --- a/src/libImaging/Draw.c +++ b/src/libImaging/Draw.c @@ -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; } @@ -540,7 +540,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) {