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

Wouldn't read a valid PGM file #10

Open
rbur004 opened this issue Oct 1, 2016 · 2 comments
Open

Wouldn't read a valid PGM file #10

rbur004 opened this issue Oct 1, 2016 · 2 comments

Comments

@rbur004
Copy link

rbur004 commented Oct 1, 2016

In Image::from_pgm, the test for a valid pgm file is wrong.

  image_data = string.gsub(/^(P5)\s([0-9]+)\s([0-9]+)\s([0-9]+)\s/, '')
  if $1 != 'P5'
    raise ArgumentError, "input must be a PGM file"
  end

The PGM spec says that any string starting with # is a comment. The test file I tried, failed to load, as it had a comment line between the P5 line, and the width line.

i.e. it looked like
P5
# test_qrcode.pgm
300 300
255
...

  image_data = pgm.gsub(/^(P5)\s(#.*\n)?([0-9]+)\s([0-9]+)\s([0-9]+)\s/, '')

Would match this file, but shift $2 to $3, $3 to $4 and $4 to $5, even if there was no comment line. Of course, it is possible to have multiple comment lines, at any point, but having a comment after the P5 seems to be standard.

@willglynn
Copy link
Owner

willglynn commented Oct 1, 2016

sigh

I would like to keep the PGM parser as small as possible. I'll settle for ignoring that single comment in that single place. (Sure it doesn't catch all comments, but that change makes it slightly less wrong than it is now, and it fixes things for you.) I'd happily merge a PR with that regex change and a test covering a comment-bearing PGM file in spec/zbar/image_spec.rb.

@rbur004
Copy link
Author

rbur004 commented Oct 2, 2016

I found it when I manually converted screen shots, which are png files, to pgm, using Graphics Converter. I was testing that I was generating pgm correctly. The goal was to generate Y800, using Chunky-png, so a screen shot of a qrcode could be processed by zbar (which now works).

https://gist.github.com/rbur004/f3615da42dc163de83d7e9e1f386892d

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

No branches or pull requests

2 participants