Optimize quirc_flip()

This commit is contained in:
Claudio Felber 2020-09-22 12:14:09 +02:00
parent 5beb59e3b4
commit 4bc17cf8c6
2 changed files with 13 additions and 14 deletions

View file

@ -919,16 +919,15 @@ quirc_decode_error_t quirc_decode(const struct quirc_code *code,
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));
}
struct quirc_code flipped = {0};
unsigned int offset = 0;
for (int y = 0; y < code->size; y++) {
for (int x = 0; x < code->size; x++) {
if (grid_bit(code, y, x)) {
flipped.cell_bitmap[offset >> 3u] |= (1u << (offset & 7u));
}
offset++;
}
}
memcpy(&code->cell_bitmap, &flipped.cell_bitmap, sizeof(flipped.cell_bitmap));
}

View file

@ -1140,7 +1140,7 @@ void quirc_extract(const struct quirc *q, int index,
int x;
for (x = 0; x < qr->grid_size; x++) {
if (read_cell(q, index, x, y) > 0) {
code->cell_bitmap[i >> 3] |= (1 << (i & 7));
code->cell_bitmap[i >> 3] |= (1 << (i & 7));
}
i++;
}