-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Closed
Labels
BugAny unexpected behavior, until confirmed feature.Any unexpected behavior, until confirmed feature.
Description
What did you do?
ImageDraw on an image with mode I;16 fails to work correctly. When given a fill color (in the range 0...0xFFFF), it draws the shapes correctly, but uses a color with the lower 8-bits repeated twice.
What did you expect to happen?
The full 16-bit fill color provided should be used to draw on the image.
What actually happened?
Only the lower 8-bits (duplicated into the higher and lower byte) were used.
What are your OS, Python and Pillow versions?
- OS: macOS 12 (also confirmed on Ubuntu 20.04)
- Python: 3.10
- Pillow: 9.5.0
from PIL import Image, ImageDraw
image = Image.new("I;16", (10, 10))
draw = ImageDraw.Draw(image)
c = 0x1234
draw.point([(0, 0)], fill=c)
print(hex(image.load()[0, 0]))
# --> 0x3434
# (but we expect it to be 0x1234)
c = 0x4567
draw.line([(0, 0), (5, 0)], fill=c)
print(hex(image.load()[0, 0]))
# --> 0x6767
# (but we expect it to be 0x4567)
c = 0x89AB
draw.rectangle([(0, 0), (5, 5)], fill=c)
print(hex(image.load()[0, 0]))
# --> 0xABAB
# (but we expect it to be 0x89AB)As you can see, for each color, the actual color applied to the image is based on the lower 8-bits, duplicated twice.
I suspect this has something to do with this:
Lines 71 to 72 in 7c945f5
| im->image8[y][x * 2] = (UINT8)ink; | |
| im->image8[y][x * 2 + 1] = (UINT8)ink; |
(Which was originally added in #3899)
Note that that issue is also referenced by #5598, so I suspect there might be a similar issue with drawing text.
Metadata
Metadata
Assignees
Labels
BugAny unexpected behavior, until confirmed feature.Any unexpected behavior, until confirmed feature.