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

Error writing png with color mode 0 and 1-bit depth in ruby 2.0.0 #43

Closed
nielsgl opened this issue Nov 12, 2013 · 3 comments
Closed

Error writing png with color mode 0 and 1-bit depth in ruby 2.0.0 #43

nielsgl opened this issue Nov 12, 2013 · 3 comments

Comments

@nielsgl
Copy link

nielsgl commented Nov 12, 2013

I found a problem with writing pngs with color mode 0 and 1-bit depth when using ruby 2.0.0p247. The error does not occur with ruby versions < 2. This is an example of how to reproduce it:

appel:code niels$ ruby --version
ruby 1.9.3p448 (2013-06-27 revision 41675) [x86_64-darwin12.5.0]
appel:code niels$ irb -r qrencoder
irb(main):001:0> qrcode = QREncoder.encode("Hello world!")
=> #<QREncoder::QRCode:0x007fd1a98417a0>
irb(main):002:0> qrcode.save_png("/tmp/helloqr.png")
=> #<File:/tmp/helloqr.png (closed)>
irb(main):003:0> exit
appel:code niels$ rbenv local 2.0.0-p247 
appel:code niels$ rbenv rehash
appel:code niels$ ruby --version
ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-darwin12.5.0]
appel:code niels$ irb -r qrencoder
irb(main):001:0> qrcode = QREncoder.encode("Hello world!")
=> #<QREncoder::QRCode:0x007fcf43825d10>
irb(main):002:0> qrcode.save_png("/tmp/helloqr2.png")
ChunkyPNG::NotSupported: No encoder found for color mode 0 and 1-bit depth!
    from /Users/niels/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/chunky_png-1.2.5/lib/chunky_png/canvas/png_encoding.rb:370:in `encode_png_pixels_to_scanline_method'
    from /Users/niels/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/chunky_png-1.2.5/lib/chunky_png/canvas/png_encoding.rb:210:in `encode_png_image_pass_to_stream'
    from /Users/niels/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/chunky_png-1.2.5/lib/chunky_png/canvas/png_encoding.rb:174:in `encode_png_image_without_interlacing'
    from /Users/niels/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/chunky_png-1.2.5/lib/chunky_png/canvas/png_encoding.rb:161:in `encode_png_pixelstream'
    from /Users/niels/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/chunky_png-1.2.5/lib/chunky_png/canvas/png_encoding.rb:85:in `to_datastream'
    from /Users/niels/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/chunky_png-1.2.5/lib/chunky_png/image.rb:62:in `to_datastream'
    from /Users/niels/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/chunky_png-1.2.5/lib/chunky_png/canvas/png_encoding.rb:35:in `write'
    from /Users/niels/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/chunky_png-1.2.5/lib/chunky_png/canvas/png_encoding.rb:43:in `block in save'
    from /Users/niels/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/chunky_png-1.2.5/lib/chunky_png/canvas/png_encoding.rb:43:in `open'
    from /Users/niels/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/chunky_png-1.2.5/lib/chunky_png/canvas/png_encoding.rb:43:in `save'
    from /Users/niels/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/qrencoder-1.4.1/lib/qrencoder/png.rb:27:in `method_missing'
    from /Users/niels/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/qrencoder-1.4.1/lib/qrencoder/qrcode.rb:11:in `save_png'
    from (irb):2
    from /Users/niels/.rbenv/versions/2.0.0-p247/bin/irb:12:in `<main>'
irb(main):003:0> 
@wvanbergen
Copy link
Owner

This is weird. The test suite, with includes an example using this mode, works fine for me on ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-darwin12.3.0]

I am suspecting a weird interaction issue with the QR code library you're using. Can you figure out what the exact arguments are (including type) that chunky_png is called with from that library?

@nielsgl
Copy link
Author

nielsgl commented Nov 13, 2013

So the library generates a qrcode and then wraps it in a png, with a bunch of points like:

[
  [0] [
    [0] 0,
    [1] 0
  ],
  [1] [
    [0] 1,
    [1] 0
  ], ...
]

with a margin of 4, pixels_per_module = 1, background = 4294967295, width = 29, and a canvas is a < ChunkyPNG::Image 29x29 [ [#ffffff #ffffff .... ] ... ]
and then it calls png.save(path), where path is a string.

@wvanbergen
Copy link
Owner

The exact example you pasted works fine for me:

~/  $ ruby -v
ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-darwin12.4.0]
~/ $ irb
irb(main):001:0> require 'qrencoder'
=> true
irb(main):002:0> qrcode = QREncoder.encode("Hello world!")
=> #<QREncoder::QRCode:0x007f91fa1dd3a8>
irb(main):003:0> qrcode.save_png("/tmp/helloqr2.png")
=> #<File:/tmp/helloqr2.png (closed)>

I am using qrencoder version 1.4.1

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