Skip to content

Commit d9c16c3

Browse files
committed
Corrected drawing I;16 points
1 parent be828f4 commit d9c16c3

File tree

3 files changed

+30
-8
lines changed

3 files changed

+30
-8
lines changed
5 Bytes
Loading

Tests/test_imagedraw.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,18 @@ def test_point(points):
586586
assert_image_equal_tofile(im, "Tests/images/imagedraw_point.png")
587587

588588

589+
def test_point_I16():
590+
# Arrange
591+
im = Image.new("I;16", (1, 1))
592+
draw = ImageDraw.Draw(im)
593+
594+
# Act
595+
draw.point((0, 0), fill=0x1234)
596+
597+
# Assert
598+
assert im.getpixel((0, 0)) == 0x1234
599+
600+
589601
@pytest.mark.parametrize("points", POINTS)
590602
def test_polygon(points):
591603
# Arrange

src/libImaging/Draw.c

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#define FLOOR(v) ((v) >= 0.0 ? (int)(v) : (int)floor(v))
4242

4343
#define INK8(ink) (*(UINT8 *)ink)
44+
#define INK16(ink) (*(UINT16 *)ink)
4445

4546
/*
4647
* Rounds around zero (up=away from zero, down=towards zero)
@@ -68,8 +69,13 @@ static inline void
6869
point8(Imaging im, int x, int y, int ink) {
6970
if (x >= 0 && x < im->xsize && y >= 0 && y < im->ysize) {
7071
if (strncmp(im->mode, "I;16", 4) == 0) {
71-
im->image8[y][x * 2] = (UINT8)ink;
72+
#ifdef WORDS_BIGENDIAN
73+
im->image8[y][x * 2] = (UINT8)(ink >> 8);
7274
im->image8[y][x * 2 + 1] = (UINT8)ink;
75+
#else
76+
im->image8[y][x * 2] = (UINT8)ink;
77+
im->image8[y][x * 2 + 1] = (UINT8)(ink >> 8);
78+
#endif
7379
} else {
7480
im->image8[y][x] = (UINT8)ink;
7581
}
@@ -631,13 +637,17 @@ DRAW draw32rgba = {point32rgba, hline32rgba, line32rgba, polygon32rgba};
631637
/* Interface */
632638
/* -------------------------------------------------------------------- */
633639

634-
#define DRAWINIT() \
635-
if (im->image8) { \
636-
draw = &draw8; \
637-
ink = INK8(ink_); \
638-
} else { \
639-
draw = (op) ? &draw32rgba : &draw32; \
640-
memcpy(&ink, ink_, sizeof(ink)); \
640+
#define DRAWINIT() \
641+
if (im->image8) { \
642+
draw = &draw8; \
643+
if (strncmp(im->mode, "I;16", 4) == 0) { \
644+
ink = INK16(ink_); \
645+
} else { \
646+
ink = INK8(ink_); \
647+
} \
648+
} else { \
649+
draw = (op) ? &draw32rgba : &draw32; \
650+
memcpy(&ink, ink_, sizeof(ink)); \
641651
}
642652

643653
int

0 commit comments

Comments
 (0)