Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified Tests/images/imagedraw_rectangle_I.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 13 additions & 1 deletion Tests/test_imagedraw.py
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,18 @@ def test_point(points):
assert_image_equal_tofile(im, "Tests/images/imagedraw_point.png")


def test_point_I16():
# Arrange
im = Image.new("I;16", (1, 1))
draw = ImageDraw.Draw(im)

# Act
draw.point((0, 0), fill=0x1234)

# Assert
assert im.getpixel((0, 0)) == 0x1234


@pytest.mark.parametrize("points", POINTS)
def test_polygon(points):
# Arrange
Expand Down Expand Up @@ -732,7 +744,7 @@ def test_rectangle_I16(bbox):
draw = ImageDraw.Draw(im)

# Act
draw.rectangle(bbox, fill="black", outline="green")
draw.rectangle(bbox, outline=0xFFFF)

# Assert
assert_image_equal_tofile(im.convert("I"), "Tests/images/imagedraw_rectangle_I.png")
Expand Down
4 changes: 3 additions & 1 deletion Tests/test_imagefont.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,9 @@ def test_I16(font):
draw = ImageDraw.Draw(im)

txt = "Hello World!"
draw.text((10, 10), txt, font=font)
draw.text((10, 10), txt, fill=0xFFFE, font=font)

assert im.getpixel((12, 14)) == 0xFFFE

target = "Tests/images/transparent_background_text_L.png"
assert_image_similar_tofile(im.convert("L"), target, 0.01)
Expand Down
26 changes: 18 additions & 8 deletions src/libImaging/Draw.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#define FLOOR(v) ((v) >= 0.0 ? (int)(v) : (int)floor(v))

#define INK8(ink) (*(UINT8 *)ink)
#define INK16(ink) (*(UINT16 *)ink)

/*
* Rounds around zero (up=away from zero, down=towards zero)
Expand Down Expand Up @@ -68,8 +69,13 @@ static inline void
point8(Imaging im, int x, int y, int ink) {
if (x >= 0 && x < im->xsize && y >= 0 && y < im->ysize) {
if (strncmp(im->mode, "I;16", 4) == 0) {
im->image8[y][x * 2] = (UINT8)ink;
#ifdef WORDS_BIGENDIAN
im->image8[y][x * 2] = (UINT8)(ink >> 8);
im->image8[y][x * 2 + 1] = (UINT8)ink;
#else
im->image8[y][x * 2] = (UINT8)ink;
im->image8[y][x * 2 + 1] = (UINT8)(ink >> 8);
#endif
} else {
im->image8[y][x] = (UINT8)ink;
}
Expand Down Expand Up @@ -631,13 +637,17 @@ DRAW draw32rgba = {point32rgba, hline32rgba, line32rgba, polygon32rgba};
/* Interface */
/* -------------------------------------------------------------------- */

#define DRAWINIT() \
if (im->image8) { \
draw = &draw8; \
ink = INK8(ink_); \
} else { \
draw = (op) ? &draw32rgba : &draw32; \
memcpy(&ink, ink_, sizeof(ink)); \
#define DRAWINIT() \
if (im->image8) { \
draw = &draw8; \
if (strncmp(im->mode, "I;16", 4) == 0) { \
ink = INK16(ink_); \
} else { \
ink = INK8(ink_); \
} \
} else { \
draw = (op) ? &draw32rgba : &draw32; \
memcpy(&ink, ink_, sizeof(ink)); \
}

int
Expand Down
2 changes: 1 addition & 1 deletion src/libImaging/Paste.c
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ fill_mask_L(
*out = BLEND(*mask, *out, ink[0], tmp1);
if (strncmp(imOut->mode, "I;16", 4) == 0) {
out++;
*out = BLEND(*mask, *out, ink[0], tmp1);
*out = BLEND(*mask, *out, ink[1], tmp1);
}
out++, mask++;
}
Expand Down