From 8331e52ce37d80161f4fd6dce30c4dd2a17d4427 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Tue, 11 Jun 2019 21:01:19 +1000 Subject: [PATCH] Consider I;16 pixel size when drawing --- Tests/images/imagedraw_rectangle_I.png | Bin 0 -> 181 bytes Tests/test_imagedraw.py | 12 ++++++++++++ src/libImaging/Draw.c | 16 ++++++++++++---- 3 files changed, 24 insertions(+), 4 deletions(-) create mode 100644 Tests/images/imagedraw_rectangle_I.png diff --git a/Tests/images/imagedraw_rectangle_I.png b/Tests/images/imagedraw_rectangle_I.png new file mode 100644 index 0000000000000000000000000000000000000000..4e94f6943dd8eaac1d3be2b930b835358f1caaf9 GIT binary patch literal 181 zcmeAS@N?(olHy`uVBq!ia0vp^DIhEWBp6sF#ZCjM8c!F;kcv5PZ|&r5aNuEZbSQD( z`^BBnrM)67Lv8z;v$nn<#Rt-#eVmxP`+v{o+WMNK(u$9*r>UR&(KJCy(bOrc= 0 && x < im->xsize && y >= 0 && y < im->ysize) - im->image8[y][x] = (UINT8) ink; + if (strncmp(im->mode, "I;16", 4) == 0) { + im->image8[y][x*2] = (UINT8) ink; + im->image8[y][x*2+1] = (UINT8) ink; + } else { + im->image8[y][x] = (UINT8) ink; + } } static inline void @@ -95,7 +100,7 @@ point32rgba(Imaging im, int x, int y, int ink) static inline void hline8(Imaging im, int x0, int y0, int x1, int ink) { - int tmp; + int tmp, pixelwidth; if (y0 >= 0 && y0 < im->ysize) { if (x0 > x1) @@ -108,8 +113,11 @@ hline8(Imaging im, int x0, int y0, int x1, int ink) return; else if (x1 >= im->xsize) x1 = im->xsize-1; - if (x0 <= x1) - memset(im->image8[y0] + x0, (UINT8) ink, x1 - x0 + 1); + if (x0 <= x1) { + pixelwidth = strncmp(im->mode, "I;16", 4) == 0 ? 2 : 1; + memset(im->image8[y0] + x0 * pixelwidth, (UINT8) ink, + (x1 - x0 + 1) * pixelwidth); + } } }