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

Improve barcode rendering (square codes & padding) #1359

Merged
merged 1 commit into from
Jun 22, 2023

Conversation

obfusk
Copy link
Contributor

@obfusk obfusk commented Jun 8, 2023

Fixes #1332.

screenshots

Screenshot_20230608_191619
Screenshot_20230608_191626
Screenshot_20230608_191642
Screenshot_20230608_191650
Screenshot_20230608_191702
Screenshot_20230608_191709

@obfusk
Copy link
Contributor Author

obfusk commented Jun 8, 2023

Might also fix #329.

@obfusk
Copy link
Contributor Author

obfusk commented Jun 22, 2023

Explanation

The current code doesn't take square barcodes into account, thus incorrectly reducing the height to match the max width using a wrong aspect ratio. I changed that to use the minimum of the height, width, and max width for both height and width (since it's square). Which results in better rendering (and no weird padding) for square barcodes like Aztec.

It also adds padding for the rounded corners by reducing the height of the image itself, which I replaced by adding actual padding to either the height or width of the imageView, depending on which is more appropriate given the shape of the barcode and whether the imageView is landscape or portrait. Which should result in no "unnecessary" padding being added in many cases, especially for square barcodes.

@obfusk
Copy link
Contributor Author

obfusk commented Jun 22, 2023

incorrectly reducing the height to match the max width using a wrong aspect ratio

It was scaling the height to match the max width, but using the aspect ratio of the imageView, ignoring the fact that the image should be square for a square barcode.

@obfusk
Copy link
Contributor Author

obfusk commented Jun 22, 2023

Which should result in no "unnecessary" padding being added in many cases, especially for square barcodes.

For a square barcode on a landscape imageView, there is zero point in adding padding to the top and bottom for rounded corners. It still adds padding, but to the left and right in this case, so it's not noticeable now as it doesn't make the barcode itself smaller any more.

@obfusk
Copy link
Contributor Author

obfusk commented Jun 22, 2023

It was scaling the height to match the max width, but using the aspect ratio of the imageView, ignoring the fact that the image should be square for a square barcode.

This was causing both weird padding (on some devices, it was not consistent between my phone and the emulator) and blurred images because of the wrong resolution, which is why I think it might fix #329.

@obfusk obfusk force-pushed the barcode-rendering branch from bff8557 to 6ff11e2 Compare June 22, 2023 19:42
@TheLastProject
Copy link
Member

Well, especially with your explanation it makes sense to me. I'm not seeing anything wrong from some quick testing. I'm going to merge it, if more testing shows issues later I can always revert easily anyway :)

@TheLastProject TheLastProject merged commit 2f3c96b into CatimaLoyalty:main Jun 22, 2023
@obfusk
Copy link
Contributor Author

obfusk commented Jun 22, 2023

I found one case that got worse. According to CatimaBarcode.isSquare(), Data Matrix is square. This does not seem to be true for all values:

Screenshot_20230622-234524_Catima Debug

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

Successfully merging this pull request may close these issues.

Square barcodes, landscape and full-screen views
2 participants