aboutsummaryrefslogtreecommitdiff
path: root/lpg/libqr/code-common.c
blob: 08b16dfe8088810f8ceaff858b1bddee6acca649 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <stdlib.h>
#include <qr/code.h>

#include "code-common.h"

void qr_code_destroy(struct qr_code * code)
{
        free(code->modules);
        free(code);
}

int qr_code_width(const struct qr_code * code)
{
        return code_side_length(code->format);
}

int code_side_length(int format)
{
        return format * 4 + 17;
}

int code_finder_count(int format)
{
        int x = format / 7;
        return format > 1 ? x*x + 4*x + 1 : 0;        
}

size_t code_total_capacity(int format)
{
        /* XXX: figure out the "correct" formula */
        return 160
             +  25 * code_finder_count(format)
             -  10 * (format / 7)
             +   2 * code_side_length(format);
}