Support horizontally flipped QR-codes according to ISO 18004:2015

This commit is contained in:
Claudio Felber 2020-09-21 16:54:55 +02:00
parent 92026d26bd
commit 5beb59e3b4
2 changed files with 19 additions and 0 deletions

View file

@ -916,3 +916,19 @@ quirc_decode_error_t quirc_decode(const struct quirc_code *code,
return QUIRC_SUCCESS;
}
void quirc_flip(struct quirc_code *code)
{
struct quirc_code flipped;
memset(&flipped, 0, sizeof(flipped));
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)) {
flipped.cell_bitmap[offset >> 3] |= (1 << (offset & 7));
}
offset++;
}
}
memcpy(&code->cell_bitmap, &flipped.cell_bitmap, sizeof(flipped.cell_bitmap));
}

View file

@ -168,6 +168,9 @@ void quirc_extract(const struct quirc *q, int index,
quirc_decode_error_t quirc_decode(const struct quirc_code *code,
struct quirc_data *data);
/* Flip a QR-code according to optional mirror feature of ISO 18004:2015 */
void quirc_flip(struct quirc_code *code);
#ifdef __cplusplus
}
#endif