You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The saved image should be viewable by Windows' default image viewer.
What actually happened?
The saved image was corrupt and could not be displayed.
Reason: The offset calculation for the bfSize (file offset 0x02) and bfOffBits (file offset 0x0A) assumes that the palette is 256 colours large (0x400 bytes). However there are only 0x200 bytes written for the palette. (4 bytes * 128 colours)
The fields biClrUsed (file offset 0x2E) and biClrImportant (file offset 0x32) are also incorrectly set to 256 instead of 128.
The text was updated successfully, but these errors were encountered:
radarhere
changed the title
Invalid 8-bit BMP files written when not all palette colours are used.
Invalid 8-bit BMP files written when not all palette colours are used
Sep 12, 2022
What did you do?
I loaded an image (BMP or PNG) in 8-bit format. (i.e. with a palette of up to 256 colours)
The image did use a palette with less than 256 colours.
Then I edited the image and saved it again, as 8-bit BMP.
EDIT: This may be a similar problem as #6500.
What did you expect to happen?
The saved image should be viewable by Windows' default image viewer.
What actually happened?
The saved image was corrupt and could not be displayed.
Reason: The offset calculation for the
bfSize
(file offset 0x02) andbfOffBits
(file offset 0x0A) assumes that the palette is 256 colours large (0x400 bytes). However there are only 0x200 bytes written for the palette. (4 bytes * 128 colours)The fields
biClrUsed
(file offset 0x2E) andbiClrImportant
(file offset 0x32) are also incorrectly set to 256 instead of 128.What are your OS, Python and Pillow versions?
I attached an archive with two tests: bmp-tests.zip
The text was updated successfully, but these errors were encountered: