From a39cb04f3e1e464c4cba1a34f57ebe35188bcdff Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Fri, 9 Jul 2021 21:23:43 +1000 Subject: [PATCH] Consider I;16 pixel size when drawing text --- Tests/test_imagefont.py | 11 +++++++++++ src/libImaging/Paste.c | 7 +++++++ 2 files changed, 18 insertions(+) diff --git a/Tests/test_imagefont.py b/Tests/test_imagefont.py index 892bd0ed1f5..002641faa85 100644 --- a/Tests/test_imagefont.py +++ b/Tests/test_imagefont.py @@ -134,6 +134,17 @@ def test_transparent_background(self): target = "Tests/images/transparent_background_text_L.png" assert_image_similar_tofile(im.convert("L"), target, 0.01) + def test_I16(self): + im = Image.new(mode="I;16", size=(300, 100)) + draw = ImageDraw.Draw(im) + ttf = self.get_font() + + txt = "Hello World!" + draw.text((10, 10), txt, font=ttf) + + target = "Tests/images/transparent_background_text_L.png" + assert_image_similar_tofile(im.convert("L"), target, 0.01) + def test_textsize_equal(self): im = Image.new(mode="RGB", size=(300, 100)) draw = ImageDraw.Draw(im) diff --git a/src/libImaging/Paste.c b/src/libImaging/Paste.c index a1bf18a9291..be26cd260b9 100644 --- a/src/libImaging/Paste.c +++ b/src/libImaging/Paste.c @@ -417,9 +417,16 @@ fill_mask_L( if (imOut->image8) { for (y = 0; y < ysize; y++) { UINT8 *out = imOut->image8[y + dy] + dx; + if (strncmp(imOut->mode, "I;16", 4) == 0) { + out += dx; + } UINT8 *mask = imMask->image8[y + sy] + sx; for (x = 0; x < xsize; x++) { *out = BLEND(*mask, *out, ink[0], tmp1); + if (strncmp(imOut->mode, "I;16", 4) == 0) { + out++; + *out = BLEND(*mask, *out, ink[0], tmp1); + } out++, mask++; } }