Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct PDF palette size when saving #7555

Merged
merged 1 commit into from Dec 4, 2023

Conversation

radarhere
Copy link
Member

@radarhere radarhere commented Nov 15, 2023

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.

Copy link
Member

@homm homm left a comment

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?

src/PIL/PdfImagePlugin.py Outdated Show resolved Hide resolved
@radarhere
Copy link
Member Author

radarhere commented Nov 16, 2023

Looking at page 164 of https://opensource.adobe.com/dc-acrobat-sdk-docs/pdfstandards/PDF32000_2008.pdf, '255' is the 'hival', the 'maximum valid index value'. It is not simply the number of palette entries, so we couldn't correctly adjust it to lower the number of required palette entries without also needing to remap the palette.

@homm
Copy link
Member

homm commented Nov 16, 2023

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 changed the title Pad PDF palette to 256 entries when saving Correct PDF palette size when saving Nov 16, 2023
@radarhere
Copy link
Member Author

radarhere commented Nov 16, 2023

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

@radarhere radarhere requested a review from homm November 30, 2023 10:43
@radarhere radarhere merged commit b431e2c into python-pillow:main Dec 4, 2023
56 checks passed
@radarhere radarhere deleted the pdf_palette branch December 4, 2023 10:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[10.1.0 regression] Palette images save as blank PDFs
2 participants