Menu

#760 pbm p2 format reader error

v1.0_(example)
closed-works-for-me
None
5
2025-11-08
2025-11-08
Leo Zhao
No

The same problem exists in ImageMagick: https://github.com/ImageMagick/ImageMagick/issues/8425
Sample images are stored in https://github.com/user-attachments/files/23314876/images.zip

 gm identify -verbose ./512x512_p2.pgm
gm identify: Unexpected end-of-file (./512x512_p2.pgm).
gm identify: Request did not return an image.

It is a bug caused by a p2-encoded pgm file lack of newline character.

Discussion

  • Bob Friesenhahn

    Bob Friesenhahn - 2025-11-08
    • summary: pdm p2 foramt reader error --> pbm p2 format reader error
    • status: open --> closed-works-for-me
    • assigned_to: Bob Friesenhahn
     
  • Bob Friesenhahn

    Bob Friesenhahn - 2025-11-08

    Note that this is not a bug. The PGM specification says:

    There is a newline character at the end of each of these lines.
    Programs that read this format should be as lenient as possible, accepting anything that looks remotely like a PGM.

    This means that a PGM file is supposed to have a newline character after the last line as well.

    Regardless, I did think (for a long time) that it was wrong to report an error if the reader knows that it has decoded all required samples. Recently, I have been looking at ImageMagick bug reports to see if there are any which also impact GraphicsMagick. When I saw the ImageMagick bug report I decided to fix it in GraphicsMagick. As a result, none of the PNM "raw" readers in GraphicsMagick require a terminating newline as of this Mercurial changeset:

    changeset: 17841:e32526991592
    user: Bob Friesenhahn bfriesen@GraphicsMagick.org
    date: Thu Nov 06 10:06:52 2025 -0600
    files: ChangeLog VisualMagick/installer/inc/version.isx coders/pnm.c magick/version.h www/ChangeLog.html
    description:
    coders/pnm.c (ReadPNMImage): Support reading PBM raw (P1), PGM raw (P2), and PPM raw (P3) files which lack a newline character at the end of the last line.

    This means that your request has been satisfied for two days already! Please test to make sure that you are happy with development GraphicsMagick.

     

    Last edit: Bob Friesenhahn 2025-11-08

Log in to post a comment.

MongoDB Logo MongoDB