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

Do not mark L mode JPEG as 1 bit in PDF #6151

Merged
merged 1 commit into from Mar 27, 2022
Merged

Conversation

radarhere
Copy link
Member

Resolves #6149

When saving a PDF, the bits setting is different for 1 and L mode images.

bits = 8
params = None
decode = None
if im.mode == "1":
filter = "DCTDecode"
colorspace = PdfParser.PdfName("DeviceGray")
procset = "ImageB" # grayscale
bits = 1
elif im.mode == "L":
filter = "DCTDecode"
# params = f"<< /Predictor 15 /Columns {width-2} >>"
colorspace = PdfParser.PdfName("DeviceGray")
procset = "ImageB" # grayscale

Except that both images are encoded as JPEGs,

elif filter == "DCTDecode":
Image.SAVE["JPEG"](im, op, filename)

which treats both 1 and L as L.

# stuff to save JPEG files
RAWMODE = {
"1": "L",
"L": "L",

So instructing the PDF that BitsPerComponent is different for these two images seems wrong. As a result, 1-bit PDFs from the current version of the code are read successfully by Chrome, but not by Firefox.

This PR fixes that by setting bits to 8 for 1-bit images as well.

@hugovk hugovk merged commit 96a9776 into python-pillow:main Mar 27, 2022
@radarhere radarhere deleted the pdf branch March 27, 2022 11:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Black-and-white PDF export regression in Pillow 8.3.x
2 participants