Pillow incorrectly enforces a minimum of 2 palette entries.
from PIL import Image
img = Image.new(size = (1, 1), mode = 'P')
img.putpalette((1, 1, 1))
img.save('file.png')
$ pngcheck -v file.png
...
1 x 1 image, 1-bit palette, non-interlaced
chunk PLTE at offset 0x00025, length 6: 2 palette entries
...
And pads the palette to bit ** 2 entries.
from PIL import Image
img = Image.new(size = (3, 3), mode = 'P')
img.putpalette((1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 4, 5)) # 5
img.save('file.png')
$ pngcheck -v file.png
...
3 x 3 image, 4-bit palette, non-interlaced
chunk PLTE at offset 0x00025, length 48: 16 palette entries
...
It's neither required nor recommended.
It is permissible to have fewer entries than the bit depth would allow.
Pillow incorrectly enforces a minimum of
2palette entries.$ pngcheck -v file.png ... 1 x 1 image, 1-bit palette, non-interlaced chunk PLTE at offset 0x00025, length 6: 2 palette entries ...And pads the palette to
bit ** 2entries.$ pngcheck -v file.png ... 3 x 3 image, 4-bit palette, non-interlaced chunk PLTE at offset 0x00025, length 48: 16 palette entries ...It's neither required nor recommended.