Reduce number of bytes read for PCX header by radarhere · Pull Request #9004 · python-pillow/Pillow

Skip to content

Navigation Menu

Sign in

Appearance settings

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Appearance settings

Conversation

@radarhere

Copy link Copy Markdown

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

Reviewers

No reviews

Assignees

No one assigned

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

2 participants

@radarhere @hugovk