mchehab / zbar

ZBar is an open source software suite for reading bar codes from various sources, including webcams. As its development stopped in 2012, I took the task of keeping it updated with the V4L2 API. This is the main repository for it. There's a clone at at LinuxTV.org, and another one at gitlab.
https://linuxtv.org/downloads/zbar/
GNU Lesser General Public License v2.1
1k stars 206 forks source link

Fix .pdf gotcha #227

Closed za3k closed 10 months ago

za3k commented 2 years ago

PDF does not inherently encode a resolution--it's essentially a vector format. By default, ImageMagick samples it at a tiny 72dpi resolution, so many QR codes are not read.

Default .pdf to 300dpi sample rate to fix the issue.

za3k commented 2 years ago

https://stackoverflow.com/questions/73656471/use-filetoblob-in-imagemagick well i'm a bit stuck using FileToBlob() if you can offer any help.

jameshilliard commented 2 years ago

https://stackoverflow.com/questions/73656471/use-filetoblob-in-imagemagick well i'm a bit stuck using FileToBlob() if you can offer any help.

Maybe should be something like this:

void *blob = FileToBlob(filename, MagickMaxBufferExtent, &blob_length, &blob_exception);
jameshilliard commented 2 years ago

or maybe:

void *blob = FileToBlob(filename, MAGICK_SSIZE_MAX, &blob_length, &blob_exception);
za3k commented 2 years ago

The second argument (extent) is not causing the issues. I started it as INT_MAX, sure, just left that out for clarity.

za3k commented 2 years ago

Proposed an ImageMagick feature to help us out. If someone has thoughts on a better way to do it, feel free to comment. https://github.com/ImageMagick/ImageMagick/issues/5554

Also, went ahead and reported my issues as a bug at https://github.com/ImageMagick/ImageMagick/issues/5553. I can get it to work for an 80K file but not a 100K file (note size is like 100MB), which makes me think MAYBE it's not just a me issue.

In the meantime, I've made sure this doesn't break stdin, and I think it could be merged. It just won't work for PDFs on stdin yet.

za3k commented 2 years ago

Confirmed the issue I was running into was a bug. ImageMagick has a patch, thanks ImageMagick!

I'll offer a PR that makes PDFs work on stdin too, once imagemagick's stable release includes their fix.

za3k commented 2 years ago

OK, ready for submission. Apparently I was wildly wrong about how setting the density works, and I can just do it unconditionally. This is now a one-line change.

za3k commented 2 years ago

Ping on this? It's a one-line change now so it seems pretty safe. You could change the default resolution to 300 or 600 if you prefer.

mchehab commented 10 months ago

Merged, thanks!