Support horizontally flipped QR-codes according to ISO 18004:2015#89
Support horizontally flipped QR-codes according to ISO 18004:2015#89kaworu merged 4 commits intodlbeer:masterfrom
Conversation
There was a problem hiding this comment.
Great design, thanks a lot for the PR!
Couple of nitpick but feel free to ignore them.
The changes I would like to see is more light on this feature. First, I think both qrtest and inspect (from the test/ directory) should "do the flip dance". Then, it definitely deserve a spot in the README.
lib/decode.c
Outdated
| struct quirc_code flipped; | ||
| memset(&flipped, 0, sizeof(flipped)); |
There was a problem hiding this comment.
nit: We mandate c99 support, so you could write struct quirc_code flipped = {0}; instead. In practice, I believe most compilers will generate the same output for both cases, so it's only a matter of readability.
lib/decode.c
Outdated
| int offset = 0; | ||
| for (int y = 0, sx = 0; y < code->size; y++, sx++) { | ||
| for (int x = 0, sy = 0; x < code->size; x++, sy++) { | ||
| if (grid_bit(code, sx, sy)) { |
There was a problem hiding this comment.
nit: My understanding here is that y == sx and x == sy always hold, and thus we could get rid of both sx and sy.
I guess the intent is to avoid grid_bit(code, y, x) because x and y would be in the inverse order of the definition:
static inline int grid_bit(const struct quirc_code *code, int x, int y)Personally, in the context of "flipping", I wouldn't mind this inversion. It would actually explicit the flipping if anything.
|
Thanks for your feedback. I have added support for flipped QR-codes to the |
|
LGTM, thank you! |
The QR-code specification supports various optional features. A newer one is "mirror imaging". I don't know in which version of the specification (2006, 2009 or 2015) it was added, but it certainly is mentioned in ISO 18004:2015:
ISO 18004: 2015, page 6, "Mirror lmaging":
ISO 18004: 2015, page 62, "Decoding procedure overview":
For the moment I decided on making the flipped detection optional by providing a new function
quirc_flip(). It flips the modules pixmap and rotates it back to the normalized position. Then a second decode attempt can be initiated. A typical call sequence would look like this:The following two QR-codes represent a normal and a horizontally flipped one. Both can be correctly decoded with this small extension:
This resolves the problem I reported in issue #88.