Skip to content

Commit 4dd6d8c

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

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-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: 19 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,25 @@ 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 (strcmp(im->mode, "I;16B") == 0
122+
#ifdef WORDS_BIGENDIAN
123+
|| strcmp(im->mode, "I;16N") == 0
124+
#endif
125+
) {
126+
bigendian = 1;
127+
}
128+
129+
UINT8 *p = im->image8[y0];
130+
while (x0 <= x1) {
131+
p[x0 * 2 + (bigendian ? 1 : 0)] = ink;
132+
p[x0 * 2 + (bigendian ? 0 : 1)] = ink >> 8;
133+
x0++;
134+
}
135+
} else {
136+
memset(im->image8[y0] + x0, (UINT8)ink, (x1 - x0 + 1));
137+
}
125138
}
126139
}
127140
}

0 commit comments

Comments
 (0)