Skip to content

Commit a8569da

Browse files
committed
Corrected drawing I;16 horizontal lines
1 parent 5a04b95 commit a8569da

File tree

3 files changed

+23
-7
lines changed

3 files changed

+23
-7
lines changed
0 Bytes
Binary file not shown.

Tests/test_imagedraw.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -783,9 +783,10 @@ def test_rectangle_I16(bbox: Coords) -> None:
783783
draw = ImageDraw.Draw(im)
784784

785785
# Act
786-
draw.rectangle(bbox, outline=0xFFFF)
786+
draw.rectangle(bbox, outline=0xCDEF)
787787

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

791792

src/libImaging/Draw.c

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,6 @@ point32rgba(Imaging im, int x, int y, int ink) {
104104

105105
static inline void
106106
hline8(Imaging im, int x0, int y0, int x1, int ink) {
107-
int pixelwidth;
108-
109107
if (y0 >= 0 && y0 < im->ysize) {
110108
if (x0 < 0) {
111109
x0 = 0;
@@ -118,10 +116,27 @@ hline8(Imaging im, int x0, int y0, int x1, int ink) {
118116
x1 = im->xsize - 1;
119117
}
120118
if (x0 <= x1) {
121-
pixelwidth = strncmp(im->mode, "I;16", 4) == 0 ? 2 : 1;
122-
memset(
123-
im->image8[y0] + x0 * pixelwidth, (UINT8)ink, (x1 - x0 + 1) * pixelwidth
124-
);
119+
if (strncmp(im->mode, "I;16", 4) == 0) {
120+
int bigendian = 0;
121+
if (
122+
#ifdef WORDS_BIGENDIAN
123+
strcmp(im->mode, "I;16") == 0 || strcmp(im->mode, "I;16L") == 0
124+
#else
125+
strcmp(im->mode, "I;16B") == 0
126+
#endif
127+
) {
128+
bigendian = 1;
129+
}
130+
131+
UINT8 *p = im->image8[y0];
132+
while (x0 <= x1) {
133+
p[x0 * 2 + (bigendian ? 1 : 0)] = ink;
134+
p[x0 * 2 + (bigendian ? 0 : 1)] = ink >> 8;
135+
x0++;
136+
}
137+
} else {
138+
memset(im->image8[y0] + x0, (UINT8)ink, (x1 - x0 + 1));
139+
}
125140
}
126141
}
127142
}

0 commit comments

Comments
 (0)