Skip to content

Commit

Permalink
Merge pull request #5598 from radarhere/i16
Browse files Browse the repository at this point in the history
Consider I;16 pixel size when drawing text
  • Loading branch information
hugovk committed Aug 6, 2021
2 parents 3307bf6 + a39cb04 commit 025f207
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
11 changes: 11 additions & 0 deletions Tests/test_imagefont.py
Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions src/libImaging/Paste.c
Expand Up @@ -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++;
}
}
Expand Down

0 comments on commit 025f207

Please sign in to comment.