Visitar URL original
Correct pasting colour onto I;16 image · python-pillow/Pillow@28b9b96 · GitHub
Skip to content

Commit 28b9b96

Browse files
committed
Correct pasting colour onto I;16 image
1 parent 867301a commit 28b9b96

2 files changed

Lines changed: 20 additions & 16 deletions

File tree

‎Tests/test_image_paste.py‎

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -283,18 +283,14 @@ def test_image_mask_RGBa(self, mode: str) -> None:
283283
],
284284
)
285285

286-
@pytest.mark.parametrize("mode", ["RGBA", "RGB", "L"])
286+
@pytest.mark.parametrize("mode", ["RGBA", "RGB", "L", "I;16"])
287287
def test_color_solid(self, mode: str) -> None:
288288
im = Image.new(mode, (200, 200), "black")
289289

290290
rect = (12, 23, 128 + 12, 128 + 23)
291291
im.paste("white", rect)
292292

293-
hist = im.crop(rect).histogram()
294-
while hist:
295-
head, hist = hist[:256], hist[256:]
296-
assert head[255] == 128 * 128
297-
assert sum(head[:255]) == 0
293+
assert_image_equal(im.crop(rect), Image.new(mode, (128, 128), "white"))
298294

299295
@pytest.mark.parametrize("mode", ["RGBA", "RGB", "L"])
300296
def test_color_mask_1(self, mode: str) -> None:
@@ -326,9 +322,7 @@ def test_color_mask_1_I16(self) -> None:
326322
im,
327323
(color,),
328324
self.mask_1,
329-
[
330-
50, 50, 10, 50, 50, 10, 10, 10, 50
331-
],
325+
[50, 50, 10, 50, 50, 10, 10, 10, 50],
332326
)
333327

334328
@pytest.mark.parametrize("mode", ["RGBA", "RGB", "L"])

‎src/libImaging/Paste.c‎

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -372,19 +372,29 @@ fill(
372372
/* fill opaque region */
373373

374374
int x, y;
375-
UINT8 ink8 = 0;
376375
INT32 ink32 = 0L;
377376

378377
memcpy(&ink32, ink, pixelsize);
379-
memcpy(&ink8, ink, sizeof(ink8));
380378

381379
if (imOut->image8 || ink32 == 0L) {
382-
dx *= pixelsize;
383-
xsize *= pixelsize;
384-
for (y = 0; y < ysize; y++) {
385-
memset(imOut->image[y + dy] + dx, ink8, xsize);
380+
int i16 = imOut->type == IMAGING_TYPE_I16;
381+
if (i16 && ink32 != 0L) {
382+
for (y = 0; y < ysize; y++) {
383+
UINT16 *out = (UINT16 *)imOut->image[y + dy] + dx;
384+
for (x = 0; x < xsize; x++) {
385+
*out++ = ink32;
386+
}
387+
}
388+
} else {
389+
UINT8 ink8 = 0;
390+
memcpy(&ink8, ink, sizeof(ink8));
391+
392+
dx *= pixelsize;
393+
xsize *= pixelsize;
394+
for (y = 0; y < ysize; y++) {
395+
memset(imOut->image[y + dy] + dx, ink8, xsize);
396+
}
386397
}
387-
388398
} else {
389399
#if defined _WIN32 && !defined _WIN64
390400
int i;

0 commit comments

Comments
 (0)