Skip to content

qt: add qr reading from file to ScanQRTextEdit and SendTab #9782

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

f321x
Copy link
Member

@f321x f321x commented May 2, 2025

There was no ability to read qr codes contained in image files. This is confusing in some contexts, as on_file_input() of ScanQRTextEdit will read the whole content of the file (instead of looking for qr codes).
The revealer plugin for example generates png files containing qr codes and uses the ScanQRTextEdit to get user input, for the user it would seem logical to click on 'Read from file' to load the generated file, however this will result in the wrong data getting loaded. Having the option to explicitly load a QR from file makes this clear.
Besides that it seems useful, considering reading QR from screenshots doesn't work on wayland.

@accumulator
Copy link
Member

Nothing wrong with the code per se, but it doesn't find a QR code in my testing (screenshot saved as png from spectacle, which itself detects a QR code)

@f321x
Copy link
Member Author

f321x commented May 2, 2025

That's weird, works fine for me with the following screenshots:

Screenshot_20250502_161712
Screenshot_20250502_093128

Can you share a png that doesn't work?

@accumulator
Copy link
Member

Screenshot_20250502_160807

@accumulator
Copy link
Member

That's weird, works fine for me with the following screenshots:

Yeah, your screenshots work fine here too

@f321x f321x force-pushed the fix_qr_input_from_file branch from f04a60a to f00f62e Compare May 5, 2025 14:45
@f321x
Copy link
Member Author

f321x commented May 5, 2025

The zbar library we use here for detecting the qr codes doesn't seem to like dense qr codes that are a large portion of the image. So i added a function _reduce_qr_code_density() to create a new image of which the original image is only a smaller part (it pads the image with white space), so it can attempt the scan multiple times with the qr code being different proportions of the image. This seems to make it more reliable, also with your screenshot.

Comment on lines 81 to 82
new_width = image.width() * 2
new_height = image.height() * 2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can really get large. Maybe + 200 suffices, as you offset the source image (100,100) below?

Copy link
Member Author

@f321x f321x May 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah right, + 200 didn't work, but instead i changed the function to make the passed image a smaller part of a new (white) image with the same size, this is faster too and seems as reliable. I also removed the offset as it could happen to cut parts of the original image if it is very small.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead i changed the function to make the passed image a smaller part of a new (white) image with the same size, this is faster too and seems as reliable.

That's.. unexpected :)

@f321x f321x force-pushed the fix_qr_input_from_file branch from f00f62e to 0a789e3 Compare May 6, 2025 11:37
There was no ability to read qr codes contained in image files. This
could lead to confusion in some contexts, as `on_file_input()` of
ScanQRTextEdit will read the whole content of the file (instead of
looking for qr codes). The revealer plugin for example generates png
files containing qr codes and uses the `ScanQRTextEdit` to get user
input, for the user it would seem logical to click on 'Read from file'
to load the generated file, however this will result in the wrong data
being loaded. Having the option to explicitly load a QR from file makes
this clear. Also it seems useful, especially considering reading QR from
screenshots doesn't work on wayland.
@f321x f321x force-pushed the fix_qr_input_from_file branch from 0a789e3 to 63c224c Compare May 6, 2025 11:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants