Reduce number of bytes read for PCX header by radarhere · Pull Request #9004 · python-pillow/Pillow
Navigation Menu
{{ message }}
python-pillow / Pillow Public
- Notifications You must be signed in to change notification settings
- Fork 2.4k
Merged
Reduce number of bytes read for PCX header#9004
hugovk merged 2 commits intopython-pillow:mainfrom
Reduce number of bytes read for PCX header#9004
hugovk merged 2 commits intopython-pillow:mainfrom
Conversation
Copy link Copy Markdown
Member
radarhere
commented
Jun 9, 2025
radarhere
commented
-
PcxImagePlugin initially reads 128 bytes
Pillow/src/PIL/PcxImagePlugin.py
Line 57 in 8e5a15b
s = self.fp.read(128)
But the header only uses up to 68 bytes.
Pillow/src/PIL/PcxImagePlugin.py
Line 73 in 8e5a15b
provided_stride = i16(s, 66)
So the number of bytes can be reduced. -
After seeking to the end of the file for one type of header, PcxImagePlugin seeks back to the start.
Pillow/src/PIL/PcxImagePlugin.py
Lines 96 to 105 in 8e5a15b
s = self.fp.read(769) if len(s) == 769 and s[0] == 12: # check if the palette is linear grayscale for i in range(256): if s[i * 3 + 1 : i * 3 + 4] != o8(i) * 3: mode = rawmode = "P" break if mode == "P": self.palette = ImagePalette.raw("RGB", s[1:]) self.fp.seek(128)
This is unnecessary, since load() will seek to the tile offset.
radarhere added 2 commits
June 9, 2025 12:21
radarhere
changed the title
Reduced number of bytes read for PCX header
Reduce number of bytes read for PCX header
hugovk
added
the
Performance
label
radarhere
deleted the
pcx
branch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment