mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-07-04 11:53:32 +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)
|
||||
|
||||
# Act
|
||||
draw.rectangle(bbox, outline=0xFFFF)
|
||||
draw.rectangle(bbox, outline=0xCDEF)
|
||||
|
||||
# Assert
|
||||
assert im.getpixel((X0, Y0)) == 0xCDEF
|
||||
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
|
||||
hline8(Imaging im, int x0, int y0, int x1, int ink, Imaging mask) {
|
||||
int pixelwidth;
|
||||
|
||||
if (y0 >= 0 && y0 < im->ysize) {
|
||||
if (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;
|
||||
}
|
||||
if (x0 <= x1) {
|
||||
pixelwidth = strncmp(im->mode, "I;16", 4) == 0 ? 2 : 1;
|
||||
if (mask == NULL) {
|
||||
memset(
|
||||
im->image8[y0] + x0 * pixelwidth,
|
||||
(UINT8)ink,
|
||||
(x1 - x0 + 1) * pixelwidth
|
||||
);
|
||||
int bigendian = -1;
|
||||
if (strncmp(im->mode, "I;16", 4) == 0) {
|
||||
bigendian =
|
||||
(
|
||||
#ifdef WORDS_BIGENDIAN
|
||||
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 {
|
||||
UINT8 *p = im->image8[y0];
|
||||
while (x0 <= x1) {
|
||||
if (mask->image8[y0][x0]) {
|
||||
p[x0 * pixelwidth] = ink;
|
||||
if (pixelwidth == 2) {
|
||||
p[x0 * pixelwidth + 1] = ink;
|
||||
if (mask == NULL || mask->image8[y0][x0]) {
|
||||
if (bigendian == -1) {
|
||||
p[x0] = ink;
|
||||
} else {
|
||||
p[x0 * 2 + (bigendian ? 1 : 0)] = ink;
|
||||
p[x0 * 2 + (bigendian ? 0 : 1)] = ink >> 8;
|
||||
}
|
||||
}
|
||||
x0++;
|
||||
|
|
Loading…
Reference in New Issue
Block a user