From 5e2332a200e7636789573e439c53b313e5d2a2ea Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Wed, 5 Jul 2023 08:49:47 +1000 Subject: [PATCH 1/2] Corrected drawing I;16 points --- Tests/images/imagedraw_rectangle_I.png | Bin 181 -> 180 bytes Tests/test_imagedraw.py | 14 ++++++++++++- src/libImaging/Draw.c | 26 +++++++++++++++++-------- 3 files changed, 31 insertions(+), 9 deletions(-) diff --git a/Tests/images/imagedraw_rectangle_I.png b/Tests/images/imagedraw_rectangle_I.png index 4e94f6943dd8eaac1d3be2b930b835358f1caaf9..a75f12c2e98f417e662f2661eab980b45b61cde1 100644 GIT binary patch delta 102 zcmdnWxP@_oidD6zi(^Q|oVT}j@-`TVusS+?xo;%mkkXypn)XS5|Jl7d3_x%o{o2RL zk9X7`yK1#D=Yq82qQh_PhD7E_X4Eu!GAut`79dQRy$UJxSp= 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) @@ -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; } @@ -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 From ba9c830b0356a209f44f747ba6b0090894dc1608 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Sat, 8 Jul 2023 11:30:48 +1000 Subject: [PATCH 2/2] Corrected writing I;16 text --- Tests/test_imagefont.py | 4 +++- src/libImaging/Paste.c | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Tests/test_imagefont.py b/Tests/test_imagefont.py index 02622e72138..343ecda82c6 100644 --- a/Tests/test_imagefont.py +++ b/Tests/test_imagefont.py @@ -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) diff --git a/src/libImaging/Paste.c b/src/libImaging/Paste.c index acf5202e50c..6684b11efe3 100644 --- a/src/libImaging/Paste.c +++ b/src/libImaging/Paste.c @@ -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++; }