Skip to content

Commit c824ab0

Browse files
committed
Fixed drawing translucent 1px high polygons
1 parent 3fa89f0 commit c824ab0

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed
76 Bytes
Loading

Tests/test_imagedraw.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,20 @@ def test_polygon_1px_high():
655655
assert_image_equal_tofile(im, expected)
656656

657657

658+
def test_polygon_1px_high_translucent():
659+
# Test drawing a translucent 1px high polygon
660+
# Arrange
661+
im = Image.new("RGB", (4, 3))
662+
draw = ImageDraw.Draw(im, "RGBA")
663+
expected = "Tests/images/imagedraw_polygon_1px_high_translucent.png"
664+
665+
# Act
666+
draw.polygon([(1, 1), (1, 1), (3, 1), (3, 1)], (255, 0, 0, 127))
667+
668+
# Assert
669+
assert_image_equal_tofile(im, expected)
670+
671+
658672
def test_polygon_translucent():
659673
# Arrange
660674
im = Image.new("RGB", (W, H))

src/libImaging/Draw.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ draw_horizontal_lines(
419419
if (e[i].ymin == y && e[i].ymin == e[i].ymax) {
420420
int xmax;
421421
int xmin = e[i].xmin;
422-
if (*x_pos < xmin) {
422+
if (*x_pos != -1 && *x_pos < xmin) {
423423
// Line would be after the current position
424424
continue;
425425
}
@@ -540,7 +540,7 @@ polygon_generic(Imaging im, int n, Edge *e, int ink, int eofill, hline_handler h
540540
}
541541
qsort(xx, j, sizeof(float), x_cmp);
542542
if (hasAlpha == 1) {
543-
int x_pos = 0;
543+
int x_pos = j == 0 ? -1 : 0;
544544
for (i = 1; i < j; i += 2) {
545545
int x_end = ROUND_DOWN(xx[i]);
546546
if (x_end < x_pos) {

0 commit comments

Comments
 (0)