aiko_engine_mp icon indicating copy to clipboard operation
aiko_engine_mp copied to clipboard

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

Open nicolan opened this issue 4 years ago • 1 comments

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.

nicolan avatar Jan 25 '21 04:01 nicolan

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.

marcmerlin avatar Jan 25 '21 16:01 marcmerlin