mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-07-04 03:43:13 +03:00
Correct drawing I;16 horizontal lines (#8985)
This commit is contained in:
parent
ff624fe1e6
commit
056dc89a3c
Binary file not shown.
|
@ -783,9 +783,10 @@ def test_rectangle_I16(bbox: Coords) -> None:
|
||||||
draw = ImageDraw.Draw(im)
|
draw = ImageDraw.Draw(im)
|
||||||
|
|
||||||
# Act
|
# Act
|
||||||
draw.rectangle(bbox, outline=0xFFFF)
|
draw.rectangle(bbox, outline=0xCDEF)
|
||||||
|
|
||||||
# Assert
|
# Assert
|
||||||
|
assert im.getpixel((X0, Y0)) == 0xCDEF
|
||||||
assert_image_equal_tofile(im, "Tests/images/imagedraw_rectangle_I.tiff")
|
assert_image_equal_tofile(im, "Tests/images/imagedraw_rectangle_I.tiff")
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -104,8 +104,6 @@ point32rgba(Imaging im, int x, int y, int ink) {
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
hline8(Imaging im, int x0, int y0, int x1, int ink, Imaging mask) {
|
hline8(Imaging im, int x0, int y0, int x1, int ink, Imaging mask) {
|
||||||
int pixelwidth;
|
|
||||||
|
|
||||||
if (y0 >= 0 && y0 < im->ysize) {
|
if (y0 >= 0 && y0 < im->ysize) {
|
||||||
if (x0 < 0) {
|
if (x0 < 0) {
|
||||||
x0 = 0;
|
x0 = 0;
|
||||||
|
@ -118,20 +116,30 @@ hline8(Imaging im, int x0, int y0, int x1, int ink, Imaging mask) {
|
||||||
x1 = im->xsize - 1;
|
x1 = im->xsize - 1;
|
||||||
}
|
}
|
||||||
if (x0 <= x1) {
|
if (x0 <= x1) {
|
||||||
pixelwidth = strncmp(im->mode, "I;16", 4) == 0 ? 2 : 1;
|
int bigendian = -1;
|
||||||
if (mask == NULL) {
|
if (strncmp(im->mode, "I;16", 4) == 0) {
|
||||||
memset(
|
bigendian =
|
||||||
im->image8[y0] + x0 * pixelwidth,
|
(
|
||||||
(UINT8)ink,
|
#ifdef WORDS_BIGENDIAN
|
||||||
(x1 - x0 + 1) * pixelwidth
|
strcmp(im->mode, "I;16") == 0 || strcmp(im->mode, "I;16L") == 0
|
||||||
);
|
#else
|
||||||
|
strcmp(im->mode, "I;16B") == 0
|
||||||
|
#endif
|
||||||
|
)
|
||||||
|
? 1
|
||||||
|
: 0;
|
||||||
|
}
|
||||||
|
if (mask == NULL && bigendian == -1) {
|
||||||
|
memset(im->image8[y0] + x0, (UINT8)ink, (x1 - x0 + 1));
|
||||||
} else {
|
} else {
|
||||||
UINT8 *p = im->image8[y0];
|
UINT8 *p = im->image8[y0];
|
||||||
while (x0 <= x1) {
|
while (x0 <= x1) {
|
||||||
if (mask->image8[y0][x0]) {
|
if (mask == NULL || mask->image8[y0][x0]) {
|
||||||
p[x0 * pixelwidth] = ink;
|
if (bigendian == -1) {
|
||||||
if (pixelwidth == 2) {
|
p[x0] = ink;
|
||||||
p[x0 * pixelwidth + 1] = ink;
|
} else {
|
||||||
|
p[x0 * 2 + (bigendian ? 1 : 0)] = ink;
|
||||||
|
p[x0 * 2 + (bigendian ? 0 : 1)] = ink >> 8;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
x0++;
|
x0++;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user