Skip to content

Conversation

@radarhere
Copy link
Member

  1. PcxImagePlugin initially reads 128 bytes

    s = self.fp.read(128)

    But the header only uses up to 68 bytes.
    provided_stride = i16(s, 66)

    So the number of bytes can be reduced.

  2. After seeking to the end of the file for one type of header, PcxImagePlugin seeks back to the start.

    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 radarhere changed the title Reduced number of bytes read for PCX header Reduce number of bytes read for PCX header Jun 9, 2025
@hugovk hugovk merged commit ff624fe into python-pillow:main Jun 10, 2025
73 of 74 checks passed
@radarhere radarhere deleted the pcx branch June 10, 2025 12:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants