Correct PDF palette size when saving by radarhere · Pull Request #7555 · python-pillow/Pillow

@radarhere

Resolves #7554

#7289 set the C palette to be empty by default. The issue has found that this causes P PDFs to appear blank. Testing, I find that the problem is that there can now be fewer than 256 palette entries saved to the PDF file, and that padding the palette to 256 entries fixes it.

homm

homm approved these changes Nov 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a third member in dict_obj["ColorSpace"] list which is 255. Isn't better to adjust it?

@radarhere

@homm

The maximum valid index value in the pallet (the current pallet, as I understand it). This is articulated because it's not a number or items, it's the index of the last element. "The colour table data shall be m•Y(hival +1) bytes long". So if we say that hival is 31, we can write (31+1)•3 = 96 bytes.

@radarhere

@radarhere radarhere changed the title Pad PDF palette to 256 entries when saving Correct PDF palette size when saving

Nov 16, 2023

@radarhere

Ah, I was confused. Ok, I've adjusted that value instead. Thanks.

homm

homm approved these changes Dec 4, 2023