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.tiff
Binary file not shown.
3 changes: 2 additions & 1 deletion Tests/test_imagedraw.py
Original file line number Diff line number Diff line change
Expand Up @@ -783,9 +783,10 @@ def test_rectangle_I16(bbox: Coords) -> None:
draw = ImageDraw.Draw(im)

# Act
draw.rectangle(bbox, outline=0xFFFF)
draw.rectangle(bbox, outline=0xCDEF)

# Assert
assert im.getpixel((X0, Y0)) == 0xCDEF
assert_image_equal_tofile(im, "Tests/images/imagedraw_rectangle_I.tiff")


Expand Down
34 changes: 21 additions & 13 deletions src/libImaging/Draw.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,6 @@

static inline void
hline8(Imaging im, int x0, int y0, int x1, int ink, Imaging mask) {
int pixelwidth;

if (y0 >= 0 && y0 < im->ysize) {
if (x0 < 0) {
x0 = 0;
Expand All @@ -118,20 +116,30 @@
x1 = im->xsize - 1;
}
if (x0 <= x1) {
pixelwidth = strncmp(im->mode, "I;16", 4) == 0 ? 2 : 1;
if (mask == NULL) {
memset(
im->image8[y0] + x0 * pixelwidth,
(UINT8)ink,
(x1 - x0 + 1) * pixelwidth
);
int bigendian = -1;
if (strncmp(im->mode, "I;16", 4) == 0) {
bigendian =
(
#ifdef WORDS_BIGENDIAN
strcmp(im->mode, "I;16") == 0 || strcmp(im->mode, "I;16L") == 0
#else
strcmp(im->mode, "I;16B") == 0
#endif
)
? 1
: 0;
}
if (mask == NULL && bigendian == -1) {
memset(im->image8[y0] + x0, (UINT8)ink, (x1 - x0 + 1));
} else {
UINT8 *p = im->image8[y0];
while (x0 <= x1) {
if (mask->image8[y0][x0]) {
p[x0 * pixelwidth] = ink;
if (pixelwidth == 2) {
p[x0 * pixelwidth + 1] = ink;
if (mask == NULL || mask->image8[y0][x0]) {
if (bigendian == -1) {
p[x0] = ink;
} else {

Check warning on line 140 in src/libImaging/Draw.c

View check run for this annotation

Codecov / codecov/patch

src/libImaging/Draw.c#L139-L140

Added lines #L139 - L140 were not covered by tests
p[x0 * 2 + (bigendian ? 1 : 0)] = ink;
p[x0 * 2 + (bigendian ? 0 : 1)] = ink >> 8;
}
}
x0++;
Expand Down
Loading