Skip to content

Commit a596a40

Browse files
authored
Merge pull request #8112 from radarhere/i16_mask
2 parents 48a921b + 08b5a2e commit a596a40

File tree

3 files changed

+35
-4
lines changed

3 files changed

+35
-4
lines changed
19.7 KB
Binary file not shown.

Tests/test_imagedraw.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,19 @@ def test_polygon(points: Coords) -> None:
634634
assert_image_equal_tofile(im, "Tests/images/imagedraw_polygon.png")
635635

636636

637+
@pytest.mark.parametrize("points", POINTS)
638+
def test_polygon_width_I16(points: Coords) -> None:
639+
# Arrange
640+
im = Image.new("I;16", (W, H))
641+
draw = ImageDraw.Draw(im)
642+
643+
# Act
644+
draw.polygon(points, outline=0xFFFF, width=2)
645+
646+
# Assert
647+
assert_image_equal_tofile(im, "Tests/images/imagedraw_polygon_width_I.tiff")
648+
649+
637650
@pytest.mark.parametrize("mode", ("RGB", "L"))
638651
@pytest.mark.parametrize("kite_points", KITE_POINTS)
639652
def test_polygon_kite(

src/libImaging/Paste.c

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,32 @@ paste_mask_1(
6565
int x, y;
6666

6767
if (imOut->image8) {
68+
int in_i16 = strncmp(imIn->mode, "I;16", 4) == 0;
69+
int out_i16 = strncmp(imOut->mode, "I;16", 4) == 0;
6870
for (y = 0; y < ysize; y++) {
6971
UINT8 *out = imOut->image8[y + dy] + dx;
72+
if (out_i16) {
73+
out += dx;
74+
}
7075
UINT8 *in = imIn->image8[y + sy] + sx;
76+
if (in_i16) {
77+
in += sx;
78+
}
7179
UINT8 *mask = imMask->image8[y + sy] + sx;
7280
for (x = 0; x < xsize; x++) {
73-
if (*mask++) {
81+
if (*mask) {
7482
*out = *in;
7583
}
76-
out++, in++;
84+
if (in_i16) {
85+
in++;
86+
}
87+
if (out_i16) {
88+
out++;
89+
if (*mask) {
90+
*out = *in;
91+
}
92+
}
93+
out++, in++, mask++;
7794
}
7895
}
7996

@@ -415,15 +432,16 @@ fill_mask_L(
415432
unsigned int tmp1;
416433

417434
if (imOut->image8) {
435+
int i16 = strncmp(imOut->mode, "I;16", 4) == 0;
418436
for (y = 0; y < ysize; y++) {
419437
UINT8 *out = imOut->image8[y + dy] + dx;
420-
if (strncmp(imOut->mode, "I;16", 4) == 0) {
438+
if (i16) {
421439
out += dx;
422440
}
423441
UINT8 *mask = imMask->image8[y + sy] + sx;
424442
for (x = 0; x < xsize; x++) {
425443
*out = BLEND(*mask, *out, ink[0], tmp1);
426-
if (strncmp(imOut->mode, "I;16", 4) == 0) {
444+
if (i16) {
427445
out++;
428446
*out = BLEND(*mask, *out, ink[1], tmp1);
429447
}

0 commit comments

Comments
 (0)