Skip to content

Deprecate P;2L and P;4L in frombytes() - #9723

Open
radarhere wants to merge 2 commits into
python-pillow:mainfrom
radarhere:frombytes_pxl
Open

Deprecate P;2L and P;4L in frombytes()#9723
radarhere wants to merge 2 commits into
python-pillow:mainfrom
radarhere:frombytes_pxl

Conversation

@radarhere

@radarhere radarhere commented Jun 27, 2026

Copy link
Copy Markdown
Member

Sequel to #9725

That PR raised a ValueError if P;2L or P;4L data is truncated in frombytes(). This PR deprecates their use as independent unpackers altogether. They can still be used when decoding PCX images.

I've moved the unpackers from Unpack.c to PcxDecode.c. Once the deprecation period is up, the unpackers and RAWMODES entries can be removed.

@radarhere radarhere added the Deprecation Feature that will be removed in the future label Jun 27, 2026
@radarhere
radarhere force-pushed the frombytes_pxl branch 3 times, most recently from 04b841f to 0f28129 Compare July 3, 2026 14:05
@akx

akx commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Hmm, these could still be useful decoders for people using Pillow to eg. carve images out of, say, game binaries?

@radarhere

Copy link
Copy Markdown
Member Author

Could you expand further? What makes you think they are used for anything other than PCX images?

@akx

akx commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Sure. I've been involved in projects to port retro games, where Pillow has been useful to convert custom bespoke file formats to modern ones. That particular example isn't P;2L or P;4L, sure, just a palettized image with RLE encoding, but in general Pillow's decoders being available to "userland" have been useful for this sort of thing.

I don't particularly see a reason why this should be deprecated in frombytes - what's the rationale? It isn't clear from the PR description.

@radarhere

Copy link
Copy Markdown
Member Author

Because #9725 added rather specific code for the handling of these two rawmodes in a non-PCX context

Pillow/src/PIL/Image.py

Lines 953 to 957 in cfc8a1e

if decoder_args and decoder_args[0] in {"P;2L", "P;4L"}:
multiple = 4 if decoder_args[0] == "P;2L" else 8
if len(data) % multiple:
msg = "not enough image data"
raise ValueError(msg)

and if the rawmodes aren't necessary for any other encoder, I'd like to get rid of it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Deprecation Feature that will be removed in the future

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants