aboutsummaryrefslogtreecommitdiff
path: root/lpg
diff options
context:
space:
mode:
Diffstat (limited to 'lpg')
-rw-r--r--lpg/libqr/TODO2
-rw-r--r--lpg/libqr/code-common.c43
-rw-r--r--lpg/libqr/code-common.h2
-rw-r--r--lpg/libqr/code-create.c23
-rw-r--r--lpg/libqr/code-layout.c27
5 files changed, 92 insertions, 5 deletions
diff --git a/lpg/libqr/TODO b/lpg/libqr/TODO
index 6efa259..eb35da8 100644
--- a/lpg/libqr/TODO
+++ b/lpg/libqr/TODO
@@ -1,5 +1,3 @@
-* Get sample generated OK
-* Fix generation for all sizes (alignment pattern)
* Auto-sizing for data
* Sample app
* Merge some files
diff --git a/lpg/libqr/code-common.c b/lpg/libqr/code-common.c
index 150dfc5..7c3c119 100644
--- a/lpg/libqr/code-common.c
+++ b/lpg/libqr/code-common.c
@@ -38,3 +38,46 @@ size_t code_total_capacity(int version)
return side * side - function_bits;
}
+const int QR_ALIGNMENT_LOCATION[40][7] = {
+ { 0, 0, 0, 0, 0, 0, 0 }, /* 1 */
+ { 6, 18, 0, 0, 0, 0, 0 }, /* 2 */
+ { 6, 22, 0, 0, 0, 0, 0 }, /* 3 */
+ { 6, 26, 0, 0, 0, 0, 0 }, /* 4 */
+ { 6, 30, 0, 0, 0, 0, 0 }, /* 5 */
+ { 6, 34, 0, 0, 0, 0, 0 }, /* 6 */
+ { 6, 22, 38, 0, 0, 0, 0 }, /* 7 */
+ { 6, 24, 42, 0, 0, 0, 0 }, /* 8 */
+ { 6, 26, 46, 0, 0, 0, 0 }, /* 9 */
+ { 6, 28, 50, 0, 0, 0, 0 }, /* 10 */
+ { 6, 30, 54, 0, 0, 0, 0 }, /* 11 */
+ { 6, 32, 58, 0, 0, 0, 0 }, /* 12 */
+ { 6, 34, 62, 0, 0, 0, 0 }, /* 13 */
+ { 6, 26, 46, 66, 0, 0, 0 }, /* 14 */
+ { 6, 26, 48, 70, 0, 0, 0 }, /* 15 */
+ { 6, 26, 50, 74, 0, 0, 0 }, /* 16 */
+ { 6, 30, 54, 78, 0, 0, 0 }, /* 17 */
+ { 6, 30, 56, 82, 0, 0, 0 }, /* 18 */
+ { 6, 30, 58, 86, 0, 0, 0 }, /* 19 */
+ { 6, 34, 62, 90, 0, 0, 0 }, /* 20 */
+ { 6, 28, 50, 72, 94, 0, 0 }, /* 21 */
+ { 6, 26, 50, 74, 98, 0, 0 }, /* 22 */
+ { 6, 30, 54, 78,102, 0, 0 }, /* 23 */
+ { 6, 28, 54, 80,106, 0, 0 }, /* 24 */
+ { 6, 32, 58, 84,110, 0, 0 }, /* 25 */
+ { 6, 30, 58, 86,114, 0, 0 }, /* 26 */
+ { 6, 34, 62, 90,118, 0, 0 }, /* 27 */
+ { 6, 26, 50, 74, 98,122, 0 }, /* 28 */
+ { 6, 30, 54, 78,102,126, 0 }, /* 29 */
+ { 6, 26, 52, 78,104,130, 0 }, /* 30 */
+ { 6, 30, 56, 82,108,134, 0 }, /* 31 */
+ { 6, 34, 60, 86,112,138, 0 }, /* 32 */
+ { 6, 30, 58, 86,114,142, 0 }, /* 33 */
+ { 6, 34, 62, 90,118,146, 0 }, /* 34 */
+ { 6, 30, 54, 78,102,126,150 }, /* 35 */
+ { 6, 24, 50, 76,102,128,154 }, /* 36 */
+ { 6, 28, 54, 80,106,132,158 }, /* 37 */
+ { 6, 32, 58, 84,110,136,162 }, /* 38 */
+ { 6, 26, 54, 82,110,138,166 }, /* 39 */
+ { 6, 30, 58, 86,114,142,170 }, /* 40 */
+};
+
diff --git a/lpg/libqr/code-common.h b/lpg/libqr/code-common.h
index 0459708..9900e4e 100644
--- a/lpg/libqr/code-common.h
+++ b/lpg/libqr/code-common.h
@@ -12,5 +12,7 @@ struct qr_code {
size_t code_total_capacity(int version);
+extern const int QR_ALIGNMENT_LOCATION[40][7];
+
#endif
diff --git a/lpg/libqr/code-create.c b/lpg/libqr/code-create.c
index 36ebb24..ae23acc 100644
--- a/lpg/libqr/code-create.c
+++ b/lpg/libqr/code-create.c
@@ -79,6 +79,8 @@ static int draw_functional(struct qr_code * code,
struct qr_bitmap * bmp;
int dim = qr_code_width(code);
int i;
+ int x, y;
+ int am_side;
bmp = qr_bitmap_create(dim, dim, 0);
if (!bmp)
@@ -95,7 +97,26 @@ static int draw_functional(struct qr_code * code,
setpx(bmp, 6, i);
}
- /* XXX: alignment pattern */
+ /* Alignment pattern */
+ am_side = code->version > 1 ? (code->version / 7) + 2 : 0;
+ for (y = 0; y < am_side; ++y) {
+ const int * am_pos = QR_ALIGNMENT_LOCATION[code->version - 1];
+
+ for (x = 0; x < am_side; ++x) {
+ if ((x == 0 && y == 0) ||
+ (x == 0 && y == am_side - 1) ||
+ (x == am_side - 1 && y == 0))
+ continue;
+
+ for (i = -2; i < 2; ++i) {
+ setpx(bmp, am_pos[x] + i, am_pos[y] - 2);
+ setpx(bmp, am_pos[x] + 2, am_pos[y] + i);
+ setpx(bmp, am_pos[x] - i, am_pos[y] + 2);
+ setpx(bmp, am_pos[x] - 2, am_pos[y] - i);
+ }
+ setpx(bmp, am_pos[x], am_pos[y]);
+ }
+ }
/* Format info */
setpx(bmp, 8, dim - 8);
diff --git a/lpg/libqr/code-layout.c b/lpg/libqr/code-layout.c
index 54947d1..2a90124 100644
--- a/lpg/libqr/code-layout.c
+++ b/lpg/libqr/code-layout.c
@@ -21,6 +21,8 @@ void qr_layout_init_mask(struct qr_code * code)
int x, y;
int dim = qr_code_width(code);
struct qr_bitmap * bmp = code->modules;
+ const int * am_pos = QR_ALIGNMENT_LOCATION[code->version - 1];
+ int am_side;
assert(bmp->mask);
@@ -53,11 +55,32 @@ void qr_layout_init_mask(struct qr_code * code)
continue;
}
- /* XXX: alignment pattern */
-
row[off] |= bit;
}
}
+
+ /* Alignment pattern */
+ am_side = code->version > 1 ? (code->version / 7) + 2 : 0;
+ for (y = 0; y < am_side; ++y) {
+ for (x = 0; x < am_side; ++x) {
+ int i, j;
+
+ if ((x == 0 && y == 0) ||
+ (x == 0 && y == am_side - 1) ||
+ (x == am_side - 1 && y == 0))
+ continue;
+
+ for (j = -2; j <= 2; ++j) {
+ unsigned char * row = bmp->mask + (am_pos[y]+j) * bmp->stride;
+ for (i = -2; i <= 2; ++i) {
+ unsigned char bit = 1 << ((am_pos[x]+i) % CHAR_BIT);
+ int off = (am_pos[x]+i) / CHAR_BIT;
+
+ row[off] &= ~bit;
+ }
+ }
+ }
+ }
}
static int is_data_bit(const struct qr_iterator * i)