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

Fix to let load_image work with P4 and P1 type PBM files #33

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

nicolan
Copy link
Contributor

@nicolan nicolan commented Jan 25, 2021

I was today years old when I found out there's two different
PBM image formats:
http://netpbm.sourceforge.net/doc/pbm.html
P4 doesn't have a creator comment, P1 does.

P4 [ whitespace ] [width] [height] [whitespace] [image data]
P1 [whitespace] # creator comment [whitespace] [width] [height] [image data]

This patch detects if the file format is P1 and skips over the creator comment to find the width and height.

I was today years old when I found out there's two different
PBM image formats:
http://netpbm.sourceforge.net/doc/pbm.html
P4 doesn't have a creator comment, P1 does.

    P4 [ whitespace ] [width] [height] [whitespace] [image data]
    P1 [whitespace] # creator comment [whitespace] [width] [height] [image data]

This patch detects if the file format is P1 and skips over the creator comment to find the width and height.
@marcmerlin
Copy link
Collaborator

Thank you for that, I noticed the same issue when

  1. taking animated gif
  2. splitting the gif in frame by frame
  3. converting each frame to PBM.

My problem was that I had
file #1:

P4
#Created with GIMP
128 64

file #2:

P4
128 64

From what you said, my first file should have said P1, but it said P4

If you look at tux_64.pbm in the source code, you will also see tux_64.pbm

P4
# CREATOR: GIMP PNM Filter Version 1.1
64 64

So, I don't know what the spec says, but it's probably better to have the parser check the 2nd line, and skip t if it's a comment, regardless of the P value.

I'd be happy to merge this if you test that against both kinds of files and you make sure that the pbm examples in examples/ , still work.

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.

2 participants